star-blackbody

Handling the Planck function
git clone git://git.meso-star.fr/star-blackbody.git
Log | Files | Refs | README | LICENSE

commit 94534dda6586253b4e08a4a7971b35c11e2281ad
parent c36c173300a96a912eefcd1858e5a16211824f44
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 24 Nov 2023 11:10:23 +0100

Several problems fixed

The sbb_ran_planck function incorrectly accepted a NULL pointer for
output arguments. In addition, the length of the bands used to
accelerate sampling was incorrectly calculated.

Finally, the average radiance was incorrectly evaluated in the
sbb_radiance_temperature function.

Diffstat:
Msrc/sbb.c | 17++++++++---------
Msrc/sbb_ran_planck.c | 3++-
2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/sbb.c b/src/sbb.c @@ -61,12 +61,12 @@ sbb_blackbody_fraction const double temperature) /* [K] */ { const double C2 = 1.43877735e-2; /* [m.K] */ - double x0 = C2 / lambda0; - double x1 = C2 / lambda1; - double v0 = x0 / temperature; - double v1 = x1 / temperature; - double w0 = sbb_wiebelt(v0); - double w1 = sbb_wiebelt(v1); + const double x0 = C2 / lambda0; + const double x1 = C2 / lambda1; + const double v0 = x0 / temperature; + const double v1 = x1 / temperature; + const double w0 = wiebelt(v0); + const double w1 = wiebelt(v1); return w1 - w0; } @@ -183,9 +183,8 @@ sbb_radiance_temperature } /* From integrated radiance to average radiance in W/m^2/sr/m */ - if(lambda_min == lambda_max) { /* monochromatic */ - radiance_avg = radiance; - } else { + radiance_avg = radiance; + if(lambda_min != lambda_max) { /* !monochromatic */ radiance_avg /= (lambda_max - lambda_min); } diff --git a/src/sbb_ran_planck.c b/src/sbb_ran_planck.c @@ -300,6 +300,7 @@ sbb_ran_planck_create struct logger* logger = NULL; res_T res = RES_OK; + if(!out_planck) return RES_BAD_ARG; res = check_ranst_planck_create_args(args); if(res != RES_OK) goto error; @@ -331,7 +332,7 @@ sbb_ran_planck_create planck->band_len = 0; } else { planck->band_len = - (planck->range[0] - planck->range[1]) + (planck->range[1] - planck->range[0]) / (double)planck->nbands; res = setup_cdf(planck);