Skip to content

Commit

Permalink
support for cesm write_restart_at_endofrun
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Oct 17, 2024
1 parent 68b2610 commit 56dc381
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
13 changes: 8 additions & 5 deletions cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ subroutine init_restart_write(filename_spec)

logical (kind=log_kind) :: &
tr_iage, tr_FY, tr_lvl, tr_iso, tr_aero, &
tr_pond_topo, tr_pond_lvl, tr_brine, tr_snow, &
tr_pond_topo, tr_pond_lvl, tr_pond_sealvl, tr_brine, tr_snow, &
tr_bgc_N, tr_bgc_C, tr_bgc_Nit, &
tr_bgc_Sil, tr_bgc_DMS, &
tr_bgc_chl, tr_bgc_Am, &
Expand Down Expand Up @@ -193,6 +193,7 @@ subroutine init_restart_write(filename_spec)
tr_iage_out=tr_iage, tr_FY_out=tr_FY, tr_lvl_out=tr_lvl, &
tr_iso_out=tr_iso, tr_aero_out=tr_aero, &
tr_pond_topo_out=tr_pond_topo, tr_pond_lvl_out=tr_pond_lvl, &
tr_pond_sealvl_out=tr_pond_sealvl, &
tr_snow_out=tr_snow, tr_brine_out=tr_brine, &
tr_bgc_N_out=tr_bgc_N, tr_bgc_C_out=tr_bgc_C, tr_bgc_Nit_out=tr_bgc_Nit, &
tr_bgc_Sil_out=tr_bgc_Sil, tr_bgc_DMS_out=tr_bgc_DMS, &
Expand All @@ -214,6 +215,8 @@ subroutine init_restart_write(filename_spec)
restart_dir(1:lenstr(restart_dir)), &
restart_file(1:lenstr(restart_file)),'.', &
myear,'-',mmonth,'-',mday,'-',msec
write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') &
'rpointer.ice.',myear,'-',mmonth,'-',mday,'-',msec
end if

if (restart_format(1:3) /= 'bin') filename = trim(filename) // '.nc'
Expand Down Expand Up @@ -333,7 +336,7 @@ subroutine init_restart_write(filename_spec)
call define_rest_field(File,'a12_4',dims)
endif

if (tr_pond_lvl) then
if (tr_pond_lvl .or. tr_pond_sealvl) then
call define_rest_field(File,'fsnow',dims)
endif

Expand Down Expand Up @@ -425,7 +428,7 @@ subroutine init_restart_write(filename_spec)
call define_rest_field(File,'ipnd',dims)
end if

if (tr_pond_lvl) then
if (tr_pond_lvl .or. tr_pond_sealvl) then
call define_rest_field(File,'apnd',dims)
call define_rest_field(File,'hpnd',dims)
call define_rest_field(File,'ipnd',dims)
Expand Down Expand Up @@ -741,8 +744,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
call pio_read_darray(File, vardesc, iodesc3d_ncat, work, status)
#ifdef CESMCOUPLED
Expand Down Expand Up @@ -770,6 +771,8 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, &
call ice_pio_check(status, &
subname//" ERROR: reading var "//trim(vname),file=__FILE__,line=__LINE__)

call pio_seterrorhandling(File, PIO_INTERNAL_ERROR)

if (diag) then
if (ndim3 > 1) then
do n=1,ndim3
Expand Down
50 changes: 25 additions & 25 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ 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

Expand Down Expand Up @@ -850,7 +850,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
idate0 = start_ymd
year_init = (idate0/10000)
month_init= (idate0-year_init*10000)/100 ! integer month of basedate
day_init = idate0-year_init*10000-month_init*100
day_init = idate0-year_init*10000-month_init*100

! - Set use_leap_years based on calendar (as some CICE calls use this instead of the calendar type)
if (calendar_type == ice_calendar_gregorian) then
Expand Down Expand Up @@ -892,7 +892,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! Prescribed ice initialization
!-----------------------------------------------------------------

call ice_prescribed_init(gcomp, clock, ice_mesh, rc)
call ice_prescribed_init(clock, ice_mesh, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

#ifdef CESMCOUPLED
Expand Down Expand Up @@ -1330,51 +1330,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 56dc381

Please sign in to comment.