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 b81cfcaf33b69766ac03cd2ed856866c0de758ec
parent abd9fbb943622d7083dd7aec105c91cf032580a1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 27 Apr 2022 09:00:25 +0200

Add and test the shtr_line_eq function

Diffstat:
Msrc/shtr.h | 15+++++++++++++++
Msrc/test_shtr_lines.c | 64++++++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/src/shtr.h b/src/shtr.h @@ -93,6 +93,21 @@ struct shtr_line { #define SHTR_LINE_NULL__ {0,0,0,0,0,0,0,-1,-1} static const struct shtr_line SHTR_LINE_NULL = SHTR_LINE_NULL__; +static INLINE int +shtr_line_eq(const struct shtr_line* line0, const struct shtr_line* line1) +{ + ASSERT(line0 && line1); + return line0->wavenumber == line1->wavenumber + && line0->intensity == line1->intensity + && line0->gamma_air == line1->gamma_air + && line0->gamma_self == line1->gamma_self + && line0->lower_state_energy == line1->lower_state_energy + && line0->n_air == line1->n_air + && line0->delta_air == line1->delta_air + && line0->molecule_id == line1->molecule_id + && line0->isotope_id_local == line1->isotope_id_local; +} + /* Forward declarations of opaque data structures */ struct shtr; struct shtr_isotope_metadata; diff --git a/src/test_shtr_lines.c b/src/test_shtr_lines.c @@ -16,12 +16,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _POSIX_C_SOURCE 200112L + #include "shtr.h" #include <rsys/clock_time.h> #include <rsys/mem_allocator.h> #include <rsys/math.h> +#include <math.h> #include <string.h> static void @@ -59,21 +62,45 @@ print_lines } } -static int -line_eq - (const struct shtr_line* l0, - const struct shtr_line* l1) +static void +test_line_eq(void) { - CHK(l0 && l1); - return l0->wavenumber == l1->wavenumber - && l0->intensity == l1->intensity - && l0->gamma_air == l1->gamma_air - && l0->gamma_self == l1->gamma_self - && l0->lower_state_energy == l1->lower_state_energy - && l0->n_air == l1->n_air - && l0->delta_air == l1->delta_air - && l0->molecule_id == l1->molecule_id - && l0->isotope_id_local == l1->isotope_id_local; + const struct shtr_line l0 = { + 0.000134, 2.672E-38, 0.0533, 0.410, 608.4727, 0.79, 0.000060, 1, 4 + }; + struct shtr_line l1 = l0; + + CHK(shtr_line_eq(&l0, &l1)); + + l1.wavenumber = nextafter(l1.wavenumber, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.wavenumber = l0.wavenumber; + l1.intensity = nextafter(l1.intensity, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.intensity = l0.intensity; + l1.gamma_air = nextafter(l1.gamma_air, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.gamma_air = l0.gamma_air; + l1.gamma_self = nextafter(l1.gamma_self, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.gamma_self = l0.gamma_self; + l1.lower_state_energy = nextafter(l1.lower_state_energy, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.lower_state_energy = l0.lower_state_energy; + l1.n_air = nextafter(l1.n_air, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.n_air = l0.n_air; + l1.delta_air = nextafter(l1.delta_air, INF); + CHK(!shtr_line_eq(&l0, &l1)); + l1.delta_air = l0.delta_air; + l1.molecule_id += 1; + CHK(!shtr_line_eq(&l0, &l1)); + l1.molecule_id = l0.molecule_id; + l1.isotope_id_local += 1; + CHK(!shtr_line_eq(&l0, &l1)); + l1.isotope_id_local = l0.isotope_id_local; + + CHK(shtr_line_eq(&l0, &l1)); } static void @@ -111,7 +138,7 @@ test_load(struct shtr* shtr) CHK(shtr_lines_list_get(NULL, &lines) == RES_BAD_ARG); CHK(shtr_lines_list_get(list, NULL) == RES_BAD_ARG); CHK(shtr_lines_list_get(list, &lines) == RES_OK); - FOR_EACH(i, 0, n) CHK(line_eq(lines+i, l+i)); + FOR_EACH(i, 0, n) CHK(shtr_line_eq(lines+i, l+i)); CHK(shtr_lines_list_ref_get(NULL) == RES_BAD_ARG); CHK(shtr_lines_list_ref_get(list) == RES_OK); @@ -130,7 +157,7 @@ test_load(struct shtr* shtr) CHK(n == nlines); CHK(shtr_lines_list_get(list, &lines) == RES_OK); - FOR_EACH(i, 0, n) CHK(line_eq(lines+i, l+i)); + FOR_EACH(i, 0, n) CHK(shtr_line_eq(lines+i, l+i)); CHK(shtr_lines_list_ref_put(list) == RES_OK); } @@ -250,7 +277,7 @@ check_view } CHK(shtr_lines_view_get_line(view, nlines_selected, &line) == RES_OK); - CHK(line_eq(line, lines+i)); + CHK(shtr_line_eq(line, lines+i)); nlines_selected += 1; } @@ -364,7 +391,7 @@ test_view(struct shtr* shtr) FOR_EACH(i, 0, n) { CHK(shtr_lines_view_get_line(view, i, &line) == RES_OK); - CHK(line_eq(line, l+i)); + CHK(shtr_line_eq(line, l+i)); } CHK(shtr_lines_view_ref_get(NULL) == RES_BAD_ARG); @@ -525,6 +552,7 @@ main(int argc, char** argv) args.verbose = 1; CHK(shtr_create(&args, &shtr) == RES_OK); + test_line_eq(); test_load(shtr); test_load_failures(shtr); test_view(shtr);