htgop_parse_layers_spectral_intervals_data.h (4020B)
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_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H 17 #define HTGOP_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H 18 19 #include "htgop_c.h" 20 #include "htgop_reader.h" 21 22 #endif /* HTGOP_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H */ 23 24 /* 25 * Generate the function that parses a per layer and per spectral interval data 26 * for a given domain. 27 */ 28 29 #if !defined(DATA) || !defined(DOMAIN) 30 #error "Missing the <DATA|DOMAIN> macro." 31 #endif 32 33 #define XDOMAIN(Name) CONCAT(CONCAT(DOMAIN, _), Name) 34 #define XDATA(Name) CONCAT(CONCAT(DATA, _), Name) 35 36 static res_T 37 CONCAT(CONCAT(CONCAT(parse_layers_spectral_intervals_, DATA), _), DOMAIN) 38 (struct htgop* htgop, struct reader* rdr) 39 { 40 struct layer* layers = NULL; 41 size_t nspecints, nlays, tab_len, quad_len; 42 size_t ispecint, ilay, itab, iquad; 43 res_T res = RES_OK; 44 ASSERT(htgop && rdr); 45 46 layers = darray_layer_data_get(&htgop->layers); 47 nlays = darray_layer_size_get(&htgop->layers); 48 ASSERT(nlays > 0); 49 50 tab_len = darray_double_size_get(&layers[0].x_h2o_tab); 51 ASSERT(tab_len > 0); 52 53 nspecints = darray_double_size_get(&htgop->XDOMAIN(specints).wave_numbers)-1; 54 ASSERT(nspecints > 0); 55 56 #define CALL(Func) { if((res = Func) != RES_OK) goto error; } (void)0 57 FOR_EACH(ispecint, 0, nspecints) { 58 struct CONCAT(layer_, XDOMAIN(spectral_interval))* layspecint; 59 struct darray_double* quad; /* Quadrature of the current interval */ 60 double* XDATA(nominal); 61 struct darray_double* XDATA(tab); 62 63 quad = darray_dbllst_data_get 64 (&htgop->XDOMAIN(specints).quadrature_pdfs) + ispecint; 65 quad_len = darray_double_size_get(quad); 66 67 /* Allocate the per layer data */ 68 FOR_EACH(ilay, 0, nlays) { 69 layspecint = CONCAT(CONCAT(darray_lay_, XDOMAIN(specint)), _data_get) 70 (&layers[ilay].XDOMAIN(specints)) + ispecint; 71 CALL(darray_double_resize(&layspecint->XDATA(nominal), quad_len)); 72 CALL(darray_dbllst_resize(&layspecint->XDATA(tab), quad_len)); 73 FOR_EACH(iquad, 0, quad_len) { /* Tabulated data */ 74 XDATA(tab) = darray_dbllst_data_get(&layspecint->XDATA(tab)) + iquad; 75 CALL(darray_double_resize(XDATA(tab), tab_len)); 76 } 77 } 78 79 FOR_EACH(iquad, 0, quad_len) { 80 /* Read per layer nominal data */ 81 FOR_EACH(ilay, 0, nlays) { 82 layspecint = CONCAT(CONCAT(darray_lay_, XDOMAIN(specint)), _data_get) 83 (&layers[ilay].XDOMAIN(specints)) + ispecint; 84 XDATA(nominal) = darray_double_data_get(&layspecint->XDATA(nominal)); 85 CALL(cstr_to_double(read_line(rdr), &XDATA(nominal)[iquad])); 86 } 87 88 /* Read per layer tabulated data */ 89 FOR_EACH(itab, 0, tab_len) { 90 FOR_EACH(ilay, 0, nlays) { 91 layspecint = CONCAT(CONCAT(darray_lay_, XDOMAIN(specint)), _data_get) 92 (&layers[ilay].XDOMAIN(specints)) + ispecint; 93 XDATA(tab) = darray_dbllst_data_get(&layspecint->XDATA(tab)) + iquad; 94 CALL(cstr_to_double(read_line(rdr), &darray_double_data_get(XDATA(tab))[itab])); 95 if(darray_double_data_get(XDATA(tab))[itab] < 0) { 96 log_err(htgop, "The radiative properties cannot be negative.\n"); 97 res = RES_BAD_ARG; 98 goto error; 99 } 100 } 101 } 102 } 103 } 104 #undef CALL 105 106 exit: 107 return res; 108 error: 109 goto exit; 110 } 111 112 #undef DATA 113 #undef DOMAIN 114 #undef XDOMAIN 115 #undef XDATA