MAPL_GenericRefresh Subroutine

public recursive subroutine MAPL_GenericRefresh(GC, IMPORT, EXPORT, CLOCK, RC)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp), intent(inout) :: GC
type(ESMF_State), intent(inout) :: IMPORT
type(ESMF_State), intent(inout) :: EXPORT
type(ESMF_Clock), intent(inout) :: CLOCK
integer, intent(out), optional :: RC

Calls

proc~~mapl_genericrefresh~~CallsGraph proc~mapl_genericrefresh MAPL_GenericRefresh proc~mapl_genericrefresh->proc~mapl_genericrefresh ESMF_GridCompGet ESMF_GridCompGet proc~mapl_genericrefresh->ESMF_GridCompGet ESMF_UtilStringLowerCase ESMF_UtilStringLowerCase proc~mapl_genericrefresh->ESMF_UtilStringLowerCase interface~mapl_getresource MAPL_GetResource proc~mapl_genericrefresh->interface~mapl_getresource interface~mapl_timeroff MAPL_TimerOff proc~mapl_genericrefresh->interface~mapl_timeroff interface~mapl_timeron MAPL_TimerOn proc~mapl_genericrefresh->interface~mapl_timeron none~get_child_export_state MAPL_MetaComp%get_child_export_state proc~mapl_genericrefresh->none~get_child_export_state none~get_child_gridcomp MAPL_MetaComp%get_child_gridcomp proc~mapl_genericrefresh->none~get_child_gridcomp none~get_child_import_state MAPL_MetaComp%get_child_import_state proc~mapl_genericrefresh->none~get_child_import_state none~get_internal_state~2 MaplGenericComponent%get_internal_state proc~mapl_genericrefresh->none~get_internal_state~2 none~get_num_children~5 CompositeComponent%get_num_children proc~mapl_genericrefresh->none~get_num_children~5 none~start~83 DistributedProfiler%start proc~mapl_genericrefresh->none~start~83 proc~getfile GETFILE proc~mapl_genericrefresh->proc~getfile proc~mapl_datestampget MAPL_DateStampGet proc~mapl_genericrefresh->proc~mapl_datestampget proc~mapl_destroyfile MAPL_DestroyFile proc~mapl_genericrefresh->proc~mapl_destroyfile proc~mapl_esmfstatereadfromfile MAPL_ESMFStateReadFromFile proc~mapl_genericrefresh->proc~mapl_esmfstatereadfromfile proc~mapl_internalstateretrieve MAPL_InternalStateRetrieve proc~mapl_genericrefresh->proc~mapl_internalstateretrieve proc~mapl_return MAPL_Return proc~mapl_genericrefresh->proc~mapl_return proc~mapl_verify MAPL_Verify proc~mapl_genericrefresh->proc~mapl_verify

Source Code

   recursive subroutine MAPL_GenericRefresh ( GC, IMPORT, EXPORT, CLOCK, RC )

      ! !ARGUMENTS:

      type(ESMF_GridComp), intent(inout) :: GC     ! composite gridded component
      type(ESMF_State),    intent(inout) :: IMPORT ! import state
      type(ESMF_State),    intent(inout) :: EXPORT ! export state
      type(ESMF_Clock),    intent(inout) :: CLOCK  ! the clock
      integer, optional,   intent(  out) :: RC     ! Error code:
      ! = 0 all is well
      ! otherwise, error
      !EOPI

      ! LOCAL VARIABLES

      character(len=ESMF_MAXSTR)                  :: IAm
      character(len=ESMF_MAXSTR)                  :: comp_name
      character(len=ESMF_MAXSTR)                  :: CHILD_NAME
      character(len=14)                           :: datestamp ! YYYYMMDD_HHMMz
      integer                                     :: status
      integer                                     :: I
      type (MAPL_MetaComp), pointer               :: STATE
      character(len=1)                            :: separator
      character(len=ESMF_MAXSTR)                  :: filetypechar
      character(len=4)                            :: extension
      integer                                     :: hdr
      class(DistributedProfiler), pointer                :: t_p
      class(DistributedProfiler), pointer                :: m_p
      type(ESMF_GridComp), pointer :: gridcomp
      type(ESMF_State), pointer :: child_import_state
      type(ESMF_State), pointer :: child_export_state
      !=============================================================================

      !  Begin...

      Iam = "MAPL_GenericRefresh"
      call ESMF_GridCompGet(GC, name=comp_name, RC=status )
      _VERIFY(status)
      Iam = trim(comp_name) // Iam

      ! Retrieve the pointer to the state
      !----------------------------------

      call MAPL_InternalStateRetrieve(GC, STATE, RC=status)
      _VERIFY(status)

      call state%t_profiler%start(_RC)
      call state%t_profiler%start('Refresh',_RC)

      call MAPL_TimerOn(STATE,"GenRefreshTot")
      ! Refresh the children
      ! ---------------------
      do I=1,STATE%get_num_children()
         gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
         call ESMF_GridCompGet( gridcomp, NAME=CHILD_NAME, RC=status )
         _VERIFY(status)
         call MAPL_TimerOn (STATE,trim(CHILD_NAME))
         child_import_state => STATE%get_child_import_state(i)
         child_export_state => STATE%get_child_export_state(i)
         call MAPL_GenericRefresh (gridcomp, child_import_state, child_export_state, CLOCK, &
              RC=status )
         _VERIFY(status)
         call MAPL_TimerOff(STATE,trim(CHILD_NAME),_RC)
      enddo

      ! Do my "own" refresh
      ! ------------------
      call MAPL_TimerOn(STATE,"GenRefreshMine")

      if (associated(STATE%RECORD)) then

         ! add timestamp to filename
         call MAPL_DateStampGet(clock, datestamp, rc=status)
         _VERIFY(status)

         !ALT: If any value of Record%filetype is MAPL_Write2RAM
         !     the restart must have been written to RAM by some component (or MAPL)
         !     and we read it from there (and ignore any disk files!)

         if (ANY(STATE%RECORD%FILETYPE == MAPL_Write2RAM)) then
            separator = '*'
         else
            separator = '.'
         end if

         I=STATE%RECORD%IMP_LEN
         if (I > 0) then
            call    MAPL_GetResource( STATE, filetypechar, LABEL="IMPORT_CHECKPOINT_TYPE:",                  RC=status )
            if ( status/=ESMF_SUCCESS  .or.  filetypechar == "default" ) then
               call MAPL_GetResource( STATE, filetypechar, LABEL="DEFAULT_CHECKPOINT_TYPE:", default='pnc4', RC=status )
               _VERIFY(status)
            end if
            filetypechar = ESMF_UtilStringLowerCase(filetypechar,rc=status)
            _VERIFY(status)
            if (filetypechar == 'pnc4') then
               extension = '.nc4'
            else
               extension = '.bin'
            end if
            STATE%RECORD%IMP_FNAME(I+1:) = separator // DATESTAMP // extension
         end if

         I=STATE%RECORD%INT_LEN
         if (I > 0) then
            call    MAPL_GetResource( STATE, hdr,      LABEL="INTERNAL_HEADER:",         default=0,      RC=status )
            _VERIFY(status)
            call    MAPL_GetResource( STATE, filetypechar, LABEL="INTERNAL_CHECKPOINT_TYPE:",                RC=status )
            if ( status/=ESMF_SUCCESS  .or.  filetypechar == "default" ) then
               call MAPL_GetResource( STATE, filetypechar, LABEL="DEFAULT_CHECKPOINT_TYPE:", default='pnc4', RC=status )
               _VERIFY(status)
            end if
            filetypechar = ESMF_UtilStringLowerCase(filetypechar,rc=status)
            _VERIFY(status)
            if (filetypechar == 'pnc4') then
               extension = '.nc4'
            else
               extension = '.bin'
            end if
            STATE%RECORD%INT_FNAME(I+1:) = separator // DATESTAMP // extension
         end if

         ! call the actual record method
         call MAPL_StateRefresh (GC, IMPORT, EXPORT, CLOCK, RC=status )
         _VERIFY(status)
      endif
      call MAPL_TimerOff(STATE,"GenRefreshMine",_RC)
      call MAPL_TimerOff(STATE,"GenRefreshTot",_RC)

      call state%t_profiler%stop('Refresh',_RC)
      call state%t_profiler%stop(_RC)

      _RETURN(ESMF_SUCCESS)
   end subroutine MAPL_GenericRefresh