Skip to content

Commit

Permalink
Allow calendar start to be set, too
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Dec 4, 2024
1 parent 542da5b commit 10e4955
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
11 changes: 7 additions & 4 deletions core/src/Xios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ void enableXios()
*
* @param dt Timestep to use for the model
* @param contextid ID for the XIOS context
* @param starttime Datetime string for the start of the simulation
* @param calendartype Type of calendar to use
*/
Xios::Xios(const std::string dt, const std::string contextid, const std::string calendartype)
Xios::Xios(const std::string dt, const std::string contextid, const std::string starttime,
const std::string calendartype)
{
calendarType = calendartype;
contextId = contextid;
timestep = Duration(dt);
startTime = TimePoint(starttime);
contextId = contextid;
calendarType = calendartype;
configure();
}

Expand Down Expand Up @@ -127,7 +130,7 @@ void Xios::configureServer()

// Set default calendar origin and start
setCalendarOrigin(TimePoint("1970-01-01T00:00:00Z")); // Unix epoch
setCalendarStart(TimePoint("2023-03-17T17:11:00Z")); // TODO: Read from config
setCalendarStart(TimePoint(startTime));
}

/*!
Expand Down
2 changes: 2 additions & 0 deletions core/src/include/Xios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void enableXios();
class Xios : public Configured<Xios> {
public:
Xios(const std::string dt = "P0-0T01:00:00", const std::string contextid = "nextSIM-DG",
const std::string starttime = "1970-01-01T00:00:00Z",
const std::string calendartype = "Gregorian");
~Xios();

Expand Down Expand Up @@ -150,6 +151,7 @@ class Xios : public Configured<Xios> {
std::string calendarType;
std::string contextId;
Duration timestep;
TimePoint startTime;
MPI_Comm clientComm;
MPI_Fint clientComm_F;
MPI_Fint nullComm_F;
Expand Down
3 changes: 2 additions & 1 deletion core/test/XiosCalendar_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ MPI_TEST_CASE("TestXiosInitialization", 2)
TimePoint origin("2020-01-23T00:08:15Z");
xios_handler.setCalendarOrigin(origin);
REQUIRE(origin == xios_handler.getCalendarOrigin());
REQUIRE(origin.format() == "1970-01-01T00:00:00Z");
REQUIRE(origin.format() == "2020-01-23T00:08:15Z");
// Calendar start
REQUIRE(xios_handler.getCalendarStart().format() == "1970-01-01T00:00:00Z"); // Default
TimePoint start("2023-03-17T17:11:00Z");
xios_handler.setCalendarStart(start);
REQUIRE(start == xios_handler.getCalendarStart());
Expand Down
4 changes: 2 additions & 2 deletions core/test/XiosReadWrite_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @file XiosReadWrite_test.cpp
* @author Joe Wallwork <jw2423@cam.ac.uk>
* @date 03 Dec 2024
* @date 04 Dec 2024
* @brief Tests for XIOS write method
* @details
* This test is designed to test the read and write methods of the C++
Expand Down Expand Up @@ -61,7 +61,7 @@ Xios setupXiosHandler(int dim, bool read)
} else {
label = "write";
}
Xios xios_handler("P0-0T01:30:00", formatId(label, dim));
Xios xios_handler("P0-0T01:30:00", formatId(label, dim), "2023-03-17T17:11:00Z");
REQUIRE(xios_handler.isInitialized());
const size_t size = xios_handler.getClientMPISize();
REQUIRE(size == 2);
Expand Down

0 comments on commit 10e4955

Please # to comment.