@@ -70,6 +70,9 @@ module rof_comp_nuopc
7070 integer :: nthrds
7171 integer , parameter :: debug = 1
7272 character (* ), parameter :: modName = " (rof_comp_nuopc)"
73+
74+ logical :: write_restart_at_endofrun = .false.
75+
7376 character (* ), parameter :: u_FILE_u = &
7477 __FILE__
7578
@@ -420,6 +423,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
420423 integer :: localPet
421424 integer :: localPeCount
422425 integer :: rofid ! component id for pio
426+ logical :: isPresent ! If attribute is present
427+ logical :: isSet ! If attribute is present and also set
423428 character (len=* ), parameter :: subname= trim (modName)// ' :(InitializeRealize) '
424429 !- --------------------------------------------------------------------------
425430
@@ -487,7 +492,15 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
487492 ! - need to compute areas where they are not defined in input file
488493 call ESMF_ClockGet(clock, currTime= currtime, rc= rc)
489494 if (ChkErr(rc,__LINE__,u_FILE_u)) return
490-
495+
496+ call NUOPC_CompAttributeGet(gcomp, name= " write_restart_at_endofrun" , value= cvalue, isPresent= isPresent, isSet= isSet, rc= rc)
497+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
498+ if (isPresent .and. isSet) then
499+ if (trim (cvalue) .eq. ' .true.' ) write_restart_at_endofrun = .true.
500+ else
501+ call shr_sys_abort( subname// ' ERROR:: write_restart_at_endofrun not isPresent or not isSet' )
502+ end if
503+
491504 call mosart_init1(currtime, rc)
492505 if (ChkErr(rc,__LINE__,u_FILE_u)) return
493506
@@ -635,35 +648,38 @@ subroutine ModelAdvance(gcomp, rc)
635648 if (ChkErr(rc,__LINE__,u_FILE_u)) return
636649
637650 !- -------------------------------
638- ! Determine if time to write restart
651+ ! Determine if time to stop
639652 !- -------------------------------
640653
641- call ESMF_ClockGetAlarm(clock, alarmname= ' alarm_restart ' , alarm= alarm, rc= rc)
654+ call ESMF_ClockGetAlarm(clock, alarmname= ' alarm_stop ' , alarm= alarm, rc= rc)
642655 if (ChkErr(rc,__LINE__,u_FILE_u)) return
643656
644657 if (ESMF_AlarmIsRinging(alarm, rc= rc)) then
645658 if (ChkErr(rc,__LINE__,u_FILE_u)) return
646- rstwr = .true.
659+ nlend = .true.
647660 call ESMF_AlarmRingerOff( alarm, rc= rc )
648661 if (ChkErr(rc,__LINE__,u_FILE_u)) return
649662 else
650- rstwr = .false.
663+ nlend = .false.
651664 endif
652665
653666 !- -------------------------------
654- ! Determine if time to stop
667+ ! Determine if time to write restart
655668 !- -------------------------------
656669
657- call ESMF_ClockGetAlarm(clock, alarmname= ' alarm_stop' , alarm= alarm, rc= rc)
658- if (ChkErr(rc,__LINE__,u_FILE_u)) return
659-
660- if (ESMF_AlarmIsRinging(alarm, rc= rc)) then
661- if (ChkErr(rc,__LINE__,u_FILE_u)) return
662- nlend = .true.
663- call ESMF_AlarmRingerOff( alarm, rc= rc )
664- if (ChkErr(rc,__LINE__,u_FILE_u)) return
670+ rstwr = .false.
671+ if (nlend .and. write_restart_at_endofrun) then
672+ rstwr = .true.
665673 else
666- nlend = .false.
674+ call ESMF_ClockGetAlarm(clock, alarmname= ' alarm_restart' , alarm= alarm, rc= rc)
675+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
676+
677+ if (ESMF_AlarmIsRinging(alarm, rc= rc)) then
678+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
679+ rstwr = .true.
680+ call ESMF_AlarmRingerOff( alarm, rc= rc )
681+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
682+ endif
667683 endif
668684
669685 !- -------------------------------
0 commit comments