ESMFL_StateGetField Subroutine

public subroutine ESMFL_StateGetField(State, FieldName, Bundle, FieldAlias, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_State), intent(in) :: State
character(len=*), intent(in) :: FieldName(:)
type(ESMF_FieldBundle), intent(inout) :: Bundle
character(len=*), intent(in), optional :: FieldAlias(:)
integer, intent(out), optional :: rc

Calls

proc~~esmfl_stategetfield~~CallsGraph proc~esmfl_stategetfield ESMFL_StateGetField esmf_fieldbundleget esmf_fieldbundleget proc~esmfl_stategetfield->esmf_fieldbundleget esmf_fieldemptycreate esmf_fieldemptycreate proc~esmfl_stategetfield->esmf_fieldemptycreate esmf_stateget esmf_stateget proc~esmfl_stategetfield->esmf_stateget interface~mapl_allocatecoupling MAPL_AllocateCoupling proc~esmfl_stategetfield->interface~mapl_allocatecoupling interface~mapl_assert MAPL_Assert proc~esmfl_stategetfield->interface~mapl_assert interface~mapl_fieldbundleadd MAPL_FieldBundleAdd proc~esmfl_stategetfield->interface~mapl_fieldbundleadd interface~mapl_fieldcreate MAPL_FieldCreate proc~esmfl_stategetfield->interface~mapl_fieldcreate proc~mapl_return MAPL_Return proc~esmfl_stategetfield->proc~mapl_return proc~mapl_verify MAPL_Verify proc~esmfl_stategetfield->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Source Code

 subroutine ESMFL_StateGetField(State, FieldName, Bundle, FieldAlias, RC)
   type(ESMF_State),           intent(IN   ) :: State
   character(len=*),           intent(IN   ) :: FieldName(:)
   type(ESMF_FieldBundle),     intent(INOUT) :: Bundle
   character(len=*), optional, intent(IN   ) :: FieldAlias(:)
   integer, optional,  intent(OUT)   :: rc

   integer                    :: status

   character(len=ESMF_MAXSTR) :: NameInBundle
   character(len=ESMF_MAXSTR) :: NameInState
   type(ESMF_Field)           :: Bundlefield
   type(ESMF_Field)           :: Statefield
   integer                    :: I
   logical                    :: NotInState
   logical                    :: NeedNewField

   type(ESMF_StateItem_Flag)  :: itemType
   logical                    :: isPresent

!   integer                    :: gridRank

!  Adds fields from a state to a bundle. If a field
!  is not in the state, it adds a dummy field. It fails
!  if it tries to add a dummy field to an empty bundle,
!  since it does not know what grid to use in the dummy.
!  The name of the field in the bundle can be reset with
!  FieldAlias

   RequestedFields: do i=1,size(FIELDNAME)

      NameInState = FieldName (I)

      if(present(FieldAlias)) then
         NameInBundle = FieldAlias(I)
      else
         NameInBundle = NameInState
      end if

! Make sure field is not in bundle

      call ESMF_FieldBundleGet(BUNDLE, FIELDNAME=NameInBundle, isPresent=isPresent, rc=STATUS)
      _VERIFY(STATUS)
      _ASSERT(.not. isPresent, trim(NameInBundle) // ' found in bundle.')

! Get Field from State

      call ESMF_StateGet (STATE, NameInState, itemType=itemType, RC=STATUS)
      _VERIFY(STATUS)

      if (itemType /= ESMF_STATEITEM_FIELD) then
         NotInState = .TRUE.
      else
         NotInState = .FALSE.
         call ESMF_StateGet (STATE, NameInState, StateFIELD,  RC=STATUS)
         _VERIFY(STATUS)
      end if

      NeedNewField = NotInState .or. (NameInState/=NameInBundle)

      if (.not. NotInState) then
         call MAPL_AllocateCoupling(stateField, rc=status)
         _VERIFY(STATUS)
      end if

      if(NeedNewField) then

         ! Define Grid and Array for new field

         if(NotInState) then

            ! Create a new empty field
            BundleField = ESMF_FieldEmptyCreate(name=NameInBundle, rc=status)
            _VERIFY(STATUS)

         else

            ! Use the grid and array in the State Field, just rename it
            BundleField = MAPL_FieldCreate(stateField, name=NameInBundle, RC=STATUS)
            _VERIFY(STATUS)
         end if

      else

         BundleField = StateField

      end if

      call MAPL_FieldBundleAdd(BUNDLE, bundleField, rc=STATUS)
      _VERIFY(STATUS)

   end do RequestedFields

   _RETURN(ESMF_SUCCESS)
 end subroutine ESMFL_StateGetField