star-aerosol

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

commit 1eaa75002d3ee4c17cfc54dd07fd9ef1194273b3
parent 32f0668d519c8bd94032af3d774720d20d24386f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 25 Aug 2022 18:21:55 +0200

Fix the sars_find_overlaped_bands function

Diffstat:
Msrc/sars.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/sars.c b/src/sars.c @@ -401,7 +401,7 @@ sars_find_overlaped_bands size_t nbands = 0; res_T res = RES_OK; - if(!sars || !range || !bands || range[0] > range[1]) { + if(!sars || !range || !ibands || range[0] > range[1]) { res = RES_BAD_ARG; goto error; } @@ -420,11 +420,17 @@ sars_find_overlaped_bands } upp = search_lower_bound(range+1, bands, nbands, sizeof(*bands), cmp_band); - if(upp) { - ibands[1] = (size_t)(upp - bands); - } else { - /* The submitted range overlaps the remaining bands */ + if(!upp) { /* The submitted range overlaps the remaining bands */ ibands[1] = nbands - 1; + } else if(upp->low <= range[1]) { /* The upper band includes range[1] */ + ibands[1] = (size_t)(upp - bands); + } else if(upp->low > range[1]) { /* The upper band is greater than range[1] */ + if(upp != bands) { + ibands[1] = (size_t)(upp - bands - 1); + } else { + ibands[0] = SIZE_MAX; + ibands[1] = 0; + } } exit: