Skip to content

Commit

Permalink
Copy restart_fh implementation in MOM6 to mediator/med_phases_restart…
Browse files Browse the repository at this point in the history
…_mod.F90

MOM6 version: ufs-community/ufs-weather-model#2099
  • Loading branch information
NickSzapiro-NOAA authored Jul 18, 2024
1 parent 2d837b1 commit 8b2f84f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion mediator/med_phases_restart_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module med_phases_restart_mod
use med_phases_prep_glc_mod , only : FBocnAccum2glc_o, ocnAccum2glc_cnt
use med_phases_prep_rof_mod , only : FBlndAccum2rof_l, lndAccum2rof_cnt
use pio , only : file_desc_t
use ESMF , only : ESMF_Time
implicit none
private

Expand All @@ -23,6 +24,8 @@ module med_phases_restart_mod
private :: med_phases_restart_alarm_init

logical :: write_restart_at_endofrun = .false.
logical :: write_restartfh = .false.
type(ESMF_Time), allocatable :: restartFhTimes(:)
logical :: whead(2) = (/.true. , .false./)
logical :: wdata(2) = (/.false., .true. /)

Expand Down Expand Up @@ -64,6 +67,8 @@ subroutine med_phases_restart_alarm_init(gcomp, rc)
integer :: restart_n ! freq_n setting relative to freq_option
logical :: isPresent
logical :: isSet
integer :: n, nfh
integer, allocatable :: restart_fh(:)
character(len=*), parameter :: subname='(med_phases_restart_alarm_init)'
!---------------------------------------

Expand Down Expand Up @@ -105,6 +110,31 @@ subroutine med_phases_restart_alarm_init(gcomp, rc)
if (trim(cvalue) .eq. '.true.') write_restart_at_endofrun = .true.
end if

! Set up times for non-interval restarts
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
call NUOPC_CompAttributeGet(gcomp, name='restart_fh', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! convert string to a list of integer restart_fh values
nfh = 1 + count(transfer(trim(cvalue), 'a', len(cvalue)) == ",")
allocate(restart_fh(1:nfh))
allocate(restartFhTimes(1:nfh)) !not deallocated
read(cvalue,*)restart_fh(1:nfh)

! create a list of times at each restart_fh
do n = 1,nfh
call ESMF_TimeIntervalSet(fhInterval, h=restart_fh(n), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restartFhTimes(n) = mcurrtime + fhInterval
call ESMF_TimePrint(restartFhTimes(n), options="string", preString="Restart_Fh at ", unit=timestr, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end do
deallocate(restart_fh)
end if

! Write mediator diagnostic output
if (maintask) then
write(logunit,*)
Expand Down Expand Up @@ -244,7 +274,17 @@ subroutine med_phases_restart_write(gcomp, rc)
endif
endif

if (alarmIsOn) then
if (allocated(RestartFhTimes)) then
write_restartfh = .false.
! check if next time is == to any restartfhtime
do n = 1,size(RestartFhTimes)
call ESMF_ClockGetNextTime(clock, nextTime=nexttime, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (nextTime == RestartFhTimes(n)) write_restartfh = .true.
end do
end if

if (alarmIsOn .or. write_restartfh) then
call ESMF_ClockGet(clock, currtime=currtime, starttime=starttime, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_ClockGetNextTime(clock, nextTime=nexttime, rc=rc)
Expand Down

0 comments on commit 8b2f84f

Please sign in to comment.