htgop_spectral_intervals.h (2814B)
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_SPECTRAL_INTERVALS_H 17 #define HTGOP_SPECTRAL_INTERVALS_H 18 19 #include "htgop_dbllst.h" 20 21 struct spectral_intervals { 22 /* List of wave numbers, in cm^-1, sorted in ascending order. 23 * #wave numbers == #intervals + 1 */ 24 struct darray_double wave_numbers; 25 struct darray_dbllst quadrature_pdfs; /* Per spectral band quadrature pdf */ 26 struct darray_dbllst quadrature_cdfs; /* Per spectral band quadrature cdf */ 27 }; 28 29 static INLINE void 30 spectral_intervals_init 31 (struct mem_allocator* allocator, struct spectral_intervals* sinters) 32 { 33 ASSERT(sinters); 34 darray_double_init(allocator, &sinters->wave_numbers); 35 darray_dbllst_init(allocator, &sinters->quadrature_pdfs); 36 darray_dbllst_init(allocator, &sinters->quadrature_cdfs); 37 38 } 39 40 static INLINE void 41 spectral_intervals_release(struct spectral_intervals* sinters) 42 { 43 ASSERT(sinters); 44 darray_double_release(&sinters->wave_numbers); 45 darray_dbllst_release(&sinters->quadrature_pdfs); 46 darray_dbllst_release(&sinters->quadrature_cdfs); 47 } 48 49 static INLINE res_T 50 spectral_intervals_copy 51 (struct spectral_intervals* dst, const struct spectral_intervals* src) 52 { 53 res_T res = RES_OK; 54 ASSERT(dst && src); 55 #define CALL(Func) { if(RES_OK != (res = Func)) return res; } (void)0 56 CALL(darray_double_copy(&dst->wave_numbers, &src->wave_numbers)); 57 CALL(darray_dbllst_copy(&dst->quadrature_pdfs, &src->quadrature_pdfs)); 58 CALL(darray_dbllst_copy(&dst->quadrature_cdfs, &src->quadrature_cdfs)); 59 #undef CALL 60 return RES_OK; 61 } 62 63 static INLINE res_T 64 spectral_intervals_copy_and_release 65 (struct spectral_intervals* dst, struct spectral_intervals* src) 66 { 67 res_T res = RES_OK; 68 ASSERT(dst && src); 69 #define CALL(Func) { if(RES_OK != (res = Func)) return res; } (void)0 70 CALL(darray_double_copy_and_release(&dst->wave_numbers, &src->wave_numbers)); 71 CALL(darray_dbllst_copy_and_release(&dst->quadrature_pdfs, &src->quadrature_pdfs)); 72 CALL(darray_dbllst_copy_and_release(&dst->quadrature_pdfs, &src->quadrature_cdfs)); 73 #undef CALL 74 spectral_intervals_release(src); 75 return RES_OK; 76 } 77 78 #endif /* HTGOP_SPECTRAL_INTERVALS_H */ 79