Skip to content

Commit

Permalink
This adds additional write restart at end of run functionality. (CICE…
Browse files Browse the repository at this point in the history
…-Consortium#984)

* support for cesm write_restart_at_endofrun

* clean up merge

* correct rpointer file name for cesm

* response to review

* correct exist and file_exist

* get pointer file name root from ice_in namelist and append timestamp for cesm

* Update cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90

Co-authored-by: Anton Steketee <[email protected]>

* the pointer_file name is set in namelist, no need to modify here

* cleanup whitespace

* need to use default cesm pointer name for write and not read from ice_in namelist

---------

Co-authored-by: Jim Edwards <[email protected]>
Co-authored-by: Anton Steketee <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent 87c7bfa commit 7a4eb51
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
14 changes: 11 additions & 3 deletions cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module ice_restart
use ice_communicate, only: my_task, master_task
use ice_exit, only: abort_ice
use ice_fileunits, only: nu_diag, nu_restart, nu_rst_pointer
#ifdef CESMCOUPLED
use ice_fileunits, only: inst_suffix
#endif
use ice_kinds_mod
use ice_restart_shared
use ice_pio
Expand Down Expand Up @@ -46,7 +49,6 @@ subroutine init_restart_read(ice_ic)
mday, msec, npt
use ice_domain_size, only: ncat
use ice_read_write, only: ice_open

character(len=char_len_long), intent(in), optional :: ice_ic

! local variables
Expand Down Expand Up @@ -174,6 +176,7 @@ subroutine init_restart_write(filename_spec)
integer (kind=int_kind) :: nbtrcr

character(len=char_len_long) :: filename
character(len=char_len_long) :: lpointer_file

integer (kind=int_kind) :: &
dimid_ncat, dimid_nilyr, dimid_nslyr, dimid_naero
Expand Down Expand Up @@ -220,7 +223,13 @@ subroutine init_restart_write(filename_spec)

! write pointer (path/file)
if (my_task == master_task) then
open(nu_rst_pointer,file=pointer_file)
#ifdef CESMCOUPLED
write(lpointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') &
'rpointer.ice'//trim(inst_suffix)//'.',myear,'-',mmonth,'-',mday,'-',msec
#else
lpointer_file = pointer_file
#endif
open(nu_rst_pointer,file=lpointer_file)
write(nu_rst_pointer,'(a)') filename
close(nu_rst_pointer)
endif
Expand Down Expand Up @@ -740,7 +749,6 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, &

call ice_pio_check(pio_inq_varndims(File, vardesc, ndims), &
subname// " ERROR: missing varndims "//trim(vname),file=__FILE__,line=__LINE__)

call pio_seterrorhandling(File, PIO_INTERNAL_ERROR)

if (ndim3 == ncat .and. ndims == 3) then
Expand Down
46 changes: 22 additions & 24 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,6 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if(mastertask) write(nu_diag,*) trim(subname)//'WARNING: pio_typename from driver needs to be set for netcdf output to work'
end if



#else

! Read the cice namelist as part of the call to cice_init1
Expand Down Expand Up @@ -1331,51 +1329,51 @@ subroutine ModelSetRunClock(gcomp, rc)
call ESMF_LogWrite(subname//'setting alarms for ' // trim(name), ESMF_LOGMSG_INFO)

!----------------
! Restart alarm
! Stop alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_n
read(cvalue,*) stop_n

call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="stop_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) restart_ymd
read(cvalue,*) stop_ymd

call alarmInit(mclock, restart_alarm, restart_option, &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
call alarmInit(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_restart', rc=rc)
alarmname = 'alarm_stop', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

!----------------
! Stop alarm
! Restart alarm
!----------------
call NUOPC_CompAttributeGet(gcomp, name="stop_option", value=stop_option, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_option", value=restart_option, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeGet(gcomp, name="stop_n", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_n", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_n
read(cvalue,*) restart_n

call NUOPC_CompAttributeGet(gcomp, name="stop_ymd", value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name="restart_ymd", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) stop_ymd
read(cvalue,*) restart_ymd

call alarmInit(mclock, stop_alarm, stop_option, &
opt_n = stop_n, &
opt_ymd = stop_ymd, &
call alarmInit(mclock, restart_alarm, restart_option, &
opt_n = restart_n, &
opt_ymd = restart_ymd, &
RefTime = mcurrTime, &
alarmname = 'alarm_stop', rc=rc)
alarmname = 'alarm_restart', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_AlarmSet(stop_alarm, clock=mclock, rc=rc)
call ESMF_AlarmSet(restart_alarm, clock=mclock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

end if
Expand Down
11 changes: 10 additions & 1 deletion cicecore/drivers/nuopc/cmeps/ice_shr_methods.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ice_shr_methods
use ESMF , only : ESMF_Mesh, ESMF_MeshGet
use ESMF , only : ESMF_GEOMTYPE_MESH, ESMF_GEOMTYPE_GRID, ESMF_FIELDSTATUS_COMPLETE
use ESMF , only : ESMF_Clock, ESMF_ClockCreate, ESMF_ClockGet, ESMF_ClockSet
use ESMF , only : ESMF_ClockPrint, ESMF_ClockAdvance
use ESMF , only : ESMF_ClockPrint, ESMF_ClockAdvance, ESMF_ClockGetAlarm
use ESMF , only : ESMF_Alarm, ESMF_AlarmCreate, ESMF_AlarmGet, ESMF_AlarmSet
use ESMF , only : ESMF_Calendar, ESMF_CALKIND_NOLEAP, ESMF_CALKIND_GREGORIAN
use ESMF , only : ESMF_Time, ESMF_TimeGet, ESMF_TimeSet
Expand Down Expand Up @@ -65,6 +65,7 @@ module ice_shr_methods
optMonthly = "monthly" , &
optYearly = "yearly" , &
optDate = "date" , &
optEnd = "end" , &
optIfdays0 = "ifdays0"

! Module data
Expand Down Expand Up @@ -920,6 +921,14 @@ subroutine alarmInit( clock, alarm, option, &
if (chkerr(rc,__LINE__,u_FILE_u)) return
update_nextalarm = .true.

case (optEnd)
call ESMF_TimeIntervalSet(AlarmInterval, yy=9999, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGetAlarm(clock, alarmname="alarm_stop", alarm=alarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmGet(alarm, ringTime=NextAlarm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

case default
call abort_ice(subname//'unknown option '//trim(option))

Expand Down

0 comments on commit 7a4eb51

Please sign in to comment.