From 9e30017848290a4d0bfafa540fcf8aa2361a5f0e Mon Sep 17 00:00:00 2001 From: dpsarmie Date: Tue, 23 Apr 2024 17:44:48 +0000 Subject: [PATCH 1/6] Add end of run restart file functionality This commit changes the ice_comp_nuopc file to add the ability to create a restart file at the end of a run. When the stop_alarm is active, the code will now force a restart file to be written. --- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index efadabbda..842b09746 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -1132,7 +1132,13 @@ subroutine ModelAdvance(gcomp, rc) write(restart_date,"(i4.4,a,i2.2,a,i2.2,a,i5.5)") yy, '-', mm, '-',dd,'-',tod write(restart_filename,'(4a)') trim(restart_dir), trim(restart_file), '.', trim(restart_date) else - force_restart_now = .false. + call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + if (ESMF_AlarmIsRinging(alarm, rc=rc)) then + force_restart_now = .true. + else + force_restart_now = .false. + endif endif !-------------------------------- From 40c5cce887fecfa52fd21011e4af0f38551acb75 Mon Sep 17 00:00:00 2001 From: dpsarmie Date: Wed, 24 Apr 2024 15:56:47 +0000 Subject: [PATCH 2/6] Add CICE write_restart_at_endofrun config option call This will allow the user to set the write_restart_at_endofrun option in the ufs.configure.*.IN file to control the creation of the restart file at the end of the run. This single config option controls restart files for CMEPS, MOM, and CICE. --- .../drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 842b09746..67794c32e 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -1118,6 +1118,8 @@ subroutine ModelAdvance(gcomp, rc) call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return + force_restart_now = .false. + if (ESMF_AlarmIsRinging(alarm, rc=rc)) then if (ChkErr(rc,__LINE__,u_FILE_u)) return force_restart_now = .true. @@ -1131,14 +1133,16 @@ subroutine ModelAdvance(gcomp, rc) write(restart_date,"(i4.4,a,i2.2,a,i2.2,a,i5.5)") yy, '-', mm, '-',dd,'-',tod write(restart_filename,'(4a)') trim(restart_dir), trim(restart_file), '.', trim(restart_date) - else - call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc) - if (ChkErr(rc,__LINE__,u_FILE_u)) return - if (ESMF_AlarmIsRinging(alarm, rc=rc)) then - force_restart_now = .true. - else - force_restart_now = .false. - endif + endif + + ! Handle end of run restart + call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, 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 + + if (isPresent .and. isSet .and. ESMF_AlarmIsRinging(alarm, rc=rc)) then + if (trim(cvalue) .eq. '.true.') force_restart_now = .true. endif !-------------------------------- From 0dfc2bb7b655da1f2c5ca593e22ca6f395101f16 Mon Sep 17 00:00:00 2001 From: dpsarmie Date: Thu, 25 Apr 2024 15:10:57 +0000 Subject: [PATCH 3/6] Move configuration check to IntializeAdvertise The check for the write_restart_at_endofrun config option was going to run at each model step. This change will run the check once and set a logical variable for the subsequent check. --- .../drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 67794c32e..22ce8a105 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -95,6 +95,7 @@ module ice_comp_nuopc logical :: profile_memory = .false. logical :: mastertask logical :: runtimelog = .false. + logical :: restart_eor = .false. !End of run restart flag integer :: start_ymd ! Start date (YYYYMMDD) integer :: start_tod ! start time of day (s) integer :: curr_ymd ! Current date (YYYYMMDD) @@ -316,6 +317,12 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) write(logmsg,*) runtimelog call ESMF_LogWrite('CICE_cap:RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO) + call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + if (isPresent .and. isSet) then + if (trim(cvalue) .eq. '.true.') restart_eor = .true. + endif + !---------------------------------------------------------------------------- ! generate local mpi comm !---------------------------------------------------------------------------- @@ -1136,13 +1143,10 @@ subroutine ModelAdvance(gcomp, rc) endif ! Handle end of run restart - call NUOPC_CompAttributeGet(gcomp, name="write_restart_at_endofrun", value=cvalue, isPresent=isPresent, isSet=isSet, 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 - - if (isPresent .and. isSet .and. ESMF_AlarmIsRinging(alarm, rc=rc)) then - if (trim(cvalue) .eq. '.true.') force_restart_now = .true. + if (restart_eor) then + call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + if (ESMF_AlarmIsRinging(alarm, rc=rc)) force_restart_now = .true. endif !-------------------------------- From 09ca939f2111206a75211deac51e81843806ae60 Mon Sep 17 00:00:00 2001 From: Daniel Sarmiento <42810219+dpsarmie@users.noreply.github.com> Date: Mon, 6 May 2024 15:15:00 -0400 Subject: [PATCH 4/6] Turn end of run alarm off Turn off stop_alarm check when write at end of run restart is called. --- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 22ce8a105..1e7216fd4 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -1147,6 +1147,8 @@ subroutine ModelAdvance(gcomp, rc) call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return if (ESMF_AlarmIsRinging(alarm, rc=rc)) force_restart_now = .true. + call ESMF_AlarmRingerOff( alarm, rc=rc ) + if (ChkErr(rc,__LINE__,u_FILE_u)) return endif !-------------------------------- From fc376d38752cf938b5d433c6caadde2025032a00 Mon Sep 17 00:00:00 2001 From: dpsarmie Date: Thu, 9 May 2024 18:16:12 +0000 Subject: [PATCH 5/6] Add check for AlarmIsRinging Added a check for AlarmIsRinging call. --- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 1e7216fd4..ba6f1379b 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -1146,9 +1146,12 @@ subroutine ModelAdvance(gcomp, rc) if (restart_eor) then call ESMF_ClockGetAlarm(clock, alarmname='alarm_stop', alarm=alarm, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - if (ESMF_AlarmIsRinging(alarm, rc=rc)) force_restart_now = .true. - call ESMF_AlarmRingerOff( alarm, rc=rc ) - if (ChkErr(rc,__LINE__,u_FILE_u)) return + if (ESMF_AlarmIsRinging(alarm, rc=rc)) then + if (ChkErr(rc,__LINE__,u_FILE_u)) return + force_restart_now = .true. + call ESMF_AlarmRingerOff( alarm, rc=rc ) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + endif endif !-------------------------------- From 9733e45c9219eba27a7632ddc0de5b338cca6b5d Mon Sep 17 00:00:00 2001 From: Daniel Sarmiento <42810219+dpsarmie@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:41:14 -0400 Subject: [PATCH 6/6] Update cice_wrapper_mod.F90 Change precision of variable being logged --- cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90 b/cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90 index d0aafbb43..4668f03b4 100644 --- a/cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90 +++ b/cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90 @@ -72,7 +72,7 @@ subroutine ufs_logfhour(msg,hour) real(dbl_kind), intent(in) :: hour character(len=char_len) :: filename integer(int_kind) :: nunit - write(filename,'(a,i3.3)')'log.ice.f',int(hour) + write(filename,'(a,i4.4)')'log.ice.f',int(hour) open(newunit=nunit,file=trim(filename)) write(nunit,'(a)')'completed: cice' write(nunit,'(a,f10.3)')'forecast hour:',hour