Skip to content

Commit

Permalink
Throw error if calendar attributes unset
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Dec 9, 2024
1 parent d5b28d0 commit cd35f66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion core/src/Xios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Xios.cpp
* @author Tom Meltzer <tdm39@cam.ac.uk>
* @author Joe Wallwork <jw2423@cam.ac.uk>
* @date 04 Dec 2024
* @date 09 Dec 2024
* @brief XIOS interface implementation
* @details
*
Expand Down Expand Up @@ -290,6 +290,9 @@ std::string Xios::getCalendarType()
*/
TimePoint Xios::getCalendarOrigin()
{
if (!cxios_is_defined_calendar_wrapper_time_origin(clientCalendar)) {
throw std::runtime_error("Xios: Calendar origin has not been set");
}
cxios_date calendar_origin;
cxios_get_calendar_wrapper_date_time_origin(clientCalendar, &calendar_origin);
return TimePoint(convertXiosDatetimeToString(calendar_origin, true));
Expand All @@ -302,6 +305,9 @@ TimePoint Xios::getCalendarOrigin()
*/
TimePoint Xios::getCalendarStart()
{
if (!cxios_is_defined_calendar_wrapper_start_date(clientCalendar)) {
throw std::runtime_error("Xios: Calendar start date has not been set");
}
cxios_date calendar_start;
cxios_get_calendar_wrapper_date_start_date(clientCalendar, &calendar_start);
return TimePoint(convertXiosDatetimeToString(calendar_start, true));
Expand All @@ -314,6 +320,9 @@ TimePoint Xios::getCalendarStart()
*/
Duration Xios::getCalendarTimestep()
{
if (!cxios_is_defined_calendar_wrapper_timestep(clientCalendar)) {
throw std::runtime_error("Xios: Calendar timestep has not been set");
}
cxios_duration calendar_timestep;
cxios_get_calendar_wrapper_timestep(clientCalendar, &calendar_timestep);
return convertDurationFromXios(calendar_timestep);
Expand Down
5 changes: 4 additions & 1 deletion core/src/include/xios_c_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file xios_c_interface.hpp
* @author Tom Meltzer <tdm39@cam.ac.uk>
* @author Joe Wallwork <jw2423@cam.ac.uk>
* @date 12 August 2024
* @date 09 Dec 2024
* @brief C interface for XIOS library
* @details
* This interface is based on an earlier version provided by Laurent as part of
Expand Down Expand Up @@ -59,13 +59,16 @@ void cxios_get_calendar_wrapper_date_time_origin(
void cxios_get_calendar_wrapper_type(
xios::CCalendarWrapper* calendarWrapper_hdl, const char* type, int type_size);
void cxios_get_current_date(cxios_date* date);
bool cxios_is_defined_calendar_wrapper_time_origin(xios::CCalendarWrapper* calendar_wrapper_hdl);
bool cxios_is_defined_calendar_wrapper_start_date(xios::CCalendarWrapper* calendar_wrapper_hdl);
void cxios_update_calendar(int step);

// timestep methods
void cxios_set_calendar_wrapper_timestep(
xios::CCalendarWrapper* calendar_wrapper_hdl, cxios_duration timestep_c);
void cxios_get_calendar_wrapper_timestep(
xios::CCalendarWrapper* calendar_wrapper_hdl, cxios_duration* timestep_c);
bool cxios_is_defined_calendar_wrapper_timestep(xios::CCalendarWrapper* calendar_wrapper_hdl);
void cxios_update_calendar_timestep(xios::CCalendarWrapper* calendarWrapper_hdl);

// axis group methods
Expand Down

0 comments on commit cd35f66

Please sign in to comment.