From 2c89c1adaeccde98fb4fa124257ee952f5c28b6d Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 26 Mar 2026 17:21:28 +0000 Subject: [PATCH 1/4] Throw an error for non-positive periods under XIOS --- core/src/Xios.cpp | 9 ++++++++- docs/xios.rst | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/Xios.cpp b/core/src/Xios.cpp index 8a7279c0d..c7f72f7d4 100644 --- a/core/src/Xios.cpp +++ b/core/src/Xios.cpp @@ -1331,6 +1331,9 @@ void Xios::createFile(const std::string& fileId) cxios_duration outputFreq; ModelMetadata& metadata = ModelMetadata::getInstance(); if (ioType == INPUT_RESTART || ioType == OUTPUT_RESTART) { + if (metadata.restartPeriod.seconds() <= 0) { + throw std::runtime_error("Xios: Restart period must be positive"); + } outputFreq = convertDurationToXios(metadata.restartPeriod); } else { std::string periodStr; @@ -1341,7 +1344,11 @@ void Xios::createFile(const std::string& fileId) } else { periodStr = Configured::getConfiguration(keyMap.at(DIAGNOSTIC_PERIOD_KEY), std::string()); - cxios_set_file_split_freq(file, convertDurationToXios(Duration(periodStr))); + period = Duration(periodStr); + if (metadata.period.seconds() <= 0) { + throw std::runtime_error("Xios: Diagnostic period must be positive"); + } + cxios_set_file_split_freq(file, convertDurationToXios(period); if (periodStr.empty() || periodStr == "0") { outputFreq = convertDurationToXios(metadata.runLength()); } else { diff --git a/docs/xios.rst b/docs/xios.rst index 61d104c41..8ad6b5773 100644 --- a/docs/xios.rst +++ b/docs/xios.rst @@ -94,6 +94,8 @@ building without XIOS. That is, the ``model`` section should include restart_file = my_restart_file.nc restart_period = P0-0T02:00:00 +Note that the restart period must be positive under XIOS. + Information related to fields to be read from and written to files are configured via the ``XiosInput``, ``XiosOutput``, and ``XiosDiagnostic`` sections, where the first two refer to restarts. Note that all of these sections From c0ccdef5f45b397627859759637ccd32b7d86d3c Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 26 Mar 2026 17:31:31 +0000 Subject: [PATCH 2/4] Fix typo --- core/src/Xios.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Xios.cpp b/core/src/Xios.cpp index c7f72f7d4..ea95ca6b2 100644 --- a/core/src/Xios.cpp +++ b/core/src/Xios.cpp @@ -1344,7 +1344,7 @@ void Xios::createFile(const std::string& fileId) } else { periodStr = Configured::getConfiguration(keyMap.at(DIAGNOSTIC_PERIOD_KEY), std::string()); - period = Duration(periodStr); + Duration period = periodStr; if (metadata.period.seconds() <= 0) { throw std::runtime_error("Xios: Diagnostic period must be positive"); } From 9359a376042821bcca1024448136945f7a2aca43 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 26 Mar 2026 17:46:13 +0000 Subject: [PATCH 3/4] Fix oversights with period handling --- core/src/Xios.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/Xios.cpp b/core/src/Xios.cpp index ea95ca6b2..c8dc155f8 100644 --- a/core/src/Xios.cpp +++ b/core/src/Xios.cpp @@ -1331,10 +1331,13 @@ void Xios::createFile(const std::string& fileId) cxios_duration outputFreq; ModelMetadata& metadata = ModelMetadata::getInstance(); if (ioType == INPUT_RESTART || ioType == OUTPUT_RESTART) { - if (metadata.restartPeriod.seconds() <= 0) { - throw std::runtime_error("Xios: Restart period must be positive"); + if (metadata.restartPeriod.seconds() == 0) { + outputFreq = convertDurationToXios(metadata.runLength()); + } else if (metadata.restartPeriod.seconds() < 0) { + throw std::runtime_error("Xios: Restart period must be non-negative"); + } else { + outputFreq = convertDurationToXios(metadata.restartPeriod); } - outputFreq = convertDurationToXios(metadata.restartPeriod); } else { std::string periodStr; if (ioType == ERA5_FORCING) { @@ -1344,15 +1347,16 @@ void Xios::createFile(const std::string& fileId) } else { periodStr = Configured::getConfiguration(keyMap.at(DIAGNOSTIC_PERIOD_KEY), std::string()); - Duration period = periodStr; - if (metadata.period.seconds() <= 0) { - throw std::runtime_error("Xios: Diagnostic period must be positive"); - } - cxios_set_file_split_freq(file, convertDurationToXios(period); if (periodStr.empty() || periodStr == "0") { outputFreq = convertDurationToXios(metadata.runLength()); } else { - outputFreq = convertDurationToXios(Duration(periodStr)); + Duration period = periodStr; + if (period.seconds() == 0) { + outputFreq = convertDurationToXios(metadata.runLength()); + } else if (period.seconds() < 0) { + throw std::runtime_error("Xios: Diagnostic period must be non-negative"); + } + outputFreq = convertDurationToXios(period); } } } From 16917315d106d5e8bfb6f310aa6f9482d9c91b67 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 26 Mar 2026 17:48:34 +0000 Subject: [PATCH 4/4] Clarify in docs --- docs/xios.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/xios.rst b/docs/xios.rst index 8ad6b5773..d5ec47329 100644 --- a/docs/xios.rst +++ b/docs/xios.rst @@ -94,7 +94,9 @@ building without XIOS. That is, the ``model`` section should include restart_file = my_restart_file.nc restart_period = P0-0T02:00:00 -Note that the restart period must be positive under XIOS. +Note that the restart period must be non-negative under XIOS. If the restart +period is set to zero then this will be interpreted as the full simulation +lenght. That is, restarts will not be written until the very end. Information related to fields to be read from and written to files are configured via the ``XiosInput``, ``XiosOutput``, and ``XiosDiagnostic``