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(BaseProfiler), pointer :: t_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)
t_p => get_global_time_profiler()
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