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 b5a697bfb6853cdc14ddb33afe3776c98de3141f
parent 45cdde55695bee9d11f0b802934aab12897b6aa2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  9 Feb 2022 09:19:33 +0100

Test the loaded isotopes

Diffstat:
Msrc/test_sht_isotope_metadata.c | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 89 insertions(+), 33 deletions(-)

diff --git a/src/test_sht_isotope_metadata.c b/src/test_sht_isotope_metadata.c @@ -19,11 +19,94 @@ #include "sht.h" #include <rsys/mem_allocator.h> +#include <rsys/math.h> #include <string.h> +static const struct sht_isotope H2O_isotopes[] = { + {9.97317E-01, 1.7458E+02, 18.010565, 0, 1, 161}, + {1.99983E-03, 1.7605E+02, 20.014811, 0, 1, 181}, + {3.71884E-04, 1.0521E+03, 19.014780, 0, 6, 171}, + {3.10693E-04, 8.6474E+02, 19.016740, 0, 6, 162}, + {6.23003E-07, 8.7557E+02, 21.020985, 0, 6, 182}, + {1.15853E-07, 5.2268E+03, 20.020956, 0, 36, 172}, + {2.41974E-08, 1.0278E+03, 20.022915, 0, 1, 262} +}; + + +static const struct sht_molecule H2O = { + "H2O", sizeof(H2O_isotopes)/sizeof(struct sht_isotope), H2O_isotopes, 1, +}; + +static const struct sht_isotope CO2_isotopes[] = { + {9.84204E-01, 2.8609E+02, 43.989830, 1, 1, 626}, + {1.10574E-02, 5.7664E+02, 44.993185, 1, 2, 636}, + {3.94707E-03, 6.0781E+02, 45.994076, 1, 1, 628}, + {7.33989E-04, 3.5426E+03, 44.994045, 1, 6, 627}, + {4.43446E-05, 1.2255E+03, 46.997431, 1, 2, 638}, + {8.24623E-06, 7.1413E+03, 45.997400, 1, 12, 637}, + {3.95734E-06, 3.2342E+02, 47.998320, 1, 1, 828}, + {1.47180E-06, 3.7666E+03, 46.998291, 1, 6, 827}, + {1.36847E-07, 1.0972E+04, 45.998262, 1, 1, 727}, + {4.44600E-08, 6.5224E+02, 49.001675, 1, 2, 838}, + {1.65354E-08, 7.5950E+03, 48.001646, 1, 12, 837}, + {1.53745E-09, 2.2120E+04, 47.001618, 1, 2, 737} +}; + +static const struct sht_molecule CO2 = { + "CO2", sizeof(CO2_isotopes)/sizeof(struct sht_isotope), CO2_isotopes, 2, +}; + +static void +molecule_print(FILE* fp, const struct sht_molecule* molecule) +{ + size_t i; + CHK(fp && molecule); + + fprintf(fp, " %s (%d)\n", molecule->name, molecule->id); + FOR_EACH(i, 0, molecule->nisotopes) { + fprintf(fp, " %d %.5E %.4E %d %.6f\n", + molecule->isotopes[i].id, + molecule->isotopes[i].abundance, + molecule->isotopes[i].Q296K, + molecule->isotopes[i].gj, + molecule->isotopes[i].molar_mass); + } +} + +static int +isotope_eq(const struct sht_isotope* i0, const struct sht_isotope* i1) +{ + CHK(i0 && i1); + return i0->abundance == i1->abundance + && i0->Q296K == i1->Q296K + && i0->molar_mass == i1->molar_mass + && i0->molecule == i1->molecule + && i0->gj == i1->gj + && i0->id == i1->id; +} + +static int +molecule_eq(const struct sht_molecule* m0, const struct sht_molecule* m1) +{ + size_t i; + + CHK(m0 && m1); + if(strcmp(m0->name, m1->name) + || m0->id != m1->id + || m0->nisotopes != m1->nisotopes) + return 0; + + FOR_EACH(i, 0, m0->nisotopes) { + if(!isotope_eq(m0->isotopes+i, m1->isotopes+i)) + return 0; + } + return 1; +} + static void test_load(struct sht* sht) { + const char* filename = "test_isotope_metadata.txt"; struct sht_isotope_metadata* metadata = NULL; struct sht_molecule molecule = SHT_MOLECULE_NULL; @@ -33,27 +116,8 @@ test_load(struct sht* sht) CHK(fp = fopen(filename, "w+")); fprintf(fp, "Molecule # Iso Abundance Q(296K) gj Molar Mass(g)\n"); - fprintf(fp, " H2O (1)\n"); - fprintf(fp, " 161 9.97317E-01 1.7458E+02 1 18.010565\n"); - fprintf(fp, " 181 1.99983E-03 1.7605E+02 1 20.014811\n"); - fprintf(fp, " 171 3.71884E-04 1.0521E+03 6 19.014780\n"); - fprintf(fp, " 162 3.10693E-04 8.6474E+02 6 19.016740\n"); - fprintf(fp, " 182 6.23003E-07 8.7557E+02 6 21.020985\n"); - fprintf(fp, " 172 1.15853E-07 5.2268E+03 36 20.020956\n"); - fprintf(fp, " 262 2.41974E-08 1.0278E+03 1 20.022915\n"); - fprintf(fp, " CO2 (2)\n"); - fprintf(fp, " 626 9.84204E-01 2.8609E+02 1 43.989830\n"); - fprintf(fp, " 636 1.10574E-02 5.7664E+02 2 44.993185\n"); - fprintf(fp, " 628 3.94707E-03 6.0781E+02 1 45.994076\n"); - fprintf(fp, " 627 7.33989E-04 3.5426E+03 6 44.994045\n"); - fprintf(fp, " 638 4.43446E-05 1.2255E+03 2 46.997431\n"); - fprintf(fp, " 637 8.24623E-06 7.1413E+03 12 45.997400\n"); - fprintf(fp, " 828 3.95734E-06 3.2342E+02 1 47.998320\n"); - fprintf(fp, " 827 1.47180E-06 3.7666E+03 6 46.998291\n"); - fprintf(fp, " 727 1.36847E-07 1.0972E+04 1 45.998262\n"); - fprintf(fp, " 838 4.44600E-08 6.5224E+02 2 49.001675\n"); - fprintf(fp, " 837 1.65354E-08 7.5950E+03 12 48.001646\n"); - fprintf(fp, " 737 1.53745E-09 2.2120E+04 2 47.001618\n"); + molecule_print(fp, &H2O); + molecule_print(fp, &CO2); rewind(fp); CHK(sht_isotope_metadata_load_stream(NULL, fp, NULL, &metadata) == RES_BAD_ARG); @@ -70,28 +134,20 @@ test_load(struct sht* sht) CHK(sht_isotope_metadata_get_molecule(metadata, 2, &molecule) == RES_BAD_ARG); CHK(sht_isotope_metadata_get_molecule(metadata, 0, &molecule) == RES_OK); - CHK(!strcmp(molecule.name, "H2O")); - CHK(molecule.id == 1); - CHK(molecule.nisotopes == 7); + CHK(molecule_eq(&molecule, &H2O)); CHK(sht_isotope_metadata_get_molecule(metadata, 1, &molecule) == RES_OK); - CHK(!strcmp(molecule.name, "CO2")); - CHK(molecule.id == 2); - CHK(molecule.nisotopes == 12); + CHK(molecule_eq(&molecule, &CO2)); CHK(sht_isotope_metadata_find_molecule(NULL, 1, &molecule) == RES_BAD_ARG); CHK(sht_isotope_metadata_find_molecule(metadata, 1, NULL) == RES_BAD_ARG); CHK(sht_isotope_metadata_find_molecule(metadata, 1, &molecule) == RES_OK); CHK(!SHT_MOLECULE_IS_NULL(&molecule)); - CHK(!strcmp(molecule.name, "H2O")); - CHK(molecule.id == 1); - CHK(molecule.nisotopes == 7); + CHK(molecule_eq(&molecule, &H2O)); CHK(sht_isotope_metadata_find_molecule(metadata, 2, &molecule) == RES_OK); CHK(!SHT_MOLECULE_IS_NULL(&molecule)); - CHK(!strcmp(molecule.name, "CO2")); - CHK(molecule.id == 2); - CHK(molecule.nisotopes == 12); + CHK(molecule_eq(&molecule, &CO2)); CHK(sht_isotope_metadata_find_molecule(metadata, 0, &molecule) == RES_OK); CHK(SHT_MOLECULE_IS_NULL(&molecule));