commit c89bd4beab21a32e0429d06394e5df36c0822813
parent 830e199c75c36875cf2ada239757f972b2bd00ca
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 25 Jul 2018 08:49:08 +0200
Add the htmie_compute_asymmetry_parameter_average function
Diffstat:
2 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/src/htmie.c b/src/htmie.c
@@ -35,13 +35,13 @@
} (void)0
/* Context used in the sum_xsections functor */
-struct sum_xsections_context {
+struct sum_context {
double prev_data;
double prev_wavelength;
double sum;
int first_entry;
};
-static const struct sum_xsections_context SUM_XSECTIONS_CONTEXT_NULL =
+static const struct sum_context SUM_CONTEXT_NULL =
{DBL_MAX, DBL_MAX, 0, 1};
struct htmie {
@@ -537,9 +537,9 @@ min_max(const double wavelength, const double data, void* ctx)
}
static FINLINE void
-sum_xsections(const double wavelength, const double data, void* context)
+sum(const double wavelength, const double data, void* context)
{
- struct sum_xsections_context* ctx = context;
+ struct sum_context* ctx = context;
ASSERT(context);
if(ctx->first_entry) {
@@ -762,7 +762,7 @@ htmie_get_xsections_scattering(const struct htmie* htmie)
}
const double*
-htmie_get_asymmetric_parameter(const struct htmie* htmie)
+htmie_get_asymmetry_parameter(const struct htmie* htmie)
{
ASSERT(htmie);
return darray_double_cdata_get(&htmie->g);
@@ -797,6 +797,16 @@ htmie_fetch_xsection_scattering
(htmie, wavelength, type, htmie_get_xsections_scattering(htmie));
}
+double
+htmie_fetch_asymmetry_parameter
+ (const struct htmie* htmie,
+ const double wavelength,
+ const enum htmie_filter_type type)
+{
+ ASSERT(htmie);
+ return fetch_data
+ (htmie, wavelength, type, htmie_get_asymmetry_parameter(htmie));
+}
void
htmie_compute_xsection_absorption_bounds
@@ -837,11 +847,10 @@ htmie_compute_xsection_absorption_average
const enum htmie_filter_type type)
{
const double* xsections;
- struct sum_xsections_context ctx = SUM_XSECTIONS_CONTEXT_NULL;
- ASSERT(htmie && band[0] < band[1]);
+ struct sum_context ctx = SUM_CONTEXT_NULL;
+ ASSERT(htmie && band && band[0] < band[1]);
xsections = darray_double_cdata_get(&htmie->xsections_absorption);
- for_each_wavelength_in_spectral_band
- (htmie, band, type, xsections, sum_xsections, &ctx);
+ for_each_wavelength_in_spectral_band(htmie, band, type, xsections, sum, &ctx);
return ctx.sum / (band[1] - band[0]);
}
@@ -852,22 +861,24 @@ htmie_compute_xsection_scattering_average
const enum htmie_filter_type type)
{
const double* xsections;
- struct sum_xsections_context ctx = SUM_XSECTIONS_CONTEXT_NULL;
- ASSERT(htmie && band[0] < band[1]);
+ struct sum_context ctx = SUM_CONTEXT_NULL;
+ ASSERT(htmie && band && band[0] < band[1]);
xsections = darray_double_cdata_get(&htmie->xsections_scattering);
- for_each_wavelength_in_spectral_band
- (htmie, band, type, xsections, sum_xsections, &ctx);
+ for_each_wavelength_in_spectral_band(htmie, band, type, xsections, sum, &ctx);
return ctx.sum / (band[1] - band[0]);
}
double
-htmie_fetch_asymmetric_parameter
+htmie_compute_asymmetry_parameter_average
(const struct htmie* htmie,
- const double wavelength,
+ const double band[2], /* Boundaries of of the spectral band in nanometer */
const enum htmie_filter_type type)
{
- ASSERT(htmie);
- return fetch_data
- (htmie, wavelength, type, htmie_get_asymmetric_parameter(htmie));
+ const double* g;
+ struct sum_context ctx = SUM_CONTEXT_NULL;
+ ASSERT(htmie && band && band[0] < band[1]);
+ g = darray_double_cdata_get(&htmie->g);
+ for_each_wavelength_in_spectral_band(htmie, band, type, g, sum, &ctx);
+ return ctx.sum / (band[1] - band[0]);
}
diff --git a/src/htmie.h b/src/htmie.h
@@ -90,7 +90,7 @@ htmie_get_xsections_scattering
(const struct htmie* htmie);
HTMIE_API const double*
-htmie_get_asymmetric_parameter
+htmie_get_asymmetry_parameter
(const struct htmie* htmie);
HTMIE_API size_t
@@ -111,6 +111,12 @@ htmie_fetch_xsection_scattering
const double wavelength,
const enum htmie_filter_type type);
+HTMIE_API double
+htmie_fetch_asymmetry_parameter
+ (const struct htmie* htmie,
+ const double wavelength,
+ const enum htmie_filter_type type);
+
/* Compute the maximum and the minimum value of the absorption cross section in
* a given spectral interval */
HTMIE_API void
@@ -143,10 +149,11 @@ htmie_compute_xsection_scattering_average
const double band[2], /* Boundaries of of the spectral band in nanometer */
const enum htmie_filter_type type);
+/* Compute the average asymmetry parameter in a given spectral interval */
HTMIE_API double
-htmie_fetch_asymmetric_parameter
+htmie_compute_asymmetry_parameter_average
(const struct htmie* htmie,
- const double wavelength,
+ const double band[2], /* Boundaries of of the spectral band in nanometer */
const enum htmie_filter_type type);
END_DECLS