Skip to content

Commit c3e4af4

Browse files
committed
Check start and step meet assumptions
1 parent ac44e60 commit c3e4af4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

core/src/ModelMetadata.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,25 @@ ModelState& ModelMetadata::affixCoordinates(ModelState& state) const
299299
return state;
300300
}
301301

302+
// Helper function for checking that the model start and timestep align with midnight and the hour.
303+
void checkStartStep(const std::string start_str, double step)
304+
{
305+
if (start_str != "T00:00:00Z") {
306+
throw std::runtime_error("ModelMetadata::setTimes: model.start must be at midnight.");
307+
}
308+
if (step < 3600) {
309+
if (std::fmod(3600, step) != 0.) {
310+
throw std::runtime_error(
311+
"ModelMetadata::setTimes: model.time_step must be aligned with the hour.");
312+
}
313+
}
314+
}
315+
302316
void ModelMetadata::setTimes(const TimePoint& start, const TimePoint& stop, const Duration& step)
303317
{
318+
#ifdef USE_XIOS
319+
checkStartStep(start.format(TimePoint::hmsFormat), step.seconds());
320+
#endif
304321
this->start = start;
305322
this->stop = stop;
306323
this->step = step;
@@ -310,6 +327,9 @@ void ModelMetadata::setTimes(const TimePoint& start, const TimePoint& stop, cons
310327

311328
void ModelMetadata::setTimes(const TimePoint& start, const Duration& runLen, const Duration& step)
312329
{
330+
#ifdef USE_XIOS
331+
checkStartStep(start.format(TimePoint::hmsFormat), step.seconds());
332+
#endif
313333
this->start = start;
314334
this->stop = start + runLen;
315335
this->step = step;

0 commit comments

Comments
 (0)