star-aerosol

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

commit e01dc26d6dc9c48e38e62c716abafa032d9e82f7
parent aee232430128c044aca83d8b0dc3fbfbe908c911
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sat,  1 Oct 2022 17:45:19 +0200

Fix sars_find_bands

When the submitted range is a single wavelength and that wavelength is
below the first band, the function considers this band as valid whereas
it should be excluded. This commit fixes this issue by notifying that in
this case no band was found.

Diffstat:
Msrc/sars.c | 13++++++++++---
Msrc/test_sars_load.c | 15+++++++++++++++
2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/sars.c b/src/sars.c @@ -419,9 +419,16 @@ sars_find_bands goto exit; } - if(range[0] == range[1]) { - ibands[1] = ibands[0]; - goto exit; /* No more to search */ + if(range[0] == range[1]) { /* No more to search */ + if(range[0] < low->low) { + /* The wavelength is not included in any band */ + ibands[0] = SIZE_MAX; + ibands[1] = 0; + } else { + ASSERT(range[0] < low->upp); + ibands[1] = ibands[0]; + } + goto exit; } upp = search_lower_bound(range+1, bands, nbands, sizeof(*bands), cmp_band); diff --git a/src/test_sars_load.c b/src/test_sars_load.c @@ -317,11 +317,26 @@ test_find(struct sars* sars) CHK(sars_find_bands(sars, range, ibands) == RES_OK); CHK(ibands[0] > ibands[1]); + range[0] = 11; + range[1] = 11; + CHK(sars_find_bands(sars, range, ibands) == RES_OK); + CHK(ibands[0] > ibands[1]); + range[0] = 0; range[1] = nextafter(1, 0); CHK(sars_find_bands(sars, range, ibands) == RES_OK); CHK(ibands[0] > ibands[1]); + range[0] = 0; + range[1] = 0; + CHK(sars_find_bands(sars, range, ibands) == RES_OK); + CHK(ibands[0] > ibands[1]); + + range[0] = nextafter(1, 0); + range[1] = nextafter(1, 0); + CHK(sars_find_bands(sars, range, ibands) == RES_OK); + CHK(ibands[0] > ibands[1]); + range[0] = 2; range[1] = 2; CHK(sars_find_bands(sars, range, ibands) == RES_OK);