star-meteo

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

commit 15feb3e8d57787634e26b21576aae8826ca33464
parent d5c24331dde74eed5b30bbf8272f03c099edda76
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 12 Aug 2025 11:54:13 +0200

Upd the calculation of the reference interval duration

Since intervals are defined relative to January 1, 1850, the duration of
the reference interval can be evaluated on the first interval, even if
only the time at the center of the interval is defined. Until now, it
was calculated once two intervals were loaded, by difference between
their interval center dates, so that the duration of the first interval
was not compared to this reference duration.

Diffstat:
Msrc/smeteo_load.c | 22+++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/smeteo_load.c b/src/smeteo_load.c @@ -339,14 +339,22 @@ 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); + if(i == 0) { + /* Calculate the reference of the interval duration. + * + * The dates of the intervals are relative to midnight on January 1, 1850. + * In addition, their time is defined at the center of the interval. Thus, + * for the first interval, calculate its duration by multiplying its date + * relative to January 1, 1850 by 2. This will be the reference duration + * for the intervals */ + interval_ref = darray_entry_cdata_get(&smeteo->entries)[i].day_1850 * 2; + + } else { + /* Check that the interval duration is constant */ + const double interval = + darray_entry_cdata_get(&smeteo->entries)[i-0].day_1850 + - darray_entry_cdata_get(&smeteo->entries)[i-1].day_1850; const double eps = interval_ref*1e-6; if(!eq_eps(interval, interval_ref, eps)) {