@@ -153,6 +153,8 @@ module MOM_cap_mod
153
153
character (len= 16 ) :: inst_suffix = ' '
154
154
real (8 ) :: timere
155
155
156
+ type (ESMF_Time), allocatable :: restartFhTimes(:)
157
+
156
158
contains
157
159
158
160
! > NUOPC SetService method is the only public entry point.
@@ -378,6 +380,7 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
378
380
geomtype = ESMF_GEOMTYPE_GRID
379
381
endif
380
382
383
+
381
384
end subroutine
382
385
383
386
! > Called by NUOPC to advertise import and export fields. "Advertise"
@@ -613,7 +616,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
613
616
open (newunit= readunit, file= rpointer_filename, form= ' formatted' , status= ' old' , iostat= iostat)
614
617
if (iostat /= 0 ) then
615
618
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg= subname// ' ERROR opening ' // rpointer_filename, &
616
- line= __LINE__, file= u_FILE_u, rcToReturn= rc)
619
+ line= __LINE__, file= u_FILE_u, rcToReturn= rc)
617
620
return
618
621
endif
619
622
do
@@ -1534,6 +1537,8 @@ subroutine ModelAdvance(gcomp, rc)
1534
1537
character (len= :), allocatable :: rpointer_filename
1535
1538
integer :: num_rest_files
1536
1539
real (8 ) :: MPI_Wtime, timers
1540
+ logical :: write_restart
1541
+ logical :: write_restartfh
1537
1542
1538
1543
rc = ESMF_SUCCESS
1539
1544
if (profile_memory) call ESMF_VMLogMemInfo(" Entering MOM Model_ADVANCE: " )
@@ -1685,13 +1690,26 @@ subroutine ModelAdvance(gcomp, rc)
1685
1690
call ESMF_ClockGetAlarm(clock, alarmname= ' restart_alarm' , alarm= restart_alarm, rc= rc)
1686
1691
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1687
1692
1693
+ write_restartfh = .false.
1694
+ ! check if next time is == to any restartfhtime
1695
+ if (allocated (RestartFhTimes)) then
1696
+ do n = 1 ,size (RestartFhTimes)
1697
+ call ESMF_ClockGetNextTime(clock, MyTime, rc= rc)
1698
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1699
+ if (MyTime == RestartFhTimes(n)) write_restartfh = .true.
1700
+ end do
1701
+ end if
1702
+
1703
+ write_restart = .false.
1688
1704
if (ESMF_AlarmIsRinging(restart_alarm, rc= rc)) then
1689
1705
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1690
-
1706
+ write_restart = .true.
1691
1707
! turn off the alarm
1692
1708
call ESMF_AlarmRingerOff(restart_alarm, rc= rc )
1693
1709
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1710
+ end if
1694
1711
1712
+ if (write_restart .or. write_restartfh) then
1695
1713
! determine restart filename
1696
1714
call ESMF_ClockGetNextTime(clock, MyTime, rc= rc)
1697
1715
if (ChkErr(rc,__LINE__,u_FILE_u)) return
@@ -1714,7 +1732,7 @@ subroutine ModelAdvance(gcomp, rc)
1714
1732
! write restart file(s)
1715
1733
call ocean_model_restart(ocean_state, restartname= restartname, num_rest_files= num_rest_files)
1716
1734
if (localPet == 0 ) then
1717
- ! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1735
+ ! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1718
1736
open (newunit= writeunit, file= rpointer_filename, form= ' formatted' , status= ' unknown' , iostat= iostat)
1719
1737
if (iostat /= 0 ) then
1720
1738
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, &
@@ -1791,25 +1809,34 @@ end subroutine ModelAdvance
1791
1809
1792
1810
1793
1811
subroutine ModelSetRunClock (gcomp , rc )
1812
+
1813
+ use ESMF, only : ESMF_TimeIntervalSet
1814
+
1794
1815
type (ESMF_GridComp) :: gcomp
1795
1816
integer , intent (out ) :: rc
1796
1817
1797
1818
! local variables
1819
+ type (ESMF_VM) :: vm
1798
1820
type (ESMF_Clock) :: mclock, dclock
1799
1821
type (ESMF_Time) :: mcurrtime, dcurrtime
1800
1822
type (ESMF_Time) :: mstoptime, dstoptime
1801
1823
type (ESMF_TimeInterval) :: mtimestep, dtimestep
1824
+ type (ESMF_TimeInterval) :: fhInterval
1802
1825
character (len= 128 ) :: mtimestring, dtimestring
1826
+ character (len= 256 ) :: timestr
1803
1827
character (len= 256 ) :: cvalue
1804
1828
character (len= 256 ) :: restart_option ! Restart option units
1805
1829
integer :: restart_n ! Number until restart interval
1806
1830
integer :: restart_ymd ! Restart date (YYYYMMDD)
1831
+ integer :: dt_cpl ! coupling timestep
1807
1832
type (ESMF_Alarm) :: restart_alarm
1808
1833
type (ESMF_Alarm) :: stop_alarm
1809
1834
logical :: isPresent, isSet
1810
1835
logical :: first_time = .true.
1811
- character (len=* ),parameter :: subname= ' MOM_cap:(ModelSetRunClock) '
1812
- character (len= 256 ) :: timestr
1836
+ integer :: localPet
1837
+ integer :: n, nfh
1838
+ integer , allocatable :: restart_fh(:)
1839
+ character (len=* ),parameter :: subname= ' (MOM_cap:ModelSetRunClock) '
1813
1840
!- -------------------------------
1814
1841
1815
1842
rc = ESMF_SUCCESS
@@ -1825,6 +1852,11 @@ subroutine ModelSetRunClock(gcomp, rc)
1825
1852
call ESMF_ClockGet(mclock, currTime= mcurrtime, timeStep= mtimestep, rc= rc)
1826
1853
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1827
1854
1855
+ call ESMF_GridCompGet(gcomp, vm= vm, rc= rc)
1856
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1857
+ call ESMF_VMGet(vm, localPet= localPet, rc= rc)
1858
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1859
+
1828
1860
!- -------------------------------
1829
1861
! check that the current time in the model and driver are the same
1830
1862
!- -------------------------------
@@ -1948,8 +1980,41 @@ subroutine ModelSetRunClock(gcomp, rc)
1948
1980
call ESMF_TimeGet(dstoptime, timestring= timestr, rc= rc)
1949
1981
call ESMF_LogWrite(" Stop Alarm will ring at : " // trim (timestr), ESMF_LOGMSG_INFO)
1950
1982
1951
- first_time = .false.
1983
+ ! set up Times to write non-interval restarts
1984
+ call NUOPC_CompAttributeGet(gcomp, name= ' restart_fh' , isPresent= isPresent, isSet= isSet, rc= rc)
1985
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1986
+ if (isPresent .and. isSet) then
1952
1987
1988
+ call ESMF_TimeIntervalGet(dtimestep, s= dt_cpl, rc= rc)
1989
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1990
+ call NUOPC_CompAttributeGet(gcomp, name= ' restart_fh' , value= cvalue, rc= rc)
1991
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
1992
+
1993
+ ! convert string to a list of integer restart_fh values
1994
+ nfh = 1 + count (transfer (trim (cvalue), ' a' , len (cvalue)) == " ," )
1995
+ allocate (restart_fh(1 :nfh))
1996
+ allocate (restartFhTimes(1 :nfh))
1997
+ read (cvalue,* )restart_fh(1 :nfh)
1998
+
1999
+ ! create a list of times at each restart_fh
2000
+ do n = 1 ,nfh
2001
+ call ESMF_TimeIntervalSet(fhInterval, h= restart_fh(n), rc= rc)
2002
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
2003
+ restartFhTimes(n) = mcurrtime + fhInterval
2004
+ call ESMF_TimePrint(restartFhTimes(n), options= " string" , preString= " Restart_Fh at " , unit= timestr, rc= rc)
2005
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
2006
+ if (localPet == 0 ) then
2007
+ if (mod (3600 * restart_fh(n),dt_cpl) /= 0 ) then
2008
+ write (stdout,' (A)' )trim (subname)// trim (timestr)// ' will not be written'
2009
+ else
2010
+ write (stdout,' (A)' )trim (subname)// trim (timestr)// ' will be written'
2011
+ end if
2012
+ end if
2013
+ end do
2014
+ deallocate (restart_fh)
2015
+ end if
2016
+
2017
+ first_time = .false.
1953
2018
endif
1954
2019
1955
2020
!- -------------------------------
0 commit comments