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 4867179150e9c9208de8c14acb7e62466c54eb59
parent 931d5d88fda890b6eef548831e976dc70edae56b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 14 Feb 2022 15:58:32 +0100

Test the loading of transitions

Diffstat:
Mcmake/CMakeLists.txt | 1+
Asrc/test_shitran_transitions.c | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -90,6 +90,7 @@ if(NOT NO_TEST) new_test(test_shitran) new_test(test_shitran_isotope_metadata) + new_test(test_shitran_transitions) endif() ################################################################################ diff --git a/src/test_shitran_transitions.c b/src/test_shitran_transitions.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2022 CNRS - LMD + * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2022 Université Paul Sabatier - IRIT + * Copyright (C) 2022 Université Paul Sabatier - Laplace + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "shitran.h" + +#include <rsys/mem_allocator.h> +#include <rsys/math.h> + +#include <string.h> + +static const struct shitran_transition g_transitions[] = { + {0.000134, 2.672E-38, 0.0533, 0.410, 608.4727, 0.79, 0.000060, 1, 4}, + {0.000379, 1.055E-39, 0.0418, 0.329,1747.9686, 0.79, 0.000110, 1, 5}, + {0.000448, 5.560E-38, 0.0490, 0.364,1093.0269, 0.79, 0.000060, 1, 4}, + {0.000686, 1.633E-36, 0.0578, 0.394, 701.1162, 0.79, 0.000180, 1, 4}, + {0.000726, 6.613E-33, 0.0695, 0.428, 402.3295, 0.79, 0.000240, 1, 3} +}; +static const size_t g_ntransitions = + sizeof(g_transitions) / sizeof(struct shitran_transition); + +static void +print_transitions + (FILE* fp, + const struct shitran_transition* transitions, + const size_t ntransitions) +{ + size_t i; + + CHK(fp && (!ntransitions || transitions)); + FOR_EACH(i, 0, ntransitions) { + fprintf(fp, + "%2d%1d%12.6f%10.3e 0.000E-00.%04d%5.3f%10.4f%4.2f%8.6f" + " 0 0 0" /* Global upper quanta */ + " 0 0 0" /* Global upper quanta */ + " 5 5 0 " /* Local upper quanta */ + " 5 5 1 " /* Local lower quanta */ + "562220" /* Error indices */ + "5041 7833348" /* References */ + " " /* Line mixing flag */ + " 66.0" /* g' */ + " 66.0" /* g'' */ + "\n", + transitions[i].molecule_id, + transitions[i].isotope_id_local == 9 ? 0 : transitions[i].isotope_id_local+1, + transitions[i].wavenumber, + transitions[i].intensity, + (int)(transitions[i].gamma_air*10000), + transitions[i].gamma_self, + transitions[i].lower_state_energy, + transitions[i].n_air, + transitions[i].delta_air); + } +} + +static void +test_load(struct shitran* shitran) +{ + struct shitran_transitions* trs = NULL; + const char* filename = "test_transitions.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(filename, "w+")); + print_transitions(fp, g_transitions, g_ntransitions); + rewind(fp); + + CHK(shitran_transitions_load_stream(NULL, fp, NULL, &trs) == RES_BAD_ARG); + CHK(shitran_transitions_load_stream(shitran, NULL, NULL, &trs) == RES_BAD_ARG); + CHK(shitran_transitions_load_stream(shitran, fp, NULL, NULL) == RES_BAD_ARG); + CHK(shitran_transitions_load_stream(shitran, fp, NULL, &trs) == RES_OK); + + CHK(shitran_transitions_ref_get(NULL) == RES_BAD_ARG); + CHK(shitran_transitions_ref_get(trs) == RES_OK); + CHK(shitran_transitions_ref_put(NULL) == RES_BAD_ARG); + CHK(shitran_transitions_ref_put(trs) == RES_OK); + 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; + (void)argc, (void)argv; + + args.verbose = 1; + CHK(shitran_create(&args, &shitran) == RES_OK); + + test_load(shitran); + + CHK(shitran_ref_put(shitran) == RES_OK); + CHK(mem_allocated_size() == 0); + return 0; +}