recursive subroutine MAPL_GenericStateRestore ( 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
integer :: status
integer :: I
type (MAPL_MetaComp), pointer :: STATE
integer :: hdr, unit
type(ESMF_GridComp), pointer :: gridcomp
type(ESMF_State), pointer :: child_import_state
type(ESMF_State), pointer :: child_export_state
type(ESMF_State), pointer :: internal_state
!=============================================================================
! Begin...
_UNUSED_DUMMY(EXPORT)
Iam = "MAPL_GenericStateRestore"
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)
! 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)
child_import_state => STATE%get_child_import_state(i)
child_export_state => STATE%get_child_export_state(i)
call MAPL_GenericStateRestore (gridcomp, child_import_state, child_export_state, CLOCK, &
RC=status )
_VERIFY(status)
enddo
! Do my "own" refresh
! ------------------
call MAPL_TimerOn(STATE,"GenRefreshMine")
if (allocated(STATE%initial_state%imp_fname)) then
call MAPL_ESMFStateReadFromFile(IMPORT, CLOCK, &
STATE%initial_state%IMP_FNAME, &
STATE, .FALSE., RC=status)
_VERIFY(status)
end if
if (allocated(state%initial_state%int_fname)) then
call MAPL_GetResource( STATE , hdr, &
default=0, &
LABEL="INTERNAL_HEADER:", &
RC=status)
_VERIFY(status)
internal_state => state%get_internal_state()
call MAPL_ESMFStateReadFromFile(internal_state, CLOCK, &
STATE%initial_state%INT_FNAME, &
STATE, hdr/=0, RC=status)
_VERIFY(status)
UNIT = GETFILE(STATE%initial_state%INT_FNAME, RC=status)
_VERIFY(status)
end if
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_GenericStateRestore