htgop

Optical properties of a gas mixture
git clone git://git.meso-star.fr/htgop.git
Log | Files | Refs | README | LICENSE

test_htgop_check_specints.h (3366B)


      1 /* Copyright (C) 2018-2021, 2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "htgop.h"
     17 
     18 #if !defined(DOMAIN)
     19   #error "Missing the <DATA|DOMAIN> macro."
     20 #endif
     21 
     22 /* Helper macros */
     23 #define GET_SPECINTS                                                           \
     24   CONCAT(CONCAT(htgop_get_, DOMAIN), _spectral_intervals)
     25 #define GET_NSPECINTS                                                          \
     26   CONCAT(CONCAT(htgop_get_, DOMAIN), _spectral_intervals_count)
     27 #define GET_SPECINT                                                            \
     28   CONCAT(CONCAT(htgop_get_, DOMAIN), _spectral_interval)
     29 
     30 static void
     31 CONCAT(CONCAT(check_, DOMAIN), _specints)
     32   (const struct htgop* htgop,
     33    const double low, /* In wavenumber */
     34    const double upp) /* In wavenumber */
     35 {
     36   struct htgop_spectral_interval specint_low;
     37   struct htgop_spectral_interval specint_upp;
     38   double wnums[2];
     39   size_t range[2];
     40   size_t range2[2];
     41   size_t i;
     42   size_t nspecints;
     43 
     44   CHK(low <= upp);
     45 
     46   wnums[0] = low;
     47   wnums[1] = upp;
     48   CHK(GET_SPECINTS(NULL, wnums, range) == RES_BAD_ARG);
     49   CHK(GET_SPECINTS(htgop, NULL, range) == RES_BAD_ARG);
     50   CHK(GET_SPECINTS(htgop, wnums, NULL) == RES_BAD_ARG);
     51   CHK(GET_SPECINTS(htgop, wnums, range) == RES_OK);
     52   CHK(range[0] <= range[1]);
     53 
     54   if(upp != low) {
     55     wnums[0] = upp;
     56     wnums[1] = low;
     57     CHK(GET_SPECINTS(htgop, wnums, range) == RES_BAD_ARG);
     58   }
     59   wnums[0] = low;
     60   wnums[1] = upp;
     61   CHK(GET_SPECINTS(htgop, wnums, range) == RES_OK);
     62 
     63   CHK(GET_SPECINT(htgop, range[0], &specint_low) == RES_OK);
     64   CHK(GET_SPECINT(htgop, range[1], &specint_upp) == RES_OK);
     65   CHK(GET_NSPECINTS(htgop, &nspecints) == RES_OK);
     66 
     67   CHK(specint_low.wave_numbers[0] < specint_upp.wave_numbers[1]);
     68   CHK(specint_low.wave_numbers[0] <= wnums[0] || range[0] == 0);
     69   CHK(specint_upp.wave_numbers[1] >= wnums[1] || range[1] == nspecints-1);
     70 
     71   range2[0] = SIZE_MAX;
     72   range2[1] = SIZE_MAX;
     73   FOR_EACH(i, 0, nspecints) {
     74     struct htgop_spectral_interval specint;
     75     CHK(GET_SPECINT(htgop, i, &specint) == RES_OK);
     76 
     77     if(specint.wave_numbers[0]<=wnums[0] && specint.wave_numbers[1]>wnums[0]) {
     78       range2[0] = i;
     79     }
     80     if(specint.wave_numbers[0]<wnums[1] && specint.wave_numbers[1]>=wnums[1]) {
     81       range2[1] = i;
     82     }
     83   }
     84 
     85   CHK(range2[0] <= range2[1]);
     86 
     87   if(range2[0] == SIZE_MAX) {
     88     /* The loaded data does not strictly include the submitted range */
     89     CHK(range[0] == 0);
     90   } else {
     91     CHK(range2[0] == range[0]);
     92   }
     93 
     94   if(range2[1] == SIZE_MAX) {
     95    /* The loaded data does not strictly include the submitted range */
     96     CHK(range[1] == nspecints-1);
     97   } else {
     98     CHK(range2[1] == range[1]);
     99   }
    100 }
    101 
    102 #undef GET_SPECINT
    103 #undef GET_SPECINTS
    104 #undef GET_NSPECINTS
    105 #undef DOMAIN
    106