htgop

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

htgop_c.h (3606B)


      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 #ifndef HTGOP_C_H
     17 #define HTGOP_C_H
     18 
     19 #include "htgop_layer.h"
     20 #include "htgop_spectral_intervals.h"
     21 
     22 #include <rsys/dynamic_array.h>
     23 #include <rsys/ref_count.h>
     24 
     25 /* Helper macros to convert from wave number to wavelength and vice versa */
     26 #define WNUM_TO_WLEN(Num) (1.0e7 / ((double)(Num)))
     27 #define WLEN_TO_WNUM(Len) WNUM_TO_WLEN(Len)
     28 
     29 /* Generate the dynamic array of level */
     30 #define DARRAY_NAME level
     31 #define DARRAY_DATA struct htgop_level
     32 #include <rsys/dynamic_array.h>
     33 
     34 struct htgop {
     35   struct htgop_ground ground;
     36 
     37   /* Description of the spectral intervals for the short/long wave domain */
     38   struct spectral_intervals lw_specints;
     39   struct spectral_intervals sw_specints;
     40 
     41   /* Cumulative distribution function for the Short Wave CIE XYZ values */
     42   struct darray_double sw_X_cdf;
     43   struct darray_double sw_Y_cdf;
     44   struct darray_double sw_Z_cdf;
     45 
     46   struct darray_layer layers; /* Par layer data */
     47   struct darray_level levels; /* Per level data (#level = #layer + 1 ) */
     48 
     49   int verbose; /* Verbosity level */
     50   struct logger* logger;
     51   struct mem_allocator* allocator;
     52   ref_T ref;
     53 };
     54 
     55 static INLINE int
     56 cmp_dbl(const void* a, const void* b)
     57 {
     58   const double d0 = *((const double*)a);
     59   const double d1 = *((const double*)b);
     60   return d0 < d1 ? -1 : (d0 > d1 ? 1 : 0);
     61 }
     62 
     63 extern LOCAL_SYM void
     64 log_err
     65   (const struct htgop* htgop,
     66    const char* fmt,
     67   ...)
     68 #ifdef COMPILER_GCC
     69   __attribute((format(printf, 2, 3)))
     70 #endif
     71   ;
     72 
     73 extern LOCAL_SYM void
     74 log_warn
     75   (const struct htgop* htgop,
     76    const char* fmt,
     77   ...)
     78 #ifdef COMPILER_GCC
     79   __attribute((format(printf, 2, 3)))
     80 #endif
     81   ;
     82 
     83 extern LOCAL_SYM double
     84 layer_lw_spectral_interval_tab_interpolate_ka
     85   (const struct htgop_layer_lw_spectral_interval_tab* tab,
     86    const double x_h2o,
     87    const double* x_h2o_upp); /* Pointer toward the 1st tabbed xH2O >= x_h2o */
     88 
     89 extern LOCAL_SYM double
     90 layer_sw_spectral_interval_tab_interpolate_ka
     91   (const struct htgop_layer_sw_spectral_interval_tab* tab,
     92    const double x_h2o,
     93    const double* x_h2o_upp); /* Pointer toward the 1st tabbed xH2O >= x_h2o */
     94 
     95 extern LOCAL_SYM double
     96 layer_sw_spectral_interval_tab_interpolate_ks
     97   (const struct htgop_layer_sw_spectral_interval_tab* tab,
     98    const double x_h2o,
     99    const double* x_h2o_upp); /* Pointer toward the 1st tabbed xH2O >= x_h2o */
    100 
    101 extern LOCAL_SYM double
    102 layer_sw_spectral_interval_tab_interpolate_kext
    103   (const struct htgop_layer_sw_spectral_interval_tab* tab,
    104    const double x_h2o,
    105    const double* x_h2o_upp); /* Pointer toward the 1st tabbed xH2O >= x_h2o */
    106 
    107 /* Return the *inclusive* lower/upper index of the spectral intervals that
    108  * overlaps the submitted wave number range */
    109 extern LOCAL_SYM res_T
    110 get_spectral_intervals
    111   (const struct htgop* htgop,
    112    const char* func_name,
    113    const double wnum_range[2],
    114    const double* wnums,
    115    const size_t nwnums,
    116    size_t specint_range[2]);
    117 
    118 #endif /* HTGOP_C_H */
    119