commit 701b894144e64bafece998abf9d6c886d99cb8d5
parent 32af2942953e4d9b4f0cfe02816cb60a0149019f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 8 Mar 2022 12:02:09 +0100
Update checks on loaded transition data
The self/air broadening half width can be null while the temperature
dependent exponent can lie in [-inf, +inf]. Finally, even if the lower
state energy cannot be negative, its value can be -1, which means that
it is not available.
Diffstat:
3 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/src/shtr_param.c b/src/shtr_param.c
@@ -32,19 +32,19 @@
#define DEFINE_PARSE_PARAM_FUNCTION(Type) \
res_T \
parse_param_##Type \
- (struct shtr* shtr, \
+ (struct shtr* shtr, \
const char* str, \
const struct param_desc* desc, \
Type* out_param) \
{ \
Type param = 0; \
res_T res = RES_OK; \
- ASSERT(shtr && desc && out_param); \
+ ASSERT(shtr && desc && out_param); \
ASSERT(desc->low < desc->upp \
|| (desc->low == desc->upp && desc->is_low_incl && desc->is_upp_incl));\
\
if(!str) { \
- log_err(shtr, "%s:%lu: %s is missing.\n", \
+ log_err(shtr, "%s:%lu: %s is missing.\n", \
desc->path, (unsigned long)desc->line, desc->name); \
res = RES_BAD_ARG; \
goto error; \
@@ -52,7 +52,7 @@
\
res = cstr_to_##Type(str, ¶m); \
if(res != RES_OK) { \
- log_err(shtr, "%s:%lu: invalid %s `%s'.\n", \
+ log_err(shtr, "%s:%lu: invalid %s `%s'.\n", \
desc->path, (unsigned long)desc->line, desc->name, str); \
res = RES_BAD_ARG; \
goto error; \
@@ -60,7 +60,7 @@
\
if(param < desc->low || (param == desc->low && !desc->is_low_incl) \
|| param > desc->upp || (param == desc->upp && !desc->is_upp_incl)) { \
- log_err(shtr, \
+ log_err(shtr, \
"%s:%lu: invalid %s `%s'. It must be in " \
"%c"CONCAT(C_FORMAT_, Type)", "CONCAT(C_FORMAT_, Type)"%c.\n", \
desc->path, (unsigned long)desc->line, desc->name, str, \
diff --git a/src/shtr_transitions_list.c b/src/shtr_transitions_list.c
@@ -110,7 +110,7 @@ parse_transition(struct shtr_transitions_list* trlst, struct txtrdr* txtrdr)
param.upp = (Upp); \
param.is_low_incl = (LowIncl); \
param.is_upp_incl = (UppIncl); \
- res = parse_param_##Type(shtr, str, ¶m, Var); \
+ res = parse_param_##Type(shtr, str, ¶m, Var); \
if(res != RES_OK) goto error; \
} (void)0
@@ -126,10 +126,27 @@ parse_transition(struct shtr_transitions_list* trlst, struct txtrdr* txtrdr)
NEXT(10); /* Skip the Enstein coef */
- PARSE(&tr.gamma_air, 5, double, "air broadening half-width", 0,INF,0,1);
- PARSE(&tr.gamma_self, 5, double, "self broadening half-width", 0,INF,0,1);
- PARSE(&tr.lower_state_energy, 10, double, "lower state energy", 0,INF,1,1);
- PARSE(&tr.n_air, 4, double, "temperature-dependent exponent", 0,INF,0,1);
+ PARSE(&tr.gamma_air, 5, double, "air broadening half-width", 0,INF,1,1);
+ PARSE(&tr.gamma_self, 5, double, "self broadening half-width", 0,INF,1,1);
+
+ /* Handle unavailable lower state energy */
+ PARSE(&tr.lower_state_energy, 10, double, "lower state energy",-INF,INF,1,1);
+ if(tr.lower_state_energy == -1) {
+ log_warn(shtr,
+ "%s:%lu: the lower state energy is unavailable for this line, so it is "
+ "ignored.\n", param.path, param.line);
+ goto exit; /* Skip the transition */
+ }
+ /* Check the domain validity */
+ if(tr.lower_state_energy < 0) {
+ log_err(shtr,
+ "%s:%lu: invalid lower state energy %g. It must be in [0, INF].\n",
+ param.path, param.line, tr.lower_state_energy);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ PARSE(&tr.n_air, 4, double, "temperature-dependent exponent",-INF,INF,1,1);
PARSE(&tr.delta_air, 8, double, "air-pressure wavenumber shift", -INF,INF,1,1);
/* Skip the remaining values */
diff --git a/src/test_shtr_transitions.c b/src/test_shtr_transitions.c
@@ -18,6 +18,7 @@
#include "shtr.h"
+#include <rsys/clock_time.h>
#include <rsys/mem_allocator.h>
#include <rsys/math.h>
@@ -170,19 +171,19 @@ test_load_failures(struct shtr* shtr)
test_transition(shtr, &tr, RES_BAD_ARG);
/* Invalid gamma air */
- tr = tr_ref; tr.gamma_air = 0;
+ tr = tr_ref; tr.gamma_air = -1;
test_transition(shtr, &tr, RES_BAD_ARG);
/* Invalid gamma self */
- tr = tr_ref; tr.gamma_self = 0;
+ tr = tr_ref; tr.gamma_self = -1;
test_transition(shtr, &tr, RES_BAD_ARG);
- /* Invalid lower state energy */
+ /* Unavailable lower state energy */
tr = tr_ref; tr.lower_state_energy = -1;
- test_transition(shtr, &tr, RES_BAD_ARG);
+ test_transition(shtr, &tr, RES_OK);
- /* Invalid n_air */
- tr = tr_ref; tr.n_air = 0;
+ /* Invalid lower state energy */
+ tr = tr_ref; tr.lower_state_energy = -2;
test_transition(shtr, &tr, RES_BAD_ARG);
/* Invalid molecule id */
@@ -210,12 +211,11 @@ check_transition(const struct shtr_transition* tr)
CHK(tr->wavenumber > 0);
CHK(tr->intensity > 0);
- CHK(tr->gamma_air > 0);
- CHK(tr->gamma_self > 0);
+ CHK(tr->gamma_air >= 0);
+ CHK(tr->gamma_self >= 0);
CHK(tr->lower_state_energy >= 0);
- CHK(tr->n_air > 0);
CHK(tr->molecule_id >= 0 && tr->molecule_id < 100);
- CHK(tr->isotope_id_local >= 0 && tr->isotope_id_local < 9);
+ CHK(tr->isotope_id_local >= 0 && tr->isotope_id_local <= 9);
}
static void
@@ -249,7 +249,14 @@ main(int argc, char** argv)
test_load(shtr);
test_load_failures(shtr);
FOR_EACH(i, 1, argc) {
+ char buf[64];
+ struct time t0, t1;
+
+ time_current(&t0);
test_load_file(shtr, argv[i]);
+ time_sub(&t0, time_current(&t1), &t0);
+ time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf));
+ printf("%s loaded in %s\n", argv[i], buf);
}
CHK(shtr_ref_put(shtr) == RES_OK);