14#define SECONDS_PER_DAY 86400
56 char const * delta_model_time,
57 char const * delta_coupling_time,
64 getCalendarType() != CALENDAR_NOT_SET,
65 "ERROR(yac_event_add): no calendar has been defined")
67 "ERROR(yac_event_add): event is already initialised.");
71 char PTstring[MAX_TIMEDELTA_STR_LEN];
79 event->dummy_time_step = newTimeDelta(getPTStringFromMS(0, PTstring));
82 event->model_time_step = newTimeDelta(delta_model_time);
83 event->coupling_time_step = newTimeDelta(delta_coupling_time);
87 "ERROR(yac_event_add): failed to generate model timestep from \"%s\" "
88 "(has to be in ISO 8601 format)", delta_model_time)
91 "ERROR(yac_event_add): failed to generate model timestep from \"%s\""
92 "(has to be in ISO 8601 format)", delta_coupling_time)
94 compare_return_val compare_timestep =
97 compare_timestep != greater_than,
98 "ERROR(yac_event_add): model timestep is bigger than coupling timestep "
99 "(\"%s\" > \"%s\")", delta_model_time, delta_coupling_time)
103 if (compare_timestep == equal_to)
event->time_operation =
TIME_NONE;
105 calendarType set_calender = getCalendarType ();
108 set_calender != CALENDAR_NOT_SET,
"ERROR: Calendar is not set.")
110 event->startdate = newDateTime(
startdate);
113 event->currentdate = newDateTime(
startdate);
116 event->stopdate = newDateTime(
stopdate);
122 event->model_time_step->sign=
'-';
125 for (
int i = 0; i <
lag; ++i)
127 addTimeDeltaToDateTime (
133 event->coupling_time_step->sign =
'-';
136 addTimeDeltaToDateTime (
138 event->coupling_time_step->sign =
'+';
140 event->model_time_step->sign=
'+';
142 char timedelta_str[MAX_TIMEDELTA_STR_LEN];
143 char datetime_str[MAX_DATETIME_STR_LEN];
147 "Coupling", (
char *) datetime_str, (
char *) datetime_str,
153#ifdef YAC_VERBOSE_EVENT
154 printf (
"event added\n" );
155 printf (
"- start date: %s\n",
157 printf (
"- current date: %s\n",
159 printf (
"- stop date: %s\n",
161 printf (
"- model time step: %s\n",
163 printf (
"- coupling time step: %s\n",
173 "ERROR(yac_event_update): event has not yet been initialised");
176 addTimeDeltaToDateTime(
196#ifdef YAC_VERBOSE_EVENT
197 char datetime_str[MAX_DATETIME_STR_LEN];
198 printf (
"- current date: %s\n",
200 printf (
"- stop date: %s\n",
204 compare_return_val check_stopdate =
208 (check_stopdate == less_than) ||
209 (check_stopdate == equal_to) ||
210 (check_stopdate == greater_than),
211 "ERROR(yac_event_check): compareDatetime(currentdate,stopdate) failed")
216 if (check_stopdate == greater_than) {
218#ifdef YAC_VERBOSE_EVENT
219 printf (
"event check delivers OUT_OF_BOUND\n");
232 if (check_stopdate == equal_to) {
234#ifdef YAC_VERBOSE_EVENT
235 printf (
"event check delivers RESTART\n" );
241#ifdef YAC_VERBOSE_EVENT
242 printf (
"event check delivers COUPLING\n" );
286 return event->time_operation;
292 struct event *
event,
char * timedelta_str ) {
294 memset(timedelta_str,
'\0',MAX_TIMEDELTA_STR_LEN);
298 return timedelta_str;
305 struct event *
event,
char * timedelta_str ) {
307 memset(timedelta_str,
'\0',MAX_TIMEDELTA_STR_LEN);
311 return timedelta_str;
323 int64_t time_int64_t = (int64_t)strtol(time, &endptr, 10);
325 *endptr ==
'\0',
"ERROR(str2int64): invalid time string '%s'", time)
332 YAC_ASSERT(time,
"ERROR(yac_time_to_ISO): time is NULL");
339 "ERROR(yac_time_to_ISO): unsupported time unit")
342 getCalendarType() != CALENDAR_NOT_SET,
343 "ERROR(yac_time_to_ISO): calendar has not yet been set")
345 static char PT_String_buffer[MAX_TIMEDELTA_STR_LEN];
351 getPTStringFromMS(
str2int64(time), PT_String_buffer);
354 getPTStringFromSeconds(
str2int64(time), PT_String_buffer);
357 getPTStringFromMinutes(
str2int64(time), PT_String_buffer);
360 getPTStringFromHours(
str2int64(time), PT_String_buffer);
363 strncpy(PT_String_buffer, time, MAX_TIMEDELTA_STR_LEN-1);
367 return PT_String_buffer;
char * yac_get_event_model_timestep(struct event *event, char *timedelta_str)
char * yac_get_event_coupling_timestep(struct event *event, char *timedelta_str)
int yac_get_event_lag(struct event *event)
void yac_event_delete(struct event *event)
char * yac_get_event_current_datetime(struct event *event, char *datetime_str)
static int64_t str2int64(char const *time)
struct event * yac_event_new()
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
int yac_get_event_time_operation(struct event *event)
void yac_event_add(struct event *event, char const *delta_model_time, char const *delta_coupling_time, int lag, enum yac_reduction_type time_operation, const char *startdate, const char *stopdate)
enum yac_action_type yac_event_check(struct event *event)
void yac_event_update(struct event *event)
enum yac_time_unit_type time_unit
enum yac_reduction_type time_operation
struct _datetime * stopdate
struct _datetime * startdate
enum yac_action_type action
struct _datetime * offset
struct _timedelta * model_time_step
struct _datetime * currentdate
struct _timedelta * dummy_time_step
struct _timedelta * coupling_time_step
#define YAC_ASSERT_F(exp, format,...)
#define YAC_ASSERT(exp, msg)