htgop

Optical properties of a gas mixture
git clone git://git.meso-star.fr/htgop.git
Log | Files | Refs | README | LICENSE

commit 8c91240f90f27048e16f570cc0b44991ee2d8c95
parent e875fb97b81112c7279344947a232466e8944d15
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 30 Jul 2018 14:31:50 +0200

Add more checks during loading

Check that the tabulated xH2O an that the levels are correctly sorted in
strict ascending order.

Diffstat:
Msrc/htgop.c | 13+++++++++++++
Msrc/test_htgop_load.c | 10++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/htgop.c b/src/htgop.c @@ -445,6 +445,12 @@ load_stream(struct htgop* htgop, FILE* stream, const char* stream_name) } FOR_EACH(ilvl, 0, nlvls) { /* Height */ CALL(cstr_to_double(read_line(&rdr), &levels[ilvl].height)); + if(ilvl && levels[ilvl].height <= levels[ilvl-1].height) { + log_err(htgop, + "%s:%lu: The levels must be sorted in strict ascending order " + "wrt their height.\n", rdr.name, rdr.iline); + goto error; + } } /* Per layer x H2O nominal */ @@ -465,6 +471,13 @@ load_stream(struct htgop* htgop, FILE* stream, const char* stream_name) FOR_EACH(ilay, 0, nlays) { double* x_h2o_tab = darray_double_data_get(&layers[ilay].x_h2o_tab); CALL(cstr_to_double(read_line(&rdr), &x_h2o_tab[itab])); + + if(itab && x_h2o_tab[itab] < x_h2o_tab[itab-1]) { + log_err(htgop, + "%s:%lu: The tabulated x H2O must be sorted in strict ascending " + "order.\n", rdr.name, rdr.iline); + goto error; + } } } diff --git a/src/test_htgop_load.c b/src/test_htgop_load.c @@ -106,6 +106,10 @@ main(int argc, char** argv) CHK(htgop_get_level(htgop, ilvl, &lvl) == RES_OK); CHK(cstr_to_double(read_line(&rdr), &dbl) == RES_OK); CHK(dbl == lvl.height); + if(ilvl) { /* Check strict ascending order */ + CHK(htgop_get_level(htgop, ilvl-1, &lvl) == RES_OK); + CHK(lvl.height < dbl); + } } /* Per layer nominal xH2O */ @@ -131,6 +135,8 @@ main(int argc, char** argv) CHK(htgop_get_layer(htgop, ilay, &lay) == RES_OK); CHK(cstr_to_double(read_line(&rdr), &dbl) == RES_OK); CHK(dbl == lay.x_h2o_tab[itab]); + /* Check strict ascending order */ + CHK(!itab || lay.x_h2o_tab[itab] > lay.x_h2o_tab[itab-1]); } } @@ -186,7 +192,7 @@ main(int argc, char** argv) if(iquad == 0) { CHK(specint.quadrature_cdf[iquad] == dbl); } else { - const double pdf = + const double pdf = specint.quadrature_cdf[iquad] - specint.quadrature_cdf[iquad-1]; CHK(eq_eps(pdf, dbl, 1.e-6)); } @@ -224,7 +230,7 @@ main(int argc, char** argv) if(iquad == 0) { CHK(specint.quadrature_cdf[iquad] == dbl); } else { - const double pdf = + const double pdf = specint.quadrature_cdf[iquad] - specint.quadrature_cdf[iquad-1]; CHK(eq_eps(pdf, dbl, 1.e-6)); }