From cd35f66cc034f7c0a188496ad91a39641f80031a Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Mon, 9 Dec 2024 13:20:13 +0000 Subject: [PATCH] Throw error if calendar attributes unset --- core/src/Xios.cpp | 11 ++++++++++- core/src/include/xios_c_interface.hpp | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/Xios.cpp b/core/src/Xios.cpp index 93b65a176..68d8b257e 100644 --- a/core/src/Xios.cpp +++ b/core/src/Xios.cpp @@ -2,7 +2,7 @@ * @file Xios.cpp * @author Tom Meltzer * @author Joe Wallwork - * @date 04 Dec 2024 + * @date 09 Dec 2024 * @brief XIOS interface implementation * @details * @@ -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)); @@ -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)); @@ -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); diff --git a/core/src/include/xios_c_interface.hpp b/core/src/include/xios_c_interface.hpp index c3663f213..11713b637 100644 --- a/core/src/include/xios_c_interface.hpp +++ b/core/src/include/xios_c_interface.hpp @@ -2,7 +2,7 @@ * @file xios_c_interface.hpp * @author Tom Meltzer * @author Joe Wallwork - * @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 @@ -59,6 +59,8 @@ 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 @@ -66,6 +68,7 @@ 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