MAPL_ExportStateGet Subroutine

public recursive subroutine MAPL_ExportStateGet(export, name, result, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_State), intent(in) :: export(:)
character(len=*), intent(in) :: name
type(ESMF_State), intent(out) :: result
integer, intent(out) :: rc

Calls

proc~~mapl_exportstateget~~CallsGraph proc~mapl_exportstateget MAPL_ExportStateGet proc~mapl_exportstateget->proc~mapl_exportstateget esmf_stateget esmf_stateget proc~mapl_exportstateget->esmf_stateget proc~mapl_return MAPL_Return proc~mapl_exportstateget->proc~mapl_return proc~mapl_verify MAPL_Verify proc~mapl_exportstateget->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

   recursive subroutine MAPL_ExportStateGet(export, name, result, rc)
      type (ESMF_State), intent(IN   ) :: export(:)
      character(len=*),  intent(IN   ) :: name
      type (ESMF_State), intent(  OUT) :: result
      integer,           intent(  OUT) :: rc

      character(len=ESMF_MAXSTR), parameter :: IAm="MAPL_ExportStateGet"
      integer                               :: status

      integer                               :: n, i, ni, k, j
      logical                               :: have_ens
      character(len=ESMF_MAXSTR)            :: sname
      type (ESMF_StateItem_Flag), pointer   :: ITEMTYPES(:)
      character(len=ESMF_MAXSTR ), pointer  :: ITEMNAMES(:)
      type (ESMF_State), pointer            :: exptmp(:)

      n = size(export)

      have_ens = index(name,":") /= 0

      do i = 1, n
         call ESMF_StateGet(export(i), name=sname, itemcount = ni, rc=status)
         _VERIFY(status)
         if (have_ens) then
            if (sname == trim(name) // '_Exports') then
               result = export(i)
               _RETURN(ESMF_SUCCESS)
            end if
         else
            if (sname(index(sname,":")+1:) == trim(name) // '_Exports') then
               result = export(i)
               _RETURN(ESMF_SUCCESS)
            end if
         end if

         allocate(itemtypes(ni), itemnames(ni), stat=status)
         _VERIFY(status)

         call ESMF_StateGet(export(i), ITEMNAMELIST=ITEMNAMES,ITEMTYPELIST=ITEMTYPES,RC=status)
         _VERIFY(status)

         j = 0
         do k = 1, ni
            if (itemtypes(k) == ESMF_StateItem_State) then
               j = j+1
            end if
         end do

         allocate(exptmp(j), stat=status)
         _VERIFY(status)

         j = 0
         do k = 1, ni
            if (itemtypes(k) == ESMF_StateItem_State) then
               j = j+1
               call ESMF_StateGet(export(i), itemnames(k), exptmp(j) , rc=status)
               _VERIFY(status)
            end if
         end do

         call MAPL_ExportStateGet(exptmp, name, result, rc=status)
         deallocate(exptmp)
         deallocate(itemtypes, itemnames)
         if (status == ESMF_SUCCESS) then
            _RETURN(ESMF_SUCCESS)
         end if
      end do

      rc = ESMF_FAILURE
      return
   end subroutine MAPL_ExportStateGet