From 56dc381243119192c245e74eeea8a19b5b5f3b9b Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 17 Oct 2024 11:14:20 -0600 Subject: [PATCH 1/3] support for cesm write_restart_at_endofrun --- .../infrastructure/io/io_pio2/ice_restart.F90 | 13 +++-- .../drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 50 +++++++++---------- .../drivers/nuopc/cmeps/ice_shr_methods.F90 | 11 +++- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index 2d98716b2..3ac98fdf1 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -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, & @@ -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, & @@ -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' @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index edf5d289a..213e3bb01 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/cicecore/drivers/nuopc/cmeps/ice_shr_methods.F90 b/cicecore/drivers/nuopc/cmeps/ice_shr_methods.F90 index 65596d822..94a2f8b23 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_shr_methods.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_shr_methods.F90 @@ -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 @@ -65,6 +65,7 @@ module ice_shr_methods optMonthly = "monthly" , & optYearly = "yearly" , & optDate = "date" , & + optEnd = "end" , & optIfdays0 = "ifdays0" ! Module data @@ -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)) From 11da279ba5b733250b061a769401328fabe9ca5c Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 17 Oct 2024 11:33:31 -0600 Subject: [PATCH 2/3] clean up merge --- .../infrastructure/io/io_pio2/ice_restart.F90 | 16 ++++++++-------- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 6 ++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index 3ac98fdf1..48a767101 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -64,6 +64,8 @@ subroutine init_restart_read(ice_ic) filename = trim(ice_ic) else if (my_task == master_task) then + write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') & + trim(pointer_file)//'.',myear,'-',mmonth,'-',mday,'-',msec open(nu_rst_pointer,file=pointer_file) read(nu_rst_pointer,'(a)') filename0 filename = trim(filename0) @@ -163,7 +165,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_pond_sealvl, tr_brine, tr_snow, & + tr_pond_topo, tr_pond_lvl, 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, & @@ -193,7 +195,6 @@ 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, & @@ -215,14 +216,14 @@ 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' ! write pointer (path/file) if (my_task == master_task) then + write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') & + trim(pointer_file)//'.',myear,'-',mmonth,'-',mday,'-',msec open(nu_rst_pointer,file=pointer_file) write(nu_rst_pointer,'(a)') filename close(nu_rst_pointer) @@ -336,7 +337,7 @@ subroutine init_restart_write(filename_spec) call define_rest_field(File,'a12_4',dims) endif - if (tr_pond_lvl .or. tr_pond_sealvl) then + if (tr_pond_lvl) then call define_rest_field(File,'fsnow',dims) endif @@ -428,7 +429,7 @@ subroutine init_restart_write(filename_spec) call define_rest_field(File,'ipnd',dims) end if - if (tr_pond_lvl .or. tr_pond_sealvl) then + if (tr_pond_lvl) then call define_rest_field(File,'apnd',dims) call define_rest_field(File,'hpnd',dims) call define_rest_field(File,'ipnd',dims) @@ -743,6 +744,7 @@ 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) @@ -771,8 +773,6 @@ 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 diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 213e3bb01..aaa149291 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -683,8 +683,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 @@ -850,7 +848,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 @@ -892,7 +890,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) ! Prescribed ice initialization !----------------------------------------------------------------- - call ice_prescribed_init(clock, ice_mesh, rc) + call ice_prescribed_init(gcomp, clock, ice_mesh, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return #ifdef CESMCOUPLED From b8232d795ce7a72bade321e06e4c64491ff772bf Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 17 Oct 2024 12:41:27 -0600 Subject: [PATCH 3/3] correct rpointer file name for cesm --- .../infrastructure/io/io_pio2/ice_restart.F90 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 index 48a767101..8ebca4b23 100644 --- a/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 +++ b/cicecore/cicedyn/infrastructure/io/io_pio2/ice_restart.F90 @@ -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 @@ -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 @@ -57,15 +59,19 @@ subroutine init_restart_read(ice_ic) integer (kind=int_kind) :: status logical (kind=log_kind), save :: first_call = .true. - + logical :: exist character(len=*), parameter :: subname = '(init_restart_read)' if (present(ice_ic)) then filename = trim(ice_ic) else if (my_task == master_task) then +#ifdef CESMCOUPLED write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') & - trim(pointer_file)//'.',myear,'-',mmonth,'-',mday,'-',msec + 'rpointer.ice'//trim(inst_suffix)//'.',myear,'-',mmonth,'-',mday,'-',msec + inquire(file=pointer_file, exist=exist) + if (.not. exist) pointer_file = 'rpointer.ice'//trim(inst_suffix) +#endif open(nu_rst_pointer,file=pointer_file) read(nu_rst_pointer,'(a)') filename0 filename = trim(filename0) @@ -222,8 +228,10 @@ subroutine init_restart_write(filename_spec) ! write pointer (path/file) if (my_task == master_task) then - write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') & - trim(pointer_file)//'.',myear,'-',mmonth,'-',mday,'-',msec +#ifdef CESMCOUPLED + write(pointer_file,'(a,i4.4,a,i2.2,a,i2.2,a,i5.5)') & + 'rpointer.ice'//trim(inst_suffix)//'.',myear,'-',mmonth,'-',mday,'-',msec +#endif open(nu_rst_pointer,file=pointer_file) write(nu_rst_pointer,'(a)') filename close(nu_rst_pointer)