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

Return an error if an id is used for 2 molecules/isotopes

Diffstat:
Msrc/sht_isotope_metadata.c | 26+++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/sht_isotope_metadata.c b/src/sht_isotope_metadata.c @@ -222,6 +222,7 @@ flush_molecule struct txtrdr* txtrdr) { size_t ientry = SIZE_MAX; + size_t* pimolecule = NULL; res_T res = RES_OK; ASSERT(metadata && molecule && MOLECULE_IS_VALID(molecule)); @@ -247,7 +248,20 @@ flush_molecule } /* Register the molecule */ - ASSERT(!htable_id2entry_find(&metadata->molid2idx, &molecule->id)); + pimolecule = htable_id2entry_find(&metadata->molid2idx, &molecule->id); + if(pimolecule) { + const struct molecule* molecule2 = NULL; + molecule2 = darray_molecule_cdata_get(&metadata->molecules) + *pimolecule; + log_err(metadata->sht, + "%s: cannot register the %s molecule. " + "The %s molecule has the same identifier %i.\n", + txtrdr_get_name(txtrdr), + str_cget(&molecule->name), + str_cget(&molecule2->name), + molecule->id); + res = RES_OK; + goto error; + } res = htable_id2entry_set(&metadata->molid2idx, &molecule->id, &ientry); if(res != RES_OK) { log_err(metadata->sht, @@ -336,7 +350,7 @@ parse_isotope (struct sht_isotope_metadata* metadata, struct txtrdr* txtrdr) { - struct isotope isotope = ISOTOPOLOGUE_NULL; + struct sht_isotope isotope = SHT_ISOTOPOLOGUE_NULL; struct param_desc param_desc = PARAM_DESC_NULL; struct sht* sht = NULL; char* tk = NULL; @@ -416,7 +430,13 @@ parse_isotope } /* Register the isotope */ - ASSERT(!htable_id2entry_find(&metadata->isoid2idx, &isotope.id)); + if(htable_id2entry_find(&metadata->isoid2idx, &isotope.id)) { + log_warn(sht, + "%s:%lu: an isotope with the same identifier %i was already registered.\n", + path, (unsigned long)line_num, isotope.id); + res = RES_OK; + goto error; + } res = htable_id2entry_set(&metadata->isoid2idx, &isotope.id, &ientry); if(res != RES_OK) { log_err(sht, "%s:%lu: error registering the isotopoe %d -- %s.\n",