star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

commit 559e6cfe753448531feeee1d22941d9cd09f227d
parent d0529a23cdc224804729bf442cfc119c3fdf4a65
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 15 Feb 2022 11:28:56 +0100

Test the loading of a transition file

Diffstat:
Msrc/test_shitran_transitions.c | 43+++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/test_shitran_transitions.c b/src/test_shitran_transitions.c @@ -196,11 +196,51 @@ test_load_failures(struct shitran* shitran) test_transition(shitran, &tr, RES_BAD_ARG); } +static void +check_transition(const struct shitran_transition* tr) +{ + /* Check NaN */ + CHK(tr->wavenumber == tr->wavenumber); + CHK(tr->intensity == tr->intensity); + CHK(tr->gamma_air == tr->gamma_air); + CHK(tr->gamma_self == tr->gamma_self); + CHK(tr->lower_state_energy == tr->lower_state_energy); + CHK(tr->n_air == tr->n_air); + CHK(tr->delta_air == tr->delta_air); + + CHK(tr->wavenumber > 0); + CHK(tr->intensity > 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); +} + +static void +test_load_file(struct shitran* shitran, const char* path) +{ + struct shitran_transitions* trs = NULL; + const struct shitran_transition* trs_list = NULL; + size_t i, n; + CHK(path); + printf("Loading `%s'.\n", path); + CHK(shitran_transitions_load(shitran, path, &trs) == RES_OK); + CHK(shitran_transitions_get_count(trs, &n) == RES_OK); + printf(" #transitions: %lu\n", n); + + CHK(shitran_transitions_get(trs, &trs_list) == RES_OK); + FOR_EACH(i, 0, n) check_transition(trs_list+i); + CHK(shitran_transitions_ref_put(trs) == RES_OK); +} + int main(int argc, char** argv) { struct shitran_create_args args = SHITRAN_CREATE_ARGS_DEFAULT; struct shitran* shitran = NULL; + int i; (void)argc, (void)argv; args.verbose = 1; @@ -208,6 +248,9 @@ main(int argc, char** argv) test_load(shitran); test_load_failures(shitran); + FOR_EACH(i, 1, argc) { + test_load_file(shitran, argv[i]); + } CHK(shitran_ref_put(shitran) == RES_OK); CHK(mem_allocated_size() == 0);