Skip to content

Commit 28c48f6

Browse files
authored
Add repeatCount to cap restart file
* Add repeatCount. * Add repeatCount to cap_restart.yaml * Add repeatCount. * Add repeatCount to cap_restart.yaml * Update to include repeatCount in make_clock * Update CHANGELOG.md * Make sure has_repeatCount has a value.
1 parent b01ce84 commit 28c48f6

6 files changed

Lines changed: 32 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8989
- Add tests of update_payload and update_from_payload for VerticalGridAspect
9090
- Add `use_field_dictionary` column to ACG3 with new unit tests.
9191
- Update cap restart file with current time at end of run.
92+
- Read/write repeatCount from/to cap restart file at beginning/end of run.
93+
9294

9395
### Changed
9496

gridcomps/cap3g/Cap.F90

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module mapl3g_Cap
1919
character(len=*), parameter :: KEY_RESTART = 'restart'
2020
character(len=*), parameter :: KEY_CLOCK = 'clock'
2121
character(len=*), parameter :: KEY_CURRTIME = 'currTime'
22+
character(len=*), parameter :: KEY_REPEATCOUNT = 'repeatCount'
2223

2324
type CheckpointOptions
2425
logical :: is_enabled = .false.
@@ -59,7 +60,7 @@ subroutine mapl_run_driver(hconfig, is_model_pet, unusable, servers, rc)
5960
call mapl_DriverInitializePhases(driver, phases=GENERIC_INIT_PHASE_SEQUENCE, _RC)
6061
call integrate(driver, hconfig, options%checkpointing, options%lgr, _RC)
6162
call driver%finalize(_RC)
62-
call update_restart_currTime(hconfig, clock, _RC)
63+
call update_restart(hconfig, clock, _RC)
6364

6465
_RETURN(_SUCCESS)
6566
_UNUSED_DUMMY(unusable)
@@ -341,15 +342,21 @@ function make_clock(hconfig, lgr, rc) result(clock)
341342
type(ESMF_Time) :: end_of_segment
342343
type(ESMF_TimeInterval) :: timeStep, segment_duration
343344
type(ESMF_TimeInterval), allocatable :: repeatDuration
344-
logical :: has_repeatDuration
345+
logical :: has_repeatDuration, has_repeatCount
345346
character(:), allocatable :: cap_restart_file
346347
character(ESMF_MAXSTR) :: iso_time
348+
integer(kind=ESMF_KIND_I8) :: repeatCount
347349

350+
repeatCount = 0
348351
cap_restart_file = esmf_HConfigAsString(hconfig, keyString=KEY_RESTART, _RC)
349352
restart_cfg = esmf_HConfigCreate(filename=cap_restart_file, _RC)
350353
currTime = mapl_HConfigAsTime(restart_cfg, keyString='currTime', _RC)
351354
iso_time = esmf_HConfigAsString(restart_cfg, keystring='currTime', _RC)
352355
call lgr%info('current time: %a', trim(iso_time))
356+
has_repeatCount = ESMF_HConfigIsDefined(restart_cfg, keyString=KEY_REPEATCOUNT, _RC)
357+
if(has_repeatCount) then
358+
repeatCount = ESMF_HConfigAsI8(restart_cfg, keyString=KEY_REPEATCOUNT, _RC)
359+
end if
353360
call esmf_HConfigDestroy(restart_cfg, _RC)
354361

355362
clock_cfg = esmf_HConfigCreateAt(hconfig, keystring=KEY_CLOCK, _RC)
@@ -381,6 +388,8 @@ function make_clock(hconfig, lgr, rc) result(clock)
381388
call lgr%info('repeat duration: %a', trim(iso_time))
382389
end if
383390

391+
! Currently, repeatCount is not an argument for ESMF_ClockCreate or ESMF_ClockSet.
392+
! Once it is added, it should be included in the create/set below.
384393
clock = esmf_ClockCreate(timeStep=timeStep, &
385394
startTime=startTime, stopTime=end_of_segment, &
386395
refTime=startTime, &
@@ -598,32 +607,31 @@ subroutine make_symlink(checkpointing_path, target_name, rc)
598607
_RETURN(_SUCCESS)
599608
end subroutine make_symlink
600609

601-
subroutine update_restart_currTime(hconfig, clock, rc)
610+
subroutine update_restart(hconfig, clock, rc)
602611
type(ESMF_HConfig), intent(in) :: hconfig
603612
type(ESMF_Clock), intent(inout) :: clock
604613
integer, optional, intent(out) :: rc
605614
integer :: status
606-
character(len=:), allocatable :: currTimeString
607615
type(ESMF_Time) :: currTime
616+
integer(kind=ESMF_KIND_I8) :: repeatCount
608617
logical :: restart_is_defined
609618
character(:), allocatable :: cap_restart_file
610619
type(ESMF_HConfig) :: restart_cfg
611-
integer, parameter :: ISOSTRING_LENGTH=20
620+
integer, parameter :: ISOSTRING_LENGTH = 20
612621
character(len=ISOSTRING_LENGTH) :: timeString
613622

614-
615-
call ESMF_ClockGet(clock, currTime=currTime, _RC)
623+
call ESMF_ClockGet(clock, currTime=currTime, repeatCount=repeatCount, _RC)
616624
call ESMF_TimeGet(currTime, timeString=timeString, _RC)
617-
currTimeString = trim(timeString)
618625
restart_is_defined = ESMF_HConfigIsDefined(hconfig, keyString=KEY_RESTART, _RC)
619626
_ASSERT(restart_is_defined, 'Unable to get restart filename')
620627
cap_restart_file = ESMF_HConfigAsString(hconfig, keyString=KEY_RESTART, _RC)
621-
restart_cfg = ESMF_HConfigCreate(filename=cap_restart_file, _RC)
622-
call ESMF_HConfigSet(restart_cfg, content=timeString, keyString=KEY_CURRTIME, _RC)
628+
restart_cfg = ESMF_HConfigCreate(_RC)
629+
call ESMF_HConfigAdd(restart_cfg, content=timeString, addKeyString=KEY_CURRTIME, _RC)
630+
call ESMF_HConfigAdd(restart_cfg, content=repeatCount, addKeyString=KEY_REPEATCOUNT, _RC)
623631
call ESMF_HConfigFileSave(restart_cfg, cap_restart_file, _RC)
624632
call ESMF_HConfigDestroy(restart_cfg, _RC)
625633
_RETURN(_SUCCESS)
626634

627-
end subroutine update_restart_currTime
635+
end subroutine update_restart
628636

629637
end module mapl3g_Cap

gridcomps/cap3g/tests/cap_restart_tests/cap.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ cap:
66
dt: PT1H
77
start: 2001-01-01T00:00:00
88
stop: 2999-03-02T21:00:00
9-
segment_duration: PT10H
9+
segment_duration: PT8H
10+
repeat_duration: PT12H
1011

1112
checkpointing:
1213
enabled: true
@@ -38,10 +39,3 @@ esmf:
3839

3940
mapl:
4041
model_petcount: 1
41-
# pflogger_cfg_file: pflogger.yaml
42-
#
43-
# servers:
44-
# pfio:
45-
# nodes: 1
46-
# mit:
47-
# nodes: 0
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
currTime: 2001-01-01T10:00:00
1+
currTime: 2001-01-01T08:00:00
2+
repeatCount: 0

gridcomps/cap3g/tests/cap_restart_tests/history.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ geoms:
77
dateline: DC
88

99
active_collections:
10-
- coll1
11-
- coll2
1210

1311
time_specs:
1412
three_hour: &three_hour

gridcomps/cap3g/tests/run_captest.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ macro(run_case CASE)
1010
RESULT_VARIABLE CMD_RESULT
1111
WORKING_DIRECTORY ${tempdir}
1212
)
13-
execute_process(
14-
COMMAND ${CMAKE_COMMAND} -E cat ${tempdir}/PET0.ESMF_LogFile
15-
)
13+
if(EXISTS ${tempdir}/PET0.ESMF_LogFile)
14+
execute_process(
15+
COMMAND ${CMAKE_COMMAND} -E cat ${tempdir}/PET0.ESMF_LogFile
16+
)
17+
endif()
1618
if(NOT CMD_RESULT AND "${CASE}" STREQUAL "cap_restart_tests")
1719
set(EXPECTED "cap_restart_expected.yaml")
1820
set(ACTUAL "cap_restart.yaml")
@@ -26,7 +28,8 @@ macro(run_case CASE)
2628
COMMAND ${CMAKE_COMMAND} -E rm -rf ${tempdir}
2729
)
2830
if(CMD_RESULT)
29-
message(FATAL_ERROR "Error running ${CASE}")
31+
set(MSG "Error running ${CASE}")
32+
message(FATAL_ERROR "${MSG}")
3033
endif()
3134
endmacro()
3235
run_case(${TEST_CASE})

0 commit comments

Comments
 (0)