From e36959909648fc29b43251e243f1de91d626c119 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 7 Aug 2019 16:32:22 -0400 Subject: [PATCH 1/3] template rc input string --- MAPL_Base/MAPL_Generic.F90 | 96 +++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/MAPL_Base/MAPL_Generic.F90 b/MAPL_Base/MAPL_Generic.F90 index 6d20bbdb53ea..6d72518335ef 100644 --- a/MAPL_Base/MAPL_Generic.F90 +++ b/MAPL_Base/MAPL_Generic.F90 @@ -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 @@ -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=:),allocatable :: ens_id + 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 @@ -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:', & @@ -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) + allocate(character(len=ens_id_width):: ens_id) if (associated(STATE%RECORD)) then call MAPL_GetResource( STATE, FILENAME, & LABEL="IMPORT_CHECKPOINT_FILE:", & @@ -1342,11 +1351,26 @@ 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) + + ens_id="" + 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)) + ens_id = COMP_NAME(i-ens_id_width+1:i) + read(ens_id,*,IOSTAT=status) j + !if is a ensemble number + if(status == 0) 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 = ens_id, nymd=yyyymmdd,nhms=hhmmss,stat=status) STATE%RECORD%INT_FNAME = FILENAME STATE%RECORD%INT_LEN = LEN_TRIM(FILENAME) else @@ -1491,10 +1515,25 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) end if VERIFY_(STATUS) - call MAPL_GetResource( STATE , FILENAME, & - LABEL="INTERNAL_RESTART_FILE:", & + ens_id = "" + 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)) + ens_id = COMP_NAME(i-ens_id_width+1:i) + read(ens_id,*,IOSTAT=status) j + !if is a ensemble number + if(status == 0) 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 = ens_id, nymd=yyyymmdd,nhms=hhmmss,stat=status) call MAPL_GetResource( STATE , hdr, & default=0, & LABEL="INTERNAL_HEADER:", & @@ -1730,7 +1769,7 @@ 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 @@ -1738,7 +1777,12 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) 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=:), allocatable :: ens_id + integer :: ens_id_width + type(ESMF_Time) :: CurrTime !============================================================================= ! Begin... @@ -1806,8 +1850,38 @@ 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) + allocate(character(len=ens_id_width):: ens_id) + + ens_id="" + 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)) + ens_id = COMP_NAME(i-ens_id_width+1:i) + read(ens_id,*,IOSTAT=status) j + !if is a ensemble number + if(status == 0) 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 = ens_id, 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 ) From 5569a5819688a35715459536d27cc5aa041dc9f2 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 8 Aug 2019 11:18:07 -0400 Subject: [PATCH 2/3] correct EASE index and log binary --- MAPL_Base/MAPL_HistoryGridComp.F90 | 1 + MAPL_Base/MAPL_LocStreamMod.F90 | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/MAPL_Base/MAPL_HistoryGridComp.F90 b/MAPL_Base/MAPL_HistoryGridComp.F90 index b7570380d217..c87248bd127f 100644 --- a/MAPL_Base/MAPL_HistoryGridComp.F90 +++ b/MAPL_Base/MAPL_HistoryGridComp.F90 @@ -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)) diff --git a/MAPL_Base/MAPL_LocStreamMod.F90 b/MAPL_Base/MAPL_LocStreamMod.F90 index 83f512660df3..626cae205b18 100644 --- a/MAPL_Base/MAPL_LocStreamMod.F90 +++ b/MAPL_Base/MAPL_LocStreamMod.F90 @@ -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. From c442accb2a2777a435e418a2a9ce9353af3d22ef Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 8 Aug 2019 14:02:21 -0400 Subject: [PATCH 3/3] rename to id_string --- MAPL_Base/MAPL_Generic.F90 | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/MAPL_Base/MAPL_Generic.F90 b/MAPL_Base/MAPL_Generic.F90 index 6d72518335ef..78b093ea8fb0 100644 --- a/MAPL_Base/MAPL_Generic.F90 +++ b/MAPL_Base/MAPL_Generic.F90 @@ -870,7 +870,7 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: year, month, day, hh, mm, ss character(len=ESMF_MAXSTR) :: gridTypeAttribute character(len=ESMF_MAXSTR) :: tmp_label, FILEtpl - character(len=:),allocatable :: ens_id + 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 @@ -1340,7 +1340,7 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_GetResource( STATE, ens_id_width, & LABEL="ENS_ID_WIDTH:", default=0, & RC=STATUS) - allocate(character(len=ens_id_width):: ens_id) + if (associated(STATE%RECORD)) then call MAPL_GetResource( STATE, FILENAME, & LABEL="IMPORT_CHECKPOINT_FILE:", & @@ -1352,17 +1352,15 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) STATE%RECORD%IMP_LEN = 0 end if - ens_id="" + 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)) - ens_id = COMP_NAME(i-ens_id_width+1:i) - read(ens_id,*,IOSTAT=status) j - !if is a ensemble number - if(status == 0) tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label) + 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) @@ -1370,7 +1368,7 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) if(STATUS==ESMF_SUCCESS) then ! if the filename is tempate - call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = ens_id, nymd=yyyymmdd,nhms=hhmmss,stat=status) + 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 @@ -1515,17 +1513,15 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) end if VERIFY_(STATUS) - ens_id = "" + 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)) - ens_id = COMP_NAME(i-ens_id_width+1:i) - read(ens_id,*,IOSTAT=status) j - !if is a ensemble number - if(status == 0) tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label) + 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) @@ -1533,7 +1529,7 @@ recursive subroutine MAPL_GenericInitialize ( GC, IMPORT, EXPORT, CLOCK, RC ) if(STATUS==ESMF_SUCCESS) then ! if the filename is tempate - call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = ens_id, nymd=yyyymmdd,nhms=hhmmss,stat=status) + 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:", & @@ -1780,7 +1776,7 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: yyyymmdd, hhmmss integer :: year, month, day, hh, mm, ss character(len=ESMF_MAXSTR) :: tmp_label, FILEtpl - character(len=:), allocatable :: ens_id + character(len=ESMF_MAXSTR) :: id_string integer :: ens_id_width type(ESMF_Time) :: CurrTime !============================================================================= @@ -1861,19 +1857,16 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_GetResource( STATE, ens_id_width, & LABEL="ENS_ID_WIDTH:", default=0, & RC=STATUS) - allocate(character(len=ens_id_width):: ens_id) - ens_id="" + 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)) - ens_id = COMP_NAME(i-ens_id_width+1:i) - read(ens_id,*,IOSTAT=status) j - !if is a ensemble number - if(status == 0) tmp_label =COMP_NAME(1:i-ens_id_width)//"_"//trim(tmp_label) + 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) @@ -1881,7 +1874,7 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) if(STATUS==ESMF_SUCCESS) then ! if the filename is tempate - call ESMF_CFIOStrTemplate(FILENAME, trim(adjustl(FILEtpl)),'GRADS', xid = ens_id, nymd=yyyymmdd,nhms=hhmmss,stat=status) + 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 )