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 9c25a62b22d91ea4d897d8b2327df0827cae3d47
parent a9446f04fcf7628fc1cf97e49d03d56316e1bf5f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 10 Feb 2022 10:54:15 +0100

Handle that the isotope identifier is not unique

Do not check the uniqueness of the identifier and delete the function
that was looking for an isotope with its identifier.

Diffstat:
Msrc/shitran.h | 9+--------
Msrc/shitran_isotope_metadata.c | 79+++++++++++++++----------------------------------------------------------------
Msrc/test_shitran_isotope_metadata.c | 29-----------------------------
3 files changed, 16 insertions(+), 101 deletions(-)

diff --git a/src/shitran.h b/src/shitran.h @@ -54,7 +54,7 @@ struct shitran_isotope { double molar_mass; /* In g */ size_t imolecule; /* Index of the molecule to which the isotope belongs */ int gj; /* State independent degeneracy factor */ - int id; /* Unique identifier of the isotope */ + int id; /* Identifier of the isotope */ }; #define SHITRAN_ISOTOPE_NULL__ {0,0,0,0,0,-1} static const struct shitran_isotope SHITRAN_ISOTOPE_NULL = @@ -140,13 +140,6 @@ shitran_isotope_metadata_find_molecule const int molecule_id, /* Unique identifier of the molecule */ struct shitran_molecule* molecule); -/* `isotope' is set to SHITRAN_ISOTOPE_NULL if `isotope_id' is not found */ -SHITRAN_API res_T -shitran_isotope_metadata_find_isotope - (struct shitran_isotope_metadata* metadata, - const int isotope_id, /* Unique identifier of the isotope */ - struct shitran_isotope* isotope); - END_DECLS #endif /* SHITRAN_H */ diff --git a/src/shitran_isotope_metadata.c b/src/shitran_isotope_metadata.c @@ -109,8 +109,8 @@ molecule_copy_and_release(struct molecule* dst, struct molecule* src) #define DARRAY_FUNCTOR_COPY_AND_RELEASE molecule_copy_and_release #include <rsys/dynamic_array.h> -/* Generate the hash table that map a unique identifier to its index */ -#define HTABLE_NAME id2entry +/* Generate the hash table that map a global identifier to its local index */ +#define HTABLE_NAME molid2idx #define HTABLE_KEY int /* Unique identifier */ #define HTABLE_DATA size_t /* Index of the corresponding registered data */ #include <rsys/hash_table.h> @@ -120,10 +120,9 @@ struct shitran_isotope_metadata { struct darray_molecule molecules; struct darray_isotope isotopes; - /* Map the identifier of a molecule/isotope to its correspond index into - * their corresponding dynamic arays into which they are registered */ - struct htable_id2entry molid2idx; - struct htable_id2entry isoid2idx; + /* Map the global identifier of a molecule to its correspond local index into + * the dynamic aray into which it is registered */ + struct htable_molid2idx molid2idx; struct shitran* shitran; ref_T ref; @@ -205,8 +204,7 @@ create_isotoplogues metadata->shitran = shitran; darray_molecule_init(shitran->allocator, &metadata->molecules); darray_isotope_init(shitran->allocator, &metadata->isotopes); - htable_id2entry_init(shitran->allocator, &metadata->molid2idx); - htable_id2entry_init(shitran->allocator, &metadata->isoid2idx); + htable_molid2idx_init(shitran->allocator, &metadata->molid2idx); exit: *out_isotopes = metadata; @@ -249,7 +247,7 @@ flush_molecule } /* Register the molecule */ - pimolecule = htable_id2entry_find(&metadata->molid2idx, &molecule->id); + pimolecule = htable_molid2idx_find(&metadata->molid2idx, &molecule->id); if(pimolecule) { const struct molecule* molecule2 = NULL; molecule2 = darray_molecule_cdata_get(&metadata->molecules) + *pimolecule; @@ -263,7 +261,7 @@ flush_molecule res = RES_OK; goto error; } - res = htable_id2entry_set(&metadata->molid2idx, &molecule->id, &ientry); + res = htable_molid2idx_set(&metadata->molid2idx, &molecule->id, &ientry); if(res != RES_OK) { log_err(metadata->shitran, "%s: error registering the %s molecule -- %s.\n", @@ -277,7 +275,7 @@ exit: return res; error: if(ientry != SIZE_MAX) darray_molecule_resize(&metadata->molecules, ientry); - htable_id2entry_erase(&metadata->molid2idx, &molecule->id); + htable_molid2idx_erase(&metadata->molid2idx, &molecule->id); goto exit; } @@ -359,7 +357,7 @@ parse_isotope char* tk_ctx = NULL; const char* path = NULL; size_t line_num = 0; - size_t ientry = SIZE_MAX; + size_t local_id = SIZE_MAX; res_T res = RES_OK; ASSERT(metadata && txtrdr); @@ -390,7 +388,7 @@ parse_isotope if(res != RES_OK) goto error; tk = strtok_r(NULL, " \t", &tk_ctx); - param_desc.name = "isotope Q(256K)"; + param_desc.name = "isotope Q(296K)"; param_desc.low = 0; param_desc.upp = INF; param_desc.is_low_incl = 0; @@ -419,8 +417,7 @@ parse_isotope (shitran, tk, path, line_num, &param_desc, &isotope.molar_mass); if(res != RES_OK) goto error; - /* Fetch the index where the isotope is going to be store */ - ientry = darray_isotope_size_get(&metadata->isotopes); + local_id = darray_isotope_size_get(&metadata->isotopes); /* Store the isotope */ res = darray_isotope_push_back(&metadata->isotopes, &isotope); @@ -431,27 +428,10 @@ parse_isotope goto error; } - /* Register the isotope */ - if(htable_id2entry_find(&metadata->isoid2idx, &isotope.id)) { - log_warn(shitran, - "%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(shitran, "%s:%lu: error registering the isotopoe %d -- %s.\n", - path, (unsigned long)line_num, isotope.id, res_to_cstr(res)); - res = RES_OK; - goto error; - } - exit: return res; error: - if(ientry != SIZE_MAX) darray_isotope_resize(&metadata->isotopes, ientry); - htable_id2entry_erase(&metadata->isoid2idx, &isotope.id); + if(local_id != SIZE_MAX) darray_isotope_resize(&metadata->isotopes, local_id); goto exit; } @@ -571,8 +551,7 @@ release_isotope_metadata(ref_T* ref) shitran = metadata->shitran; darray_molecule_release(&metadata->molecules); darray_isotope_release(&metadata->isotopes); - htable_id2entry_release(&metadata->molid2idx); - htable_id2entry_release(&metadata->isoid2idx); + htable_molid2idx_release(&metadata->molid2idx); MEM_RM(shitran->allocator, metadata); SHITRAN(ref_put(shitran)); } @@ -700,7 +679,7 @@ shitran_isotope_metadata_find_molecule goto error; } - pimolecule = htable_id2entry_find(&metadata->molid2idx, &molecule_id); + pimolecule = htable_molid2idx_find(&metadata->molid2idx, &molecule_id); if(!pimolecule) { *out_molecule = SHITRAN_MOLECULE_NULL; } else { @@ -715,31 +694,3 @@ error: goto exit; } -res_T -shitran_isotope_metadata_find_isotope - (struct shitran_isotope_metadata* metadata, - const int isotope_id, /* Unique identifier of the isotope */ - struct shitran_isotope* out_isotope) -{ - size_t* piisotope = NULL; - res_T res = RES_OK; - - if(!metadata || !out_isotope) { - res = RES_BAD_ARG; - goto error; - } - - piisotope = htable_id2entry_find(&metadata->isoid2idx, &isotope_id); - if(!piisotope) { - *out_isotope = SHITRAN_ISOTOPE_NULL; - } else { - ASSERT(*piisotope < darray_isotope_size_get(&metadata->isotopes)); - *out_isotope = darray_isotope_cdata_get(&metadata->isotopes)[*piisotope]; - } - -exit: - return res; -error: - goto exit; -} - diff --git a/src/test_shitran_isotope_metadata.c b/src/test_shitran_isotope_metadata.c @@ -111,31 +111,10 @@ molecule_eq(const struct shitran_molecule* m0, const struct shitran_molecule* m1 return 1; } -static void -check_molecule_isotopes - (struct shitran_isotope_metadata* mdata, - const struct shitran_molecule* molecule) -{ - struct shitran_isotope isotope = SHITRAN_ISOTOPE_NULL; - struct shitran_molecule molecule2 = SHITRAN_MOLECULE_NULL; - size_t i; - CHK(mdata && molecule); - - FOR_EACH(i, 0, H2O.nisotopes) { - CHK(shitran_isotope_metadata_find_isotope - (mdata, molecule->isotopes[i].id, &isotope) == RES_OK); - CHK(!SHITRAN_ISOTOPE_IS_NULL(&isotope)); - CHK(isotope_eq(&isotope, &molecule->isotopes[i])); - CHK(shitran_isotope_metadata_get_molecule - (mdata, isotope.imolecule, &molecule2) == RES_OK); - CHK(molecule_eq(molecule, &molecule2)); - } -} static void test_load(struct shitran* shitran) { - struct shitran_isotope isotope = SHITRAN_ISOTOPE_NULL; struct shitran_molecule molecule = SHITRAN_MOLECULE_NULL; const char* filename = "test_isotope_metadata.txt"; struct shitran_isotope_metadata* mdata = NULL; @@ -181,14 +160,6 @@ test_load(struct shitran* shitran) CHK(shitran_isotope_metadata_find_molecule(mdata, 0, &molecule) == RES_OK); CHK(SHITRAN_MOLECULE_IS_NULL(&molecule)); - CHK(shitran_isotope_metadata_find_isotope(NULL, 161, &isotope) == RES_BAD_ARG); - CHK(shitran_isotope_metadata_find_isotope(mdata, 161, NULL) == RES_BAD_ARG); - CHK(shitran_isotope_metadata_find_isotope(mdata, 0, &isotope) == RES_OK); - CHK(SHITRAN_ISOTOPE_IS_NULL(&isotope)); - - check_molecule_isotopes(mdata, &H2O); - check_molecule_isotopes(mdata, &CO2); - CHK(shitran_isotope_metadata_ref_get(NULL) == RES_BAD_ARG); CHK(shitran_isotope_metadata_ref_get(mdata) == RES_OK); CHK(shitran_isotope_metadata_ref_put(NULL) == RES_BAD_ARG);