@@ -91,6 +91,10 @@ module MOM_cap_mod
91
91
use NUOPC_Model, only: model_label_Finalize = > label_Finalize
92
92
use NUOPC_Model, only: SetVM
93
93
94
+ #ifndef CESMCOUPLED
95
+ use shr_is_restart_fh_mod, only : init_is_restart_fh, is_restart_fh, is_restart_fh_type
96
+ #endif
97
+
94
98
implicit none ; private
95
99
96
100
public SetServices
@@ -150,13 +154,12 @@ module MOM_cap_mod
150
154
#else
151
155
logical :: cesm_coupled = .false.
152
156
type (ESMF_GeomType_Flag) :: geomtype
157
+ type (is_restart_fh_type) :: restartfh_info ! For flexible restarts in UFS
153
158
#endif
154
159
character (len= 8 ) :: restart_mode = ' alarms'
155
160
character (len= 16 ) :: inst_suffix = ' '
156
161
real (8 ) :: timere
157
162
158
- type (ESMF_Time), allocatable :: restartFhTimes(:)
159
-
160
163
contains
161
164
162
165
! > NUOPC SetService method is the only public entry point.
@@ -625,7 +628,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
625
628
open (newunit= readunit, file= rpointer_filename, form= ' formatted' , status= ' old' , iostat= iostat)
626
629
if (iostat /= 0 ) then
627
630
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg= subname// ' ERROR opening ' // rpointer_filename, &
628
- line= __LINE__, file= u_FILE_u, rcToReturn= rc)
631
+ line= __LINE__, file= u_FILE_u, rcToReturn= rc)
629
632
return
630
633
endif
631
634
do
@@ -1643,11 +1646,9 @@ subroutine ModelAdvance(gcomp, rc)
1643
1646
character (len= :), allocatable :: rpointer_filename
1644
1647
integer :: num_rest_files
1645
1648
real (8 ) :: MPI_Wtime, timers
1646
- logical :: write_restart
1647
- logical :: write_restartfh
1649
+ logical :: write_restart, write_restartfh
1648
1650
logical :: write_restart_eor
1649
1651
1650
-
1651
1652
rc = ESMF_SUCCESS
1652
1653
if (profile_memory) call ESMF_VMLogMemInfo(" Entering MOM Model_ADVANCE: " )
1653
1654
if (write_runtimelog) then
@@ -1797,16 +1798,6 @@ subroutine ModelAdvance(gcomp, rc)
1797
1798
call ESMF_ClockGetAlarm(clock, alarmname= ' restart_alarm' , alarm= restart_alarm, rc= rc)
1798
1799
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1799
1800
1800
- write_restartfh = .false.
1801
- ! check if next time is == to any restartfhtime
1802
- if (allocated (RestartFhTimes)) then
1803
- do n = 1 ,size (RestartFhTimes)
1804
- call ESMF_ClockGetNextTime(clock, MyTime, rc= rc)
1805
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
1806
- if (MyTime == RestartFhTimes(n)) write_restartfh = .true.
1807
- end do
1808
- end if
1809
-
1810
1801
write_restart = .false.
1811
1802
if (ESMF_AlarmIsRinging(restart_alarm, rc= rc)) then
1812
1803
if (ChkErr(rc,__LINE__,u_FILE_u)) return
@@ -1827,7 +1818,12 @@ subroutine ModelAdvance(gcomp, rc)
1827
1818
end if
1828
1819
end if
1829
1820
1830
- if (write_restart .or. write_restartfh .or. write_restart_eor) then
1821
+ #ifndef CESMCOUPLED
1822
+ call is_restart_fh(clock, restartfh_info, write_restartfh)
1823
+ if (write_restartfh) write_restart = .true.
1824
+ #endif
1825
+
1826
+ if (write_restart .or. write_restart_eor) then
1831
1827
! determine restart filename
1832
1828
call ESMF_ClockGetNextTime(clock, MyTime, rc= rc)
1833
1829
if (ChkErr(rc,__LINE__,u_FILE_u)) return
@@ -1850,7 +1846,7 @@ subroutine ModelAdvance(gcomp, rc)
1850
1846
! write restart file(s)
1851
1847
call ocean_model_restart(ocean_state, restartname= restartname, num_rest_files= num_rest_files)
1852
1848
if (localPet == 0 ) then
1853
- ! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1849
+ ! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1854
1850
open (newunit= writeunit, file= rpointer_filename, form= ' formatted' , status= ' unknown' , iostat= iostat)
1855
1851
if (iostat /= 0 ) then
1856
1852
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, &
@@ -1927,34 +1923,26 @@ end subroutine ModelAdvance
1927
1923
1928
1924
1929
1925
subroutine ModelSetRunClock (gcomp , rc )
1930
-
1931
- use ESMF, only : ESMF_TimeIntervalSet
1932
-
1933
1926
type (ESMF_GridComp) :: gcomp
1934
1927
integer , intent (out ) :: rc
1935
1928
1936
1929
! local variables
1937
- type (ESMF_VM) :: vm
1938
1930
type (ESMF_Clock) :: mclock, dclock
1939
1931
type (ESMF_Time) :: mcurrtime, dcurrtime
1940
1932
type (ESMF_Time) :: mstoptime, dstoptime
1941
1933
type (ESMF_TimeInterval) :: mtimestep, dtimestep
1942
- type (ESMF_TimeInterval) :: fhInterval
1943
1934
character (len= 128 ) :: mtimestring, dtimestring
1944
- character (len= 256 ) :: timestr
1945
1935
character (len= 256 ) :: cvalue
1946
1936
character (len= 256 ) :: restart_option ! Restart option units
1947
1937
integer :: restart_n ! Number until restart interval
1948
1938
integer :: restart_ymd ! Restart date (YYYYMMDD)
1949
- integer :: dt_cpl ! coupling timestep
1939
+ integer :: dt_cpl
1950
1940
type (ESMF_Alarm) :: restart_alarm
1951
1941
type (ESMF_Alarm) :: stop_alarm
1952
1942
logical :: isPresent, isSet
1953
1943
logical :: first_time = .true.
1954
- integer :: localPet
1955
- integer :: n, nfh
1956
- integer , allocatable :: restart_fh(:)
1957
- character (len=* ),parameter :: subname= ' (MOM_cap:ModelSetRunClock) '
1944
+ character (len=* ),parameter :: subname= ' MOM_cap:(ModelSetRunClock) '
1945
+ character (len= 256 ) :: timestr
1958
1946
!- -------------------------------
1959
1947
1960
1948
rc = ESMF_SUCCESS
@@ -1970,11 +1958,6 @@ subroutine ModelSetRunClock(gcomp, rc)
1970
1958
call ESMF_ClockGet(mclock, currTime= mcurrtime, timeStep= mtimestep, rc= rc)
1971
1959
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1972
1960
1973
- call ESMF_GridCompGet(gcomp, vm= vm, rc= rc)
1974
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
1975
- call ESMF_VMGet(vm, localPet= localPet, rc= rc)
1976
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
1977
-
1978
1961
!- -------------------------------
1979
1962
! check that the current time in the model and driver are the same
1980
1963
!- -------------------------------
@@ -2073,6 +2056,9 @@ subroutine ModelSetRunClock(gcomp, rc)
2073
2056
call ESMF_LogWrite(subname// " Restarts will be written at finalize only" , ESMF_LOGMSG_INFO)
2074
2057
endif
2075
2058
endif
2059
+ call ESMF_TimeIntervalGet(dtimestep, s= dt_cpl, rc= rc)
2060
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
2061
+ call init_is_restart_fh(mcurrTime, dt_cpl, is_root_pe(), restartfh_info)
2076
2062
endif
2077
2063
2078
2064
if (restart_mode == ' alarms' ) then
@@ -2098,41 +2084,8 @@ subroutine ModelSetRunClock(gcomp, rc)
2098
2084
call ESMF_TimeGet(dstoptime, timestring= timestr, rc= rc)
2099
2085
call ESMF_LogWrite(" Stop Alarm will ring at : " // trim (timestr), ESMF_LOGMSG_INFO)
2100
2086
2101
- ! set up Times to write non-interval restarts
2102
- call NUOPC_CompAttributeGet(gcomp, name= ' restart_fh' , isPresent= isPresent, isSet= isSet, rc= rc)
2103
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
2104
- if (isPresent .and. isSet) then
2105
-
2106
- call ESMF_TimeIntervalGet(dtimestep, s= dt_cpl, rc= rc)
2107
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
2108
- call NUOPC_CompAttributeGet(gcomp, name= ' restart_fh' , value= cvalue, rc= rc)
2109
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
2110
-
2111
- ! convert string to a list of integer restart_fh values
2112
- nfh = 1 + count (transfer (trim (cvalue), ' a' , len (cvalue)) == " ," )
2113
- allocate (restart_fh(1 :nfh))
2114
- allocate (restartFhTimes(1 :nfh))
2115
- read (cvalue,* )restart_fh(1 :nfh)
2116
-
2117
- ! create a list of times at each restart_fh
2118
- do n = 1 ,nfh
2119
- call ESMF_TimeIntervalSet(fhInterval, h= restart_fh(n), rc= rc)
2120
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
2121
- restartFhTimes(n) = mcurrtime + fhInterval
2122
- call ESMF_TimePrint(restartFhTimes(n), options= " string" , preString= " Restart_Fh at " , unit= timestr, rc= rc)
2123
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
2124
- if (localPet == 0 ) then
2125
- if (mod (3600 * restart_fh(n),dt_cpl) /= 0 ) then
2126
- write (stdout,' (A)' )trim (subname)// trim (timestr)// ' will not be written'
2127
- else
2128
- write (stdout,' (A)' )trim (subname)// trim (timestr)// ' will be written'
2129
- end if
2130
- end if
2131
- end do
2132
- deallocate (restart_fh)
2133
- end if
2134
-
2135
2087
first_time = .false.
2088
+
2136
2089
endif
2137
2090
2138
2091
!- -------------------------------
0 commit comments