MAPL_GenericStateSave Subroutine

public recursive subroutine MAPL_GenericStateSave(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

MAPL_GenericStateSavewArrDescrCreateReaderComm
w
wArrDescrCreateWriterComm
w
wArrDescrSet
w
wCompositeComponent%get_num_children
w
wESMF_AttributeGet
w
wESMF_ClockGet
w
wESMF_GridGet
w
wesmf_stateget
w
wESMF_TimeGet
w
wESMF_UtilStringLowerCase
w
wFREE_FILE
w
wGETFILE
w
wLogger%warning
w
wMAPL_Am_I_Root
w
wMAPL_Assert
w
wMAPL_DateStampGet
w
wMAPL_GenericStateSave
w
wMAPL_GetLogger
w
wMAPL_GetResource
w
wMAPL_GridGet
w
wMAPL_InternalStateRetrieve
w
wMAPL_LocStreamGet
w
wMAPL_LocStreamIsAssociated
w
wMAPL_MetaComp%get_child_export_state
w
wMAPL_MetaComp%get_child_gridcomp
w
wMAPL_MetaComp%get_child_import_state
w
wMAPL_Return
w
wMAPL_VarWrite
w
wMAPL_VarWriteNCPar
w
wMAPL_Verify
w
wMaplGenericComponent%get_internal_state
w
wmpi_barrier
w
wmpi_comm_rank
w
wmpi_file_close
w
wmpi_file_open
w
wmpi_info_create
w
wmpi_info_free
w
wmpi_info_set
w
wWRITE_PARALLEL
w

Source Code

   recursive subroutine MAPL_GenericStateSave( GC, IMPORT, EXPORT, CLOCK, RC )
      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:

      type(mapl_metacomp), pointer :: state
      integer :: i,filetype

      character(len=14)                           :: datestamp
      character(len=1)                            :: separator

      character(len=ESMF_MAXSTR)                  :: filetypechar
      character(len=4)                            :: extension
      integer                                     :: hdr
      integer :: status
      character(len=:), allocatable :: tmpstr
      character(len=ESMF_MAXSTR) :: filename
      character(len=ESMF_MAXSTR)                  :: CFILETYPE
      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

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

      call MAPL_GetResource( STATE, FILENAME,         &
           LABEL="IMPORT_CHECKPOINT_FILE:", &
           RC=status)
      if(status==ESMF_SUCCESS) then
         _ASSERT(.not.allocated(state%initial_state%imp_fname),"can only save one state")
         STATE%initial_state%IMP_FNAME = FILENAME
      end if
      call MAPL_GetResource( STATE   , filename,  &
           LABEL="INTERNAL_CHECKPOINT_FILE:", &
           RC=status)
      if(status==ESMF_SUCCESS) then
         _ASSERT(.not.allocated(state%initial_state%int_fname),"can only save one state")
         STATE%initial_state%INT_FNAME = FILENAME
      end if

      do I=1,STATE%get_num_children()
         gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
         child_import_state => STATE%get_child_import_state(i)
         child_export_state => STATE%get_child_export_state(i)
         call MAPL_GenericStateSave (gridcomp, &
              child_import_state, &
              child_export_state, &
              CLOCK, RC=status )
         _VERIFY(status)
      enddo

      call MAPL_DateStampGet(clock, datestamp, rc=status)
      _VERIFY(status)
      filetype=state%initial_state%filetype
      if (FILETYPE /= MAPL_Write2Disk) then
         separator = '*'
      else
         separator = '.'
      end if

      if (allocated(state%initial_state%imp_fname)) 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
         tmpstr=trim(state%initial_state%imp_fname)
         deallocate(state%initial_state%imp_fname)
         STATE%initial_state%IMP_FNAME = tmpstr // separator // DATESTAMP // extension
         deallocate(tmpstr)
      end if

      if (allocated(state%initial_state%int_fname)) 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
         tmpstr=trim(state%initial_state%int_fname)
         deallocate(state%initial_state%int_fname)
         STATE%initial_state%INT_FNAME = tmpstr // separator // DATESTAMP // extension
         deallocate(tmpstr)
      end if

      if (allocated(state%initial_state%imp_fname)) then
         call    MAPL_GetResource( STATE, CFILETYPE, LABEL="IMPORT_CHECKPOINT_TYPE:",                  RC=status )
         if ( status/=ESMF_SUCCESS  .or.  CFILETYPE == "default" ) then
            call MAPL_GetResource( STATE, CFILETYPE, LABEL="DEFAULT_CHECKPOINT_TYPE:", default='pnc4', RC=status )
            _VERIFY(status)
         end if
         call MAPL_ESMFStateWriteToFile(IMPORT, CLOCK, &
              STATE%initial_state%IMP_FNAME, &
              CFILETYPE, STATE, .FALSE.,  write_with_oserver = state%grid%write_restart_by_oserver, &
              RC=status)
         _VERIFY(status)
      end if

      if (allocated(state%initial_state%int_fname)) then
         call    MAPL_GetResource( STATE, hdr,      LABEL="INTERNAL_HEADER:",         default=0,      RC=status )
         _VERIFY(status)
         call    MAPL_GetResource( STATE, CFILETYPE, LABEL="INTERNAL_CHECKPOINT_TYPE:",                RC=status )
         if ( status/=ESMF_SUCCESS  .or.  CFILETYPE == "default" ) then
            call MAPL_GetResource( STATE, CFILETYPE, LABEL="DEFAULT_CHECKPOINT_TYPE:", default='pnc4', RC=status )
            _VERIFY(status)
         end if
         internal_state => STATE%get_internal_state()
         call MAPL_ESMFStateWriteToFile(internal_state, CLOCK, &
              STATE%initial_state%INT_FNAME, &
              CFILETYPE, STATE, hdr/=0, write_with_oserver = state%grid%write_restart_by_oserver, &
              RC=status)
         _VERIFY(status)
      end if

      _RETURN(ESMF_SUCCESS)
   end subroutine MAPL_GenericStateSave