@@ -19,6 +19,7 @@ module shr_is_restart_fh_mod
1919 end type is_restart_fh_type
2020
2121 public :: init_is_restart_fh, is_restart_fh, finalize_restart_fh, is_restart_fh_type
22+ public :: log_restart_fh
2223
2324contains
2425
@@ -81,7 +82,7 @@ subroutine init_is_restart_fh(currentTime, dtime, lLog, restartfh_info)
8182 call ESMF_ConfigDestroy(CF_mc, rc= rc)
8283 if (ESMF_LogFoundError(rcToCheck= rc, msg= ESMF_LOGERR_PASSTHRU, line= __LINE__, file= __FILE__)) return
8384 end if ! model_configure
84-
85+
8586 end subroutine init_is_restart_fh
8687
8788 subroutine is_restart_fh (clock , restartfh_info , lWrite )
@@ -91,7 +92,7 @@ subroutine is_restart_fh(clock, restartfh_info, lWrite)
9192 !
9293 ! !USES:
9394 use ESMF, only : ESMF_ClockGetNextTime
94-
95+
9596 !
9697 ! !ARGUMENTS:
9798 type (ESMF_Clock), intent (in ) :: clock
@@ -114,8 +115,59 @@ subroutine is_restart_fh(clock, restartfh_info, lWrite)
114115 end if
115116
116117 lWrite = restartfh_info% write_restartfh
117-
118+
118119 end subroutine is_restart_fh
120+ ! ===============================================================================
121+ ! > Write a log file
122+ ! !
123+ ! > @details Write a log file for a named component when a restart file is written
124+ ! !
125+ ! ! @param[in] nextTime the ESMF time at the end of a ModelAdvance
126+ ! ! @param[in] startTime the ESMF time at the Model Start
127+ ! ! @param[in] complog the named component
128+ ! ! @param[out] rc return code
129+ ! !
130+ 131+ ! > @date 04-14-2025
132+ subroutine log_restart_fh (nextTime , startTime , complog , rc )
133+
134+ use ESMF, only : ESMF_SUCCESS, ESMF_MAXSTR, ESMF_Time, ESMF_TimeInterval
135+ use ESMF, only : ESMF_TimeGet, ESMF_TimeIntervalGet
136+ use ESMF, only : operator (==), operator (- )
137+
138+ type (ESMF_Time), intent (in ) :: nextTime, startTime
139+ character (len=* ), intent (in ) :: complog
140+ integer , intent (out ) :: rc
141+
142+ ! local variables
143+ type (ESMF_TimeInterval) :: elapsedTime
144+ real (ESMF_KIND_R8 ) :: fhour
145+ character (ESMF_MAXSTR) :: filename
146+ character (ESMF_MAXSTR) :: nexttimestring
147+ integer :: fh_logunit
148+ integer :: yr,mon,day,hour,minute,sec ! time units
149+ character (len=* ), parameter :: subname= ' (log_restart_fh)'
150+ !- ----------------------------------------------------------------------
151+
152+ call ESMF_LogWrite(trim (subname)// " : called" , ESMF_LOGMSG_INFO)
153+ rc = ESMF_SUCCESS
154+
155+ elapsedTime = nextTime - startTime
156+ call ESMF_TimeIntervalGet(elapsedTime, h_r8 = fhour,rc= rc)
157+ if (ESMF_LogFoundError(rcToCheck= rc, msg= ESMF_LOGERR_PASSTHRU, line= __LINE__, file= __FILE__)) return
158+
159+ call ESMF_TimeGet(nexttime, yy= yr, mm= mon, dd= day, h= hour, m= minute, s= sec, rc= rc)
160+ if (ESMF_LogFoundError(rcToCheck= rc, msg= ESMF_LOGERR_PASSTHRU, line= __LINE__, file= __FILE__)) return
161+ write (nexttimestring,' (6i8)' )yr,mon,day,hour,minute,sec
162+
163+ write (filename,' (a,i4.4)' )' log.' // trim (complog)// ' .f' ,int (fhour)
164+ open (newunit= fh_logunit,file= trim (filename))
165+ write (fh_logunit,' (a)' )' completed: ' // trim (complog)
166+ write (fh_logunit,' (a,f10.3)' )' forecast hour:' ,fhour
167+ write (fh_logunit,' (a)' )' valid time: ' // trim (nexttimestring)
168+ close (fh_logunit)
169+
170+ end subroutine log_restart_fh
119171
120172 subroutine finalize_restart_fh (restartfh_info )
121173 !
0 commit comments