star-ck

Describe the radiative properties of gas mixtures
git clone git://git.meso-star.fr/star-ck.git
Log | Files | Refs | README | LICENSE

commit 5178802a0749116983a05e43804924bafb55e18b
parent e3f860b8bba26e7a895bece4e429f01ba31d647b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 15 Jun 2022 09:23:17 +0200

Ensure that bands are sorted in ascending order and not overlap

Diffstat:
Msrc/sck.c | 12+++++++++++-
Msrc/test_sck_load.c | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/sck.c b/src/sck.c @@ -75,7 +75,7 @@ read_quad_pt stream_name, iband, iquad_pt); res = RES_IO_ERR; goto error; - } + } if(quad_pt->weight < 0) { log_err(sck, @@ -257,6 +257,16 @@ load_stream(struct sck* sck, FILE* stream, const char* stream_name) struct band* band = darray_band_data_get(&sck->bands) + iband; res = read_band(sck, band, stream, stream_name); if(res != RES_OK) goto error; + if(iband > 0 && band[0].low < band[-1].upp) { + log_err(sck, + "%s: bands must be sorted in ascending order and must not " + "overlap (band %lu in [%g, %g] nm; band %lu in [%g, %g] nm).\n", + stream_name, + (unsigned long)(iband-1), band[-1].low, band[-1].upp, + (unsigned long)(iband), band[ 0].low, band[ 0].upp); + res = RES_BAD_ARG; + goto error; + } } /* Compute the length in bytes of the k to map for each band/quadrature point */ diff --git a/src/test_sck_load.c b/src/test_sck_load.c @@ -336,6 +336,44 @@ test_load_fail(struct sck* sck) CHK(sck_load_stream(sck, fp, NULL) == RES_BAD_ARG); CHK(fclose(fp) == 0); + + /* Unsorted bands */ + fp = tmpfile(); + CHK(fp); + pagesize = 16384; + nnodes = 1; + nbands = 2; + CHK(fwrite(&pagesize, sizeof(pagesize), 1, fp) == 1); + CHK(fwrite(&nbands, sizeof(nbands), 1, fp) == 1); + CHK(fwrite(&nnodes, sizeof(nnodes), 1, fp) == 1); + low = 1; + upp = 2; + nqpts = 1; + CHK(fwrite(&low, sizeof(low), 1, fp) == 1); + CHK(fwrite(&upp, sizeof(upp), 1, fp) == 1); + CHK(fwrite(&nqpts, sizeof(nqpts), 1, fp) == 1); + weight = 1; + CHK(fwrite(&weight, sizeof(weight), 1, fp) == 1); + low = 0; + upp = 1; + nqpts = 1; + CHK(fwrite(&low, sizeof(low), 1, fp) == 1); + CHK(fwrite(&upp, sizeof(upp), 1, fp) == 1); + CHK(fwrite(&nqpts, sizeof(nqpts), 1, fp) == 1); + weight = 1; + CHK(fwrite(&weight, sizeof(weight), 1, fp) == 1); + CHK(fseek(fp, (long)ALIGN_SIZE((size_t)ftell(fp), pagesize), SEEK_SET) == 0); + ks = 1; + CHK(fwrite(&ka, sizeof(ks), 1, fp) == 1); + CHK(fseek(fp, (long)ALIGN_SIZE((size_t)ftell(fp), pagesize), SEEK_SET) == 0); + ka = 1; + CHK(fwrite(&ka, sizeof(ka), 1, fp) == 1); + CHK(fseek(fp, (long)ALIGN_SIZE((size_t)ftell(fp), pagesize)-1, SEEK_SET) == 0); + CHK(fwrite(&byte, sizeof(byte), 1, fp) == 1); /* Positioned the EOF */ + rewind(fp); + + CHK(sck_load_stream(sck, fp, NULL) == RES_BAD_ARG); + CHK(fclose(fp) == 0); } static void