Skip to content

Commit a4da9b3

Browse files
committed
Merge in repeat clock capability.
Merge branch 'repeating_clock' into develop
2 parents 1e77226 + cc80483 commit a4da9b3

File tree

8 files changed

+1193
-36
lines changed

8 files changed

+1193
-36
lines changed

src/Infrastructure/TimeMgr/include/ESMCI_Clock.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ namespace ESMCI{
9595
Time currTime; // current time
9696
Time prevTime; // previous time
9797

98+
99+
bool repeat; // If true, this is a repeating clock
100+
TimeInterval repeatDuration; // Duration to repeat over if it's a repeating clock
101+
ESMC_I8 repeatCount; // the number of times the clock has repeated
102+
103+
98104
ESMC_I8 advanceCount; // number of times
99105
// ESMCI_ClockAdvance has
100106
// been called (number of
@@ -163,7 +169,10 @@ namespace ESMCI{
163169
int *timeZone=0,
164170
ESMC_I8 *advanceCount=0,
165171
int *alarmCount=0,
166-
ESMC_Direction *direction=0);
172+
ESMC_Direction *direction=0,
173+
TimeInterval *repeatDuration=0,
174+
ESMC_I8 *repeatCount=0
175+
);
167176

168177
int advance(TimeInterval *timeStep=0,
169178
char *ringingAlarmList1stElementPtr=0,
@@ -229,7 +238,7 @@ namespace ESMCI{
229238
// friend function to allocate and initialize clock from heap
230239
friend Clock *ESMCI_ClockCreate(int, const char*, TimeInterval*,
231240
Time*, Time*, TimeInterval*,
232-
int*, Time*, int*);
241+
int*, Time*, TimeInterval*, int*);
233242
// TODO: add overload for ESMC_R8 *runTimeStepCount
234243

235244
// friend function to copy a clock
@@ -284,6 +293,7 @@ namespace ESMCI{
284293
int *runTimeStepCount=0,
285294
// TODO: add overload for ESMC_R8 *runTimeStepCount=0,
286295
Time* refTime=0,
296+
TimeInterval *repeatDuration=0,
287297
int* rc=0);
288298

289299
// friend function to copy a clock

src/Infrastructure/TimeMgr/interface/ESMCI_Clock_F.C

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern "C" {
4747
TimeInterval *runDuration,
4848
int *runTimeStepCount,
4949
Time *refTime,
50+
TimeInterval *repeatDuration,
5051
int *status,
5152
ESMCI_FortranStrLenArg name_l) {
5253
*ptr = ESMCI_ClockCreate(
@@ -59,6 +60,7 @@ extern "C" {
5960
ESMC_NOT_PRESENT_FILTER(runDuration),
6061
ESMC_NOT_PRESENT_FILTER(runTimeStepCount),
6162
ESMC_NOT_PRESENT_FILTER(refTime),
63+
ESMC_NOT_PRESENT_FILTER(repeatDuration),
6264
ESMC_NOT_PRESENT_FILTER(status) );
6365
}
6466

@@ -126,6 +128,8 @@ extern "C" {
126128
ESMC_I8 *advanceCount,
127129
int *alarmCount,
128130
ESMC_Direction *direction,
131+
TimeInterval *repeatDuration,
132+
ESMC_I8 *repeatCount,
129133
int *status,
130134
ESMCI_FortranStrLenArg tempName_l) {
131135
ESMF_CHECK_POINTER(*ptr, status)
@@ -149,7 +153,10 @@ extern "C" {
149153
ESMC_NOT_PRESENT_FILTER(timeZone),
150154
ESMC_NOT_PRESENT_FILTER(advanceCount),
151155
ESMC_NOT_PRESENT_FILTER(alarmCount),
152-
ESMC_NOT_PRESENT_FILTER(direction) );
156+
ESMC_NOT_PRESENT_FILTER(direction),
157+
ESMC_NOT_PRESENT_FILTER(repeatDuration),
158+
ESMC_NOT_PRESENT_FILTER(repeatCount)
159+
);
153160
if (ESMC_PRESENT(status)) *status = rc;
154161
}
155162

src/Infrastructure/TimeMgr/interface/ESMC_Clock.C

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ESMC_Clock ESMC_ClockCreate(
7373
(ESMCI::Time *)&startTime,
7474
(ESMCI::Time *)&stopTime,
7575
(ESMCI::TimeInterval *)NULL, (int *)NULL,
76-
(ESMCI::Time *)NULL, &localrc);
76+
(ESMCI::Time *)NULL, (ESMCI::TimeInterval *)NULL, &localrc);
7777
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT, rc)) {
7878
clock.ptr = NULL; // defensive; should already be set in ClockCreate()
7979
return clock; // bail out
@@ -156,9 +156,12 @@ int ESMC_ClockGet(ESMC_Clock clock, ESMC_TimeInterval *currSimTime,
156156
(ESMCI::Calendar **)NULL,
157157
(ESMC_CalKind_Flag *)NULL,
158158
(int *)NULL,
159-
advanceCount,
159+
advanceCount,
160160
(int *)NULL,
161-
(ESMC_Direction *)NULL);
161+
(ESMC_Direction *)NULL,
162+
(ESMCI::TimeInterval *)NULL,
163+
(ESMC_I8 *)NULL
164+
);
162165
if (ESMC_LogDefault.MsgFoundError(localrc, ESMCI_ERR_PASSTHRU, ESMC_CONTEXT,
163166
&rc)) return rc; // bail out
164167
// return successfully

src/Infrastructure/TimeMgr/interface/ESMF_Clock.F90

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ end subroutine ESMF_ClockAdvance
426426
! !INTERFACE:
427427
! Private name; call using ESMF_ClockCreate()
428428
function ESMF_ClockCreateNew(timeStep, startTime, keywordEnforcer, &
429-
stopTime, runDuration, runTimeStepCount, refTime, name, rc)
429+
stopTime, runDuration, runTimeStepCount, refTime, repeatDuration, name, rc)
430430

431431
! !RETURN VALUE:
432432
type(ESMF_Clock) :: ESMF_ClockCreateNew
@@ -439,6 +439,7 @@ function ESMF_ClockCreateNew(timeStep, startTime, keywordEnforcer, &
439439
type(ESMF_TimeInterval), intent(in), optional :: runDuration
440440
integer, intent(in), optional :: runTimeStepCount
441441
type(ESMF_Time), intent(in), optional :: refTime
442+
type(ESMF_TimeInterval), intent(in), optional :: repeatDuration
442443
character (len=*), intent(in), optional :: name
443444
integer, intent(out), optional :: rc
444445

@@ -482,6 +483,9 @@ function ESMF_ClockCreateNew(timeStep, startTime, keywordEnforcer, &
482483
! \item[{[refTime]}]
483484
! The {\tt ESMF\_Clock}'s reference time. Provides reference point
484485
! for simulation time (see currSimTime in ESMF\_ClockGet() below).
486+
! \item[{[repeatDuration]}]
487+
! If specified and not 0, then makes {\tt ESMF\_Clock} a repeating clock that runs for
488+
! {\tt repeatDuration} and then resets back to {\tt statTime}.
485489
! \item[{[name]}]
486490
! The name for the newly created clock. If not specified, a
487491
! default unique name will be generated: "ClockNNN" where NNN
@@ -518,7 +522,7 @@ function ESMF_ClockCreateNew(timeStep, startTime, keywordEnforcer, &
518522
! invoke C to C++ entry point to allocate and initialize new clock
519523
call c_ESMC_ClockCreateNew(ESMF_ClockCreateNew, nameLen, name, &
520524
timeStep, startTime, stopTime, runDuration, &
521-
runTimeStepCount, refTime, localrc)
525+
runTimeStepCount, refTime, repeatDuration, localrc)
522526
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
523527
ESMF_CONTEXT, rcToReturn=rc)) return
524528

@@ -680,7 +684,8 @@ subroutine ESMF_ClockGet(clock, keywordEnforcer, &
680684
timeStep, startTime, stopTime, &
681685
runDuration, runTimeStepCount, refTime, currTime, prevTime, &
682686
currSimTime, prevSimTime, calendar, calkindflag, timeZone, &
683-
advanceCount, alarmCount, direction, name, rc)
687+
advanceCount, alarmCount, direction, repeatDuration, repeatCount, &
688+
name, rc)
684689

685690
! !ARGUMENTS:
686691
type(ESMF_Clock), intent(in) :: clock
@@ -701,6 +706,8 @@ subroutine ESMF_ClockGet(clock, keywordEnforcer, &
701706
integer(ESMF_KIND_I8), intent(out), optional :: advanceCount
702707
integer, intent(out), optional :: alarmCount
703708
type(ESMF_Direction_Flag), intent(out), optional :: direction
709+
type(ESMF_TimeInterval), intent(out), optional :: repeatDuration
710+
integer(ESMF_KIND_I8), intent(out), optional :: repeatCount
704711
character (len=*), intent(out), optional :: name
705712
integer, intent(out), optional :: rc
706713

@@ -762,6 +769,10 @@ subroutine ESMF_ClockGet(clock, keywordEnforcer, &
762769
! The {\tt ESMF\_Clock}'s time stepping direction. See also
763770
! {\tt ESMF\_ClockIsReverse()}, an alternative for convenient use in
764771
! "if" and "do while" constructs.
772+
! \item[{[repeatDuration]}]
773+
! If not 0, then how long the clock should run before going back to startTime.
774+
! \item[{[repeatCount]}]
775+
! The number of times this clock has gone back to startTime when repeating.
765776
! \item[{[name]}]
766777
! The name of this clock.
767778
! \item[{[rc]}]
@@ -800,7 +811,8 @@ subroutine ESMF_ClockGet(clock, keywordEnforcer, &
800811
runDuration, runTimeStepCount, refTime, &
801812
currTime, prevTime, currSimTime, prevSimTime, &
802813
calendar, calkindflag, timeZone, advanceCount, &
803-
alarmCount, direction, localrc)
814+
alarmCount, direction, repeatDuration, repeatCount, &
815+
localrc)
804816
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
805817
ESMF_CONTEXT, rcToReturn=rc)) return
806818

@@ -821,7 +833,8 @@ subroutine ESMF_ClockGet(clock, keywordEnforcer, &
821833
call ESMF_TimeIntervalInit(currSimTime)
822834
call ESMF_TimeIntervalInit(prevSimTime)
823835
call ESMF_CalendarSetInitCreated(calendar)
824-
836+
call ESMF_TimeIntervalInit(repeatDuration)
837+
825838
! Return success
826839
if (present(rc)) rc = ESMF_SUCCESS
827840
end subroutine ESMF_ClockGet

0 commit comments

Comments
 (0)