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 3603459c3b9bf97edfb9805b189f568b696f4326
parent 1927228d69dbdc4165ddf1b0d7c14379946f85f8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 28 Jan 2026 17:26:35 +0100

Test the mapping from molecule id to their names

Diffstat:
MMakefile | 4+++-
Asrc/test_shtr_molecule_id.c | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -159,7 +159,8 @@ lint: TEST_SRC = \ src/test_shtr.c \ src/test_shtr_isotope_metadata.c \ - src/test_shtr_lines.c + src/test_shtr_lines.c \ + src/test_shtr_molecule_id.c TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) TEST_TGT = $(TEST_SRC:.c=.t) @@ -192,6 +193,7 @@ $(TEST_OBJ): config.mk shtr-local.pc test_shtr \ test_shtr_isotope_metadata \ test_shtr_lines \ +test_shtr_molecule_id \ : config.mk shtr-local.pc $(LIBNAME) $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) diff --git a/src/test_shtr_molecule_id.c b/src/test_shtr_molecule_id.c @@ -0,0 +1,100 @@ +/* Copyright (C) 2022, 2025, 2026 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2025, 2026 Université de Lorraine + * Copyright (C) 2022 Centre National de la Recherche Scientifique + * Copyright (C) 2022 Université Paul Sabatier + * + * 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 "shtr.h" +#include <string.h> + +static const char* +id2cstr(const enum shtr_molecule_id id) +{ + const char* cstr = NULL; + switch(id) { + case SHTR_H2O: cstr = "H2O"; break; + case SHTR_CO2: cstr = "CO2"; break; + case SHTR_O3: cstr = "O3"; break; + case SHTR_N2O: cstr = "N2O"; break; + case SHTR_CO: cstr = "CO"; break; + case SHTR_CH4: cstr = "CH4"; break; + case SHTR_O2: cstr = "O2"; break; + case SHTR_NO: cstr = "NO"; break; + case SHTR_SO2: cstr = "SO2"; break; + case SHTR_NO2: cstr = "NO2"; break; + case SHTR_NH3: cstr = "NH3"; break; + case SHTR_HNO3: cstr = "HNO3"; break; + case SHTR_OH: cstr = "OH"; break; + case SHTR_HF: cstr = "HF"; break; + case SHTR_HCl: cstr = "HCl"; break; + case SHTR_HBr: cstr = "HBr"; break; + case SHTR_HI: cstr = "HI"; break; + case SHTR_ClO: cstr = "ClO"; break; + case SHTR_OCS: cstr = "OCS"; break; + case SHTR_H2CO: cstr = "H2CO"; break; + case SHTR_HOCl: cstr = "HOCl"; break; + case SHTR_N2: cstr = "N2"; break; + case SHTR_HCN: cstr = "HCN"; break; + case SHTR_CH3Cl: cstr = "CH3Cl"; break; + case SHTR_H2O2: cstr = "H2O2"; break; + case SHTR_C2H2: cstr = "C2H2"; break; + case SHTR_C2H6: cstr = "C2H6"; break; + case SHTR_PH3: cstr = "PH3"; break; + case SHTR_COF2: cstr = "COF2"; break; + case SHTR_SF6: cstr = "SF6"; break; + case SHTR_H2S: cstr = "H2S"; break; + case SHTR_HCOOH: cstr = "HCOOH"; break; + case SHTR_HO2: cstr = "HO2"; break; + case SHTR_O: cstr = "O"; break; + case SHTR_ClONO2: cstr = "ClONO2"; break; + case SHTR_NOplus: cstr = "NO+"; break; + case SHTR_HOBr: cstr = "HOBr"; break; + case SHTR_C2H4: cstr = "C2H4"; break; + case SHTR_CH3OH: cstr = "CH3OH"; break; + case SHTR_CH3Br: cstr = "CH3Br"; break; + case SHTR_CH3CN: cstr = "CH3CN"; break; + case SHTR_CF4: cstr = "CF4"; break; + case SHTR_C4H2: cstr = "C4H2"; break; + case SHTR_HC3N: cstr = "HC3N"; break; + case SHTR_H2: cstr = "H2"; break; + case SHTR_CS: cstr = "CS"; break; + case SHTR_SO3: cstr = "SO3"; break; + case SHTR_C2N2: cstr = "C2N2"; break; + case SHTR_COCl2: cstr = "COCl2"; break; + case SHTR_SO: cstr = "SO"; break; + case SHTR_CH3F: cstr = "CH3F"; break; + case SHTR_GeH4: cstr = "GeH4"; break; + case SHTR_CS2: cstr = "CS2"; break; + case SHTR_CH3I: cstr = "CH3I"; break; + case SHTR_NF3: cstr = "NF3"; break; + default: FATAL("Unreachable code\n"); break; + } + return cstr; +} + +int +main(void) +{ + int i = 0; + + CHK(SHTR_MOLECULE_ID_NULL == 0); + + FOR_EACH(i, 1, SHTR_MAX_MOLECULE_COUNT) { + const char* cstr0 = shtr_molecule_cstr(i); + const char* cstr1 = id2cstr(i); + CHK(!strcmp(cstr0, cstr1)); + } + return 0; +}