This show how to work with events.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tests.h"
initCalendar(PROLEPTIC_GREGORIAN);
{
struct {
} tests[] =
.value = "3600000"},
.value = "3600"},
.value = "60"},
.value = "1"},
.value = "PT01H"}};
enum {NUM_TESTS = sizeof(tests) / sizeof(tests[0])};
for (size_t i = 0; i < NUM_TESTS; ++i)
if (strcmp(
tests[i].
value, tests[i].time_unit),
"PT01H"))
PUT_ERR("ERROR in yac_time_to_ISO");
}
{
char const * start_date = "1850-01-01T00:00:00";
char const * stop_date = "1850-01-01T00:01:00";
char const * model_time_step_iso =
char const * coupling_time_step_iso =
event, model_time_step_iso, coupling_time_step_iso,
char time_step_buffer[MAX_TIMEDELTA_STR_LEN];
if (strcmp(
coupling_time_step_iso))
PUT_ERR("ERROR in yac_get_event_coupling_timestep");
if (strcmp(
model_time_step_iso))
PUT_ERR("ERROR in yac_get_event_model_timestep");
PUT_ERR("ERROR in yac_get_event_lag");
free((void*)coupling_time_step_iso);
free((void*)model_time_step_iso);
enum {NUM_TIME_STEPS = 15};
for (int t = 0; t < NUM_TIME_STEPS; ++t) {
}
}
{
char const * start_date = "1850-01-01T00:00:00";
char const * stop_date = "1850-01-01T00:01:00";
char const * model_time_step_iso =
char const * coupling_time_step_iso =
event, model_time_step_iso, coupling_time_step_iso,
char time_step_buffer[MAX_TIMEDELTA_STR_LEN];
if (strcmp(
coupling_time_step_iso))
PUT_ERR("ERROR in yac_get_event_coupling_timestep");
if (strcmp(
model_time_step_iso))
PUT_ERR("ERROR in yac_get_event_model_timestep");
PUT_ERR("ERROR in yac_get_event_lag");
free((void*)coupling_time_step_iso);
free((void*)model_time_step_iso);
enum {NUM_TIME_STEPS = 15};
for (int t = 0; t < NUM_TIME_STEPS; ++t) {
}
}
{
char const * start_date = "1850-01-01T00:00:00";
char const * stop_date = "1850-01-01T06:00:00";
char const * model_time_step_iso =
char const * coupling_time_step_iso =
event, model_time_step_iso, coupling_time_step_iso,
char time_step_buffer[MAX_TIMEDELTA_STR_LEN];
if (strcmp(
coupling_time_step_iso))
PUT_ERR("ERROR in yac_get_event_coupling_timestep");
if (strcmp(
model_time_step_iso))
PUT_ERR("ERROR in yac_get_event_model_timestep");
PUT_ERR("ERROR in yac_get_event_lag");
free((void*)coupling_time_step_iso);
free((void*)model_time_step_iso);
enum {NUM_TIME_STEPS = 16};
for (int t = 0; t < NUM_TIME_STEPS; ++t) {
}
}
{
char const * start_date = "1850-01-01T00:00:00";
char const * stop_date = "1850-01-01T00:01:00";
enum {MIN_LAG = -6, MAX_LAG = 3};
enum {NUM_LAGS = MAX_LAG - MIN_LAG + 1};
enum {NUM_TIME_STEPS = 15};
for (
int lag = MIN_LAG;
lag <= MAX_LAG; ++
lag) {
char const * model_time_step_iso =
char const * coupling_time_step_iso =
event, model_time_step_iso, coupling_time_step_iso,
char time_step_buffer[MAX_TIMEDELTA_STR_LEN];
if (strcmp(
coupling_time_step_iso))
PUT_ERR("ERROR in yac_get_event_coupling_timestep");
if (strcmp(
model_time_step_iso))
PUT_ERR("ERROR in yac_get_event_model_timestep");
PUT_ERR("ERROR in yac_get_event_lag");
free((void*)coupling_time_step_iso);
free((void*)model_time_step_iso);
for (
int t =
lag; t < NUM_TIME_STEPS; ++t) {
if (
action != ref_action[t - MIN_LAG])
PUT_ERR("wrong action\n");
}
}
}
freeCalendar();
return TEST_EXIT_CODE;
}
char const * yac_time_to_ISO(char const *time, enum yac_time_unit_type time_unit)
int main(int argc, char **argv)
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)
struct event * yac_event_new()
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
enum yac_action_type action
struct _timedelta * model_time_step
struct _timedelta * coupling_time_step