star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

commit ee491a22f00eb1824bdbcf1590a205ffb8bcecdc
parent 8ad4997df9f7ef488918ebcebdcf6a6a9a88ae71
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 11 Aug 2025 16:50:00 +0200

Check the duration of the time intervals

It must be constant.

Diffstat:
Msrc/smeteo_load.c | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/smeteo_load.c b/src/smeteo_load.c @@ -152,6 +152,15 @@ parse_line(struct smeteo* smeteo, struct txtrdr* txtrdr) res = parse_time(smeteo, txtrdr, date, hour, &entry.time); if(res != RES_OK) goto error; + if(entry.time.tm_year + 1900 < 1850) { /* tm_year: year minus 1900 */ + ERROR(smeteo, + "%s:%zu: unexpected date `%s'. " + "The year should be greater than or equal to 1850.\n", + txtrdr_get_name(txtrdr), txtrdr_get_line_num(txtrdr), date); + res = RES_BAD_ARG; + goto error; + } + #define PARSE_DOUBLE(Name, Var, Min, Max) { \ char* str = strtok_r(NULL, " \t", &tk_ctx); \ res = parse_double(smeteo, txtrdr, Name, str, Min, Max, &Var); \ @@ -295,6 +304,7 @@ load_stream(struct smeteo* smeteo, FILE* fp, const char* name) struct txtrdr* txtrdr = NULL; size_t i = 0; size_t nintervals = 0; + double interval_ref = -1; /* Reference duration of an interval */ res_T res = RES_OK; ASSERT(smeteo && name); @@ -327,6 +337,33 @@ load_stream(struct smeteo* smeteo, FILE* fp, const char* name) } if((res = parse_line(smeteo, txtrdr)) != RES_OK) goto error; + + #define COMPUTE_TIME_INTERVAL(Id) \ + darray_entry_cdata_get(&smeteo->entries)[Id-0].day_1850 \ + - darray_entry_cdata_get(&smeteo->entries)[Id-1].day_1850 + + if(i == 1) { /* Calculate the reference of the interval length */ + interval_ref = COMPUTE_TIME_INTERVAL(i); + + } else if(i > 1) { /* Check that the interval duration is constant */ + const double interval = COMPUTE_TIME_INTERVAL(i); + const double eps = interval_ref*1e-6; + + if(!eq_eps(interval, interval_ref, eps)) { + ERROR(smeteo, + "%s:%lu: invalid time interval. " + "It is calculated from the `day_1850' variables between consecutive " + "intervals. The interval duration must be constant, which is not the " + "case here. Reference interval: %g; current interval: %g -- " + "%g != %g +/- %g.\n", + txtrdr_get_name(txtrdr), txtrdr_get_line_num(txtrdr), + interval_ref, interval, interval_ref, interval, eps); + res = RES_BAD_ARG; + goto error; + } + } + + #undef COMPUTE_TIME_INTERVAL } exit: