commit e3d1e1e772016c136c879464a37c4337e7c741a5
parent 5152414998fcb4296e7d6e5d197f832c790ca540
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 16 Nov 2022 18:56:16 +0100
Add the RNATM_MAX_COMPONENTS_COUNT constant
Set the maximum number of atmospheric components to 16 (including gas).
This constant simplifies reserving the memory space used to store data
per component: it can be done directly on the stack.
Diffstat:
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/rnatm.c b/src/rnatm.c
@@ -79,6 +79,10 @@ check_rnatm_create_args(const struct rnatm_create_args* args)
/* Invalid args */
if(!args) return RES_BAD_ARG;
+ /* Invalid total number of components */
+ if(args->naerosols + 1/*gas*/ >= RNATM_MAX_COMPONENTS_COUNT)
+ return RES_BAD_ARG;
+
/* Invalid gas */
res = check_rnatm_gas_args(&args->gas);
if(res != RES_OK) return res;
diff --git a/src/rnatm.h b/src/rnatm.h
@@ -48,6 +48,9 @@
/* Gas identifier */
#define RNATM_GAS ((size_t)-1)
+/* Maximum number of components supported by the library (gas included) */
+#define RNATM_MAX_COMPONENTS_COUNT 16
+
/* Forward declaration of external data types */
struct logger;
struct mem_allocator;
diff --git a/src/rnatm_properties.c b/src/rnatm_properties.c
@@ -34,9 +34,6 @@
#include <rsys/clock_time.h>
#include <rsys/cstr.h>
-#define CUMULATIVE_SIZE_MAX 32
-typedef float (cumulative_T)[CUMULATIVE_SIZE_MAX];
-
/*******************************************************************************
* Helper functions
******************************************************************************/
@@ -970,7 +967,7 @@ compute_unnormalized_cumulative_radcoef
const double pos[3],
const size_t iband,
const size_t iquad,
- cumulative_T cumulative,
+ float cumulative[RNATM_MAX_COMPONENTS_COUNT],
size_t* cumulative_sz,
/* For debug */
const double k_min,
@@ -988,10 +985,7 @@ compute_unnormalized_cumulative_radcoef
(void)k_min;
naerosols = darray_aerosol_size_get(&atm->aerosols);
- if(naerosols+1/*gas*/ > CUMULATIVE_SIZE_MAX) {
- res = RES_MEM_ERR;
- goto error;
- }
+ ASSERT(naerosols+1 < RNATM_MAX_COMPONENTS_COUNT);
/* Setup the arguments common to all components */
cell_args.iband = iband;
@@ -1039,7 +1033,7 @@ rnatm_get_radcoef
const struct rnatm_get_radcoef_args* args,
double* out_k)
{
- cumulative_T cumul;
+ float cumul[RNATM_MAX_COMPONENTS_COUNT];
size_t cumul_sz;
double k = 0;
res_T res = RES_OK;
@@ -1075,7 +1069,7 @@ rnatm_sample_component
const struct rnatm_sample_component_args* args,
size_t* cpnt)
{
- cumulative_T cumul;
+ float cumul[RNATM_MAX_COMPONENTS_COUNT];
float norm;
size_t cumul_sz;
size_t i;