Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp rpointer #500

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions cesm/driver/esm_time_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ subroutine esm_time_clockInit(ensemble_driver, instance_driver, logunit, maintas
logical :: isPresent
logical :: inDriver
logical, save :: firsttime=.true.
logical :: exists
character(len=*), parameter :: subname = '('//__FILE__//':esm_time_clockInit) '
!-------------------------------------------------------------------------------

Expand Down Expand Up @@ -130,7 +131,7 @@ subroutine esm_time_clockInit(ensemble_driver, instance_driver, logunit, maintas

if (read_restart) then

call NUOPC_CompAttributeGet(instance_driver, name='drv_restart_pointer', value=restart_file, rc=rc)
call NUOPC_CompAttributeGet(instance_driver, name='drv_restart_pointer', value=restart_pfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (trim(restart_file) /= 'none') then
Expand All @@ -140,13 +141,18 @@ subroutine esm_time_clockInit(ensemble_driver, instance_driver, logunit, maintas
if(isPresent) then
call NUOPC_CompAttributeGet(instance_driver, name="inst_suffix", value=inst_suffix, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_pfile = replace_text(restart_file, ".cpl", ".cpl."//inst_suffix)
else
inst_suffix = ""
endif

restart_pfile = trim(restart_file)//inst_suffix

if (maintask) then
inquire( file=trim(restart_pfile), exist=exists)
print *,__FILE__,__LINE__,trim(restart_pfile), exists
if (.not. exists) then
restart_pfile = "rpointer.cpl"
if (inst_suffix .ne. "") restart_pfile = trim(restart_pfile)//'.'//inst_suffix
endif

call ESMF_LogWrite(trim(subname)//" read rpointer file = "//trim(restart_pfile), &
ESMF_LOGMSG_INFO)
open(newunit=unitn, file=restart_pfile, form='FORMATTED', status='old',iostat=ierr)
Expand Down Expand Up @@ -323,7 +329,20 @@ subroutine esm_time_clockInit(ensemble_driver, instance_driver, logunit, maintas
if (ChkErr(rc,__LINE__,u_FILE_u)) return
firsttime = .false.
endif
end subroutine esm_time_clockInit
contains
mvertens marked this conversation as resolved.
Show resolved Hide resolved
FUNCTION Replace_Text (s,text,rep) RESULT(outs)
CHARACTER(len=*) :: s,text,rep
CHARACTER(LEN(s)+100) :: outs ! provide outs with extra 100 char len
INTEGER :: i, nt, nr

outs = s ; nt = LEN_TRIM(text) ; nr = LEN_TRIM(rep)
DO
i = INDEX(outs,text(:nt)) ; IF (i == 0) EXIT
outs = outs(:i-1) // rep(:nr) // outs(i+nt:)
END DO
END FUNCTION Replace_Text

end subroutine esm_time_clockInit

!===============================================================================

Expand Down
2 changes: 0 additions & 2 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
nmlgen.set_value(
"component_list", value=valid_comps_string.replace("CPL", "MED")
)
# the driver restart pointer will look like a mediator is present even if it is not
nmlgen.set_value("drv_restart_pointer", value="rpointer.cpl")

logger.info("Writing nuopc_runconfig for components {}".format(valid_comps))
nuopc_config_file = os.path.join(confdir, "nuopc.runconfig")
Expand Down
11 changes: 11 additions & 0 deletions cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@
</desc>
</entry>

<entry id="DRV_RESTART_POINTER">
mvertens marked this conversation as resolved.
Show resolved Hide resolved
<type>char</type>
<default_value>rpointer.cpl</default_value>
<group>run_begin_stop_restart</group>
<file>env_run.xml</file>
<desc>
Name of the restart pointer file, this can be used to restart from an
intermediate restart by appending the restart date and time in format YYYY-MM-DD-SSSSS
</desc>
</entry>

<entry id="PAUSE_OPTION">
<type>char</type>
<valid_values>none,never,nsteps,nseconds,nminutes,nhours,ndays,nmonths,nyears</valid_values>
Expand Down
4 changes: 2 additions & 2 deletions cime_config/namelist_definition_drv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@
</values>
</entry>

<entry id="drv_restart_pointer">
<entry id="drv_restart_pointer" modify_via_xml="DRV_RESTART_POINTER">
<type>char</type>
<category>expdef</category>
<group>DRIVER_attributes</group>
<desc>
Driver restart pointer file to initialize time info
</desc>
<values>
<value>rpointer.cpl</value>
<value>$DRV_RESTART_POINTER</value>
</values>
</entry>

Expand Down
51 changes: 23 additions & 28 deletions mediator/med_phases_restart_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ subroutine med_phases_restart_write(gcomp, rc)
use med_io_mod , only : med_io_close, med_io_date2yyyymmdd, med_io_sec2hms
use med_phases_history_mod, only : auxcomp
use med_constants_mod , only : SecPerDay => med_constants_SecPerDay

use nuopc_shr_methods , only : shr_get_rpointer_name
! Input/output variables
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
Expand Down Expand Up @@ -172,9 +172,9 @@ subroutine med_phases_restart_write(gcomp, rc)
character(ESMF_MAXSTR) :: case_name ! case name
character(ESMF_MAXSTR) :: restart_file ! Local path to restart filename
character(ESMF_MAXSTR) :: restart_pfile ! Local path to restart pointer filename
character(ESMF_MAXSTR) :: cpl_inst_tag ! instance tag
character(ESMF_MAXSTR) :: restart_dir ! Optional restart directory name
character(ESMF_MAXSTR) :: cvalue ! attribute string
character(ESMF_MAXSTR) :: cpl_inst_tag ! instance tag
logical :: alarmIsOn ! generic alarm flag
real(R8) :: tbnds(2) ! CF1.0 time bounds
logical :: isPresent
Expand All @@ -197,14 +197,6 @@ subroutine med_phases_restart_write(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name='case_name', value=case_name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', isPresent=isPresent, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if(isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', value=cpl_inst_tag, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
cpl_inst_tag = ""
endif
call NUOPC_CompAttributeGet(gcomp, name='restart_dir', isPresent=isPresent, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if(isPresent) then
Expand Down Expand Up @@ -296,12 +288,20 @@ subroutine med_phases_restart_write(gcomp, rc)
! Use nexttimestr rather than currtimestr here since that is the time at the end of
! the timestep and is preferred for restart file names
!---------------------------------------
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', isPresent=isPresent, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', value=cpl_inst_tag, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
cpl_inst_tag = ""
endif

write(restart_file,"(6a)") trim(restart_dir)//trim(case_name),'.cpl', trim(cpl_inst_tag),'.r.',&
trim(nexttimestr),'.nc'

if (maintask) then
restart_pfile = "rpointer.cpl"//trim(cpl_inst_tag)
call shr_get_rpointer_name(gcomp, 'cpl', next_ymd, next_tod, restart_pfile, 'write', rc)
call ESMF_LogWrite(trim(subname)//" write rpointer file = "//trim(restart_pfile), ESMF_LOGMSG_INFO)
open(newunit=unitn, file=restart_pfile, form='FORMATTED')
write(unitn,'(a)') trim(restart_file)
Expand Down Expand Up @@ -480,13 +480,14 @@ subroutine med_phases_restart_read(gcomp, rc)

! Read mediator restart

use ESMF , only : ESMF_GridComp, ESMF_VM, ESMF_Clock, ESMF_Time, ESMF_MAXSTR
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS, ESMF_FAILURE
use ESMF , only : ESMF_LOGMSG_ERROR, ESMF_VMBroadCast
use ESMF , only : ESMF_GridCompGet, ESMF_ClockGet, ESMF_ClockPrint
use ESMF , only : ESMF_FieldBundleIsCreated, ESMF_TimeGet
use NUOPC , only : NUOPC_CompAttributeGet
use med_io_mod , only : med_io_read
use ESMF , only : ESMF_GridComp, ESMF_VM, ESMF_Clock, ESMF_Time, ESMF_MAXSTR
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_SUCCESS, ESMF_FAILURE
use ESMF , only : ESMF_LOGMSG_ERROR, ESMF_VMBroadCast
use ESMF , only : ESMF_GridCompGet, ESMF_ClockGet, ESMF_ClockPrint
use ESMF , only : ESMF_FieldBundleIsCreated, ESMF_TimeGet
use NUOPC , only : NUOPC_CompAttributeGet
use med_io_mod , only : med_io_read
use nuopc_shr_methods, only : shr_get_rpointer_name

! Input/output variables
type(ESMF_GridComp) :: gcomp
Expand All @@ -501,10 +502,10 @@ subroutine med_phases_restart_read(gcomp, rc)
integer :: n
integer :: ierr, unitn
integer :: yr,mon,day,sec ! time units
integer :: curr_ymd
character(ESMF_MAXSTR) :: case_name ! case name
character(ESMF_MAXSTR) :: restart_file ! Local path to restart filename
character(ESMF_MAXSTR) :: restart_pfile ! Local path to restart pointer filename
character(ESMF_MAXSTR) :: cpl_inst_tag ! instance tag
logical :: isPresent
character(len=*), parameter :: subname='(med_phases_restart_read)'
!---------------------------------------
Expand All @@ -520,14 +521,6 @@ subroutine med_phases_restart_read(gcomp, rc)
! Get case name and inst suffix
call NUOPC_CompAttributeGet(gcomp, name='case_name', value=case_name, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', isPresent=isPresent, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='inst_suffix', value=cpl_inst_tag, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
cpl_inst_tag = ""
endif

! Get the clock info
call ESMF_GridCompGet(gcomp, clock=clock)
Expand All @@ -536,6 +529,8 @@ subroutine med_phases_restart_read(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_TimeGet(currtime,yy=yr, mm=mon, dd=day, s=sec, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ymd2date(yr,mon,day,curr_ymd)

write(currtimestr,'(i4.4,a,i2.2,a,i2.2,a,i5.5)') yr,'-',mon,'-',day,'-',sec
if (dbug_flag > 1) then
call ESMF_LogWrite(trim(subname)//": currtime = "//trim(currtimestr), ESMF_LOGMSG_INFO)
Expand All @@ -546,8 +541,8 @@ subroutine med_phases_restart_read(gcomp, rc)
endif

! Get the restart file name from the pointer file
restart_pfile = "rpointer.cpl"//trim(cpl_inst_tag)
if (maintask) then
call shr_get_rpointer_name(gcomp, 'cpl', curr_ymd, sec, restart_pfile, 'read', rc)
call ESMF_LogWrite(trim(subname)//" read rpointer file = "//trim(restart_pfile), ESMF_LOGMSG_INFO)
open(newunit=unitn, file=restart_pfile, form='FORMATTED', status='old', iostat=ierr)
read (unitn,'(a)', iostat=ierr) restart_file
Expand Down
Loading