star-meteo

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

commit 8ad4997df9f7ef488918ebcebdcf6a6a9a88ae71
parent 4ee0eae5b1c0d66576adf1d85e9ed8624a4399e5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 11 Aug 2025 15:59:10 +0200

Check that the number of data loaded matches the expected number

Do not return an error if this is not the case. Instead, display a
warning, as it may be a deliberate choice by the user to provide only a
subset of their data without bothering to update the header accordingly.
Since this number is only used internally to pre-allocate storage space,
it is not critical to ignore its value.

Diffstat:
Msrc/smeteo_load.c | 16++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/smeteo_load.c b/src/smeteo_load.c @@ -293,6 +293,8 @@ static res_T load_stream(struct smeteo* smeteo, FILE* fp, const char* name) { struct txtrdr* txtrdr = NULL; + size_t i = 0; + size_t nintervals = 0; res_T res = RES_OK; ASSERT(smeteo && name); @@ -308,12 +310,22 @@ load_stream(struct smeteo* smeteo, FILE* fp, const char* name) if((res = parse_header(smeteo, txtrdr)) != RES_OK) goto error; - for(;;) { + nintervals = darray_entry_capacity(&smeteo->entries); + + FOR_EACH(i, 0, nintervals) { if((res = txtrdr_read_line(txtrdr)) != RES_OK) { ERROR_READ_LINE(smeteo, txtrdr, res); goto error; } - if(!txtrdr_get_cline(txtrdr)) break; /* No more line */ + + if(!txtrdr_get_cline(txtrdr)) { + WARN(smeteo, + "%s: missing data. %lu meteorological data sets varying over time are " + "expected, but only %lu are provided.\n", + txtrdr_get_name(txtrdr), nintervals, i); + break; + } + if((res = parse_line(smeteo, txtrdr)) != RES_OK) goto error; }