Skip to content

Commit

Permalink
Merge pull request #22 from GEOS-ESM/feature/rc_template
Browse files Browse the repository at this point in the history
Feature/rc template
  • Loading branch information
bena-nasa authored Aug 12, 2019
2 parents 32ed6b9 + c442acc commit 3e990ab
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 11 deletions.
89 changes: 78 additions & 11 deletions MAPL_Base/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module MAPL_GenericMod

use ESMF
use ESMFL_Mod
use ESMF_CFIOMod, only: ESMF_CFIOStrTemplate
use MAPL_BaseMod
use MAPL_IOMod
use MAPL_ProfMod
Expand Down Expand Up @@ -865,9 +866,12 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC )
logical :: ChldGridValid
integer :: reference_date
integer :: reference_time
integer :: yyyymmdd
integer :: yyyymmdd, hhmmss
integer :: year, month, day, hh, mm, ss
character(len=ESMF_MAXSTR) :: gridTypeAttribute
character(len=ESMF_MAXSTR) :: tmp_label, FILEtpl
character(len=ESMF_MAXSTR) :: id_string
integer :: ens_id_width
real(ESMF_KIND_R8) :: fixedLons, fixedLats
type(ESMF_GridComp) :: GCCS ! this is needed as a workaround
! for recursive ESMF method within method
Expand Down Expand Up @@ -1182,10 +1186,11 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC )
VERIFY_(STATUS)

! get current time from clock and create a reference time with optonal override
call ESMF_TimeGet( currTime, YY = YEAR, MM = MONTH, DD = DAY, rc = STATUS )
call ESMF_TimeGet( currTime, YY = YEAR, MM = MONTH, DD = DAY, H=HH, M=MM, S=SS, rc = STATUS )
VERIFY_(STATUS)

yyyymmdd = year*10000 + month*100 + day
hhmmss = HH*10000 + MM*100 + SS

! Get Alarm reference date and time from resouce, it defaults to midnight of the current day
call MAPL_GetResource (STATE, reference_date, label='REFERENCE_DATE:', &
Expand Down Expand Up @@ -1332,6 +1337,10 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC )
deallocate(R_FILETYPE, R_ALARM)
endif

call MAPL_GetResource( STATE, ens_id_width, &
LABEL="ENS_ID_WIDTH:", default=0, &
RC=STATUS)

if (associated(STATE%RECORD)) then
call MAPL_GetResource( STATE, FILENAME, &
LABEL="IMPORT_CHECKPOINT_FILE:", &
Expand All @@ -1342,11 +1351,24 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC )
else
STATE%RECORD%IMP_LEN = 0
end if

call MAPL_GetResource( STATE, FILENAME, &
LABEL="INTERNAL_CHECKPOINT_FILE:", &
RC=STATUS)

id_string=""
tmp_label = "INTERNAL_CHECKPOINT_FILE:"
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
if((STATUS /= ESMF_SUCCESS) .and. ens_id_width > 0) then
i = len(trim(COMP_NAME))
id_string = COMP_NAME(i-ens_id_width+1:i)
tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label)
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
endif

if(STATUS==ESMF_SUCCESS) then
! if the filename is tempate
call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = trim(id_string), nymd=yyyymmdd,nhms=hhmmss,stat=status)
STATE%RECORD%INT_FNAME = FILENAME
STATE%RECORD%INT_LEN = LEN_TRIM(FILENAME)
else
Expand Down Expand Up @@ -1491,10 +1513,23 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC )
end if
VERIFY_(STATUS)

call MAPL_GetResource( STATE , FILENAME, &
LABEL="INTERNAL_RESTART_FILE:", &
id_string = ""
tmp_label = "INTERNAL_RESTART_FILE:"
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
if((STATUS /=ESMF_SUCCESS) .and. ens_id_width >0) then
i = len(trim(COMP_NAME))
id_string = COMP_NAME(i-ens_id_width+1:i)
tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label)
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
endif

if(STATUS==ESMF_SUCCESS) then
! if the filename is tempate
call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = trim(id_string), nymd=yyyymmdd,nhms=hhmmss,stat=status)
call MAPL_GetResource( STATE , hdr, &
default=0, &
LABEL="INTERNAL_HEADER:", &
Expand Down Expand Up @@ -1730,15 +1765,20 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC )
character(len=ESMF_MAXSTR) :: CHILD_NAME
character(len=ESMF_MAXSTR) :: RECFIN
type (MAPL_MetaComp), pointer :: STATE
integer :: I
integer :: I,j
logical :: final_checkpoint
integer :: NC
integer :: PHASE
integer :: NUMPHASES
integer :: MAXPHASES
type (MAPL_MetaPtr), allocatable :: CHLDMAPL(:)
integer :: hdr

integer :: yyyymmdd, hhmmss
integer :: year, month, day, hh, mm, ss
character(len=ESMF_MAXSTR) :: tmp_label, FILEtpl
character(len=ESMF_MAXSTR) :: id_string
integer :: ens_id_width
type(ESMF_Time) :: CurrTime
!=============================================================================

! Begin...
Expand Down Expand Up @@ -1806,8 +1846,35 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC )
! Checkpoint the internal state if required.
!------------------------------------------

call MAPL_GetResource( STATE, FILENAME, LABEL="INTERNAL_CHECKPOINT_FILE:", RC=STATUS )
call ESMF_ClockGet (clock, currTime=currTime, rc=status)
VERIFY_(STATUS)
call ESMF_TimeGet( currTime, YY = YEAR, MM = MONTH, DD = DAY, H=HH, M=MM, S=SS, rc = STATUS )
VERIFY_(STATUS)

yyyymmdd = year*10000 + month*100 + day
hhmmss = HH*10000 + MM*100 + SS

call MAPL_GetResource( STATE, ens_id_width, &
LABEL="ENS_ID_WIDTH:", default=0, &
RC=STATUS)

id_string=""
tmp_label = "INTERNAL_CHECKPOINT_FILE:"
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
if((STATUS /= ESMF_SUCCESS) .and. ens_id_width>0) then
i = len(trim(COMP_NAME))
id_string = COMP_NAME(i-ens_id_width+1:i)
tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label)
call MAPL_GetResource( STATE , FILEtpl, &
LABEL=trim(tmp_label), &
RC=STATUS)
endif

if(STATUS==ESMF_SUCCESS) then
! if the filename is tempate
call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = trim(id_string), nymd=yyyymmdd,nhms=hhmmss,stat=status)
call MAPL_GetResource( STATE, FILETYPE, LABEL="INTERNAL_CHECKPOINT_TYPE:", RC=STATUS )
if ( STATUS/=ESMF_SUCCESS .or. FILETYPE == "default" ) then
call MAPL_GetResource( STATE, FILETYPE, LABEL="DEFAULT_CHECKPOINT_TYPE:", default='pnc4', RC=STATUS )
Expand Down
1 change: 1 addition & 0 deletions MAPL_Base/MAPL_HistoryGridComp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,7 @@ subroutine Run ( gc, import, export, clock, rc )
end if

if( MAPL_AM_I_ROOT() ) then
if (index(list(n)%format,'flat') == 0 ) &
write(6,'(1X,"Writing: ",i6," Slices (",i4," Nodes, ",i4," PartitionRoot) to File: ",a)') &
list(n)%Slices,list(n)%Psize,list(n)%Root, &
trim(MAPL_CFIOGetFilename(list(n)%MCFIO))
Expand Down
8 changes: 8 additions & 0 deletions MAPL_Base/MAPL_LocStreamMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK,
VERIFY_(STATUS)
end do

! adjust EASE grid index from tile file
do N=1,STREAM%N_GRIDS
if(index(STREAM%TILING(N)%NAME,'EASE') /=0 ) then
AVR(:,NumGlobalVars+1+NumLocalVars*(N-1)) = AVR(:,NumGlobalVars+1+NumLocalVars*(N-1))+1
AVR(:,NumGlobalVars+2+NumLocalVars*(N-1)) = AVR(:,NumGlobalVars+2+NumLocalVars*(N-1))+1
endif
enddo

call FREE_FILE(UNIT)

! Allocate msk for which tiles to include in the stream being created.
Expand Down

0 comments on commit 3e990ab

Please sign in to comment.