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 8b72b53d71c91a7ca6bc66b53bbeea4c92027ff8
parent d1fa1ee8839cdbd02b3f3a44323e620fcd076259
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 10 Feb 2022 10:59:32 +0100

Test the isotope metadata data loaded from a file

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

diff --git a/src/test_shitran_isotope_metadata.c b/src/test_shitran_isotope_metadata.c @@ -111,6 +111,44 @@ molecule_eq(const struct shitran_molecule* m0, const struct shitran_molecule* m1 return 1; } +static void +check_isotope + (struct shitran_isotope_metadata* mdata, + const struct shitran_molecule* molecule, + const struct shitran_isotope* isotope) +{ + struct shitran_molecule molecule2 = SHITRAN_MOLECULE_NULL; + + /* Check NaN */ + CHK(isotope->abundance == isotope->abundance); + CHK(isotope->Q296K == isotope->Q296K); + CHK(isotope->molar_mass == isotope->molar_mass); + + CHK(isotope->abundance > 0 && isotope->abundance <= 1); + CHK(isotope->Q296K > 0); + CHK(isotope->molar_mass > 0); + CHK(isotope->id >= 0); + + CHK(shitran_isotope_metadata_get_molecule + (mdata, isotope->imolecule, &molecule2) == RES_OK); + CHK(molecule_eq(molecule, &molecule2)); +} + +static void +check_molecule + (struct shitran_isotope_metadata* mdata, + struct shitran_molecule* molecule) +{ + size_t i = 0; + + CHK(mdata && molecule); + CHK(molecule->name); + CHK(molecule->id >= 0); + + FOR_EACH(i, 0, molecule->nisotopes) { + check_isotope(mdata, molecule, molecule->isotopes+i); + } +} static void test_load(struct shitran* shitran) @@ -149,9 +187,11 @@ test_load(struct shitran* shitran) CHK(shitran_isotope_metadata_get_molecule(mdata, 0, &molecule) == RES_OK); CHK(molecule_eq(&molecule, &H2O)); + check_molecule(mdata, &molecule); CHK(shitran_isotope_metadata_get_molecule(mdata, 1, &molecule) == RES_OK); CHK(molecule_eq(&molecule, &CO2)); + check_molecule(mdata, &molecule); CHK(shitran_isotope_metadata_find_molecule(NULL, 1, &molecule) == RES_BAD_ARG); CHK(shitran_isotope_metadata_find_molecule(mdata, 1, NULL) == RES_BAD_ARG); @@ -316,9 +356,18 @@ static void test_load_file(struct shitran* shitran, const char* path) { struct shitran_isotope_metadata* mdata = NULL; + size_t i, n; CHK(path); printf("Loading `%s'.\n", path); CHK(shitran_isotope_metadata_load(shitran, path, &mdata) == RES_OK); + CHK(shitran_isotope_metadata_get_molecules_count(mdata, &n) == RES_OK); + printf(" #molecules: %lu\n", n); + FOR_EACH(i, 0, n) { + struct shitran_molecule molecule = SHITRAN_MOLECULE_NULL; + CHK(shitran_isotope_metadata_get_molecule(mdata, i, &molecule) == RES_OK); + printf(" Checking %s\n", molecule.name); + check_molecule(mdata, &molecule); + } CHK(shitran_isotope_metadata_ref_put(mdata) == RES_OK); }