11/*
2- * This file is a stand-alone executable developed for the
3- * testing of the C++ interface to the RTE+RRTMGP radiation code.
4- *
5- * It is free software: you can redistribute it and/or modify
6- * it under the terms of the GNU General Public License as published by
7- * the Free Software Foundation, either version 3 of the License, or
8- * (at your option) any later version.
9- *
10- * This software is distributed in the hope that it will be useful,
11- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13- * GNU General Public License for more details.
14- *
15- * You should have received a copy of the GNU General Public License
16- * along with this software. If not, see <http://www.gnu.org/licenses/>.
17- */
18-
19- #include < boost/algorithm/string.hpp>
20- #include < chrono>
21- #include < cmath>
22- #include < iomanip>
23- #include < cuda_profiler_api.h>
24-
25- #include " Status.h"
26- #include " Netcdf_interface.h"
27- #include " Array.h"
28- #include " Gas_concs.h"
29- #include " tilt_utils.h"
30- #include " types.h"
2+ * This file is a stand-alone executable developed for the
3+ * testing of the C++ interface to the RTE+RRTMGP radiation code.
4+ *
5+ * It is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This software is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this software. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+ #include < boost/algorithm/string.hpp>
20+ #include < chrono>
21+ #include < cmath>
22+ #include < iomanip>
23+ #include < cuda_profiler_api.h>
24+
25+ #include " Status.h"
26+ #include " Netcdf_interface.h"
27+ #include " Array.h"
28+ #include " Gas_concs.h"
29+ #include " Aerosol_optics_rt.h"
30+ #include " tilt_utils.h"
31+ #include " types.h"
32+
33+ void read_and_set_aer (
34+ const std::string& aerosol_name, const int n_col_x, const int n_col_y, const int n_lay,
35+ const Netcdf_handle& input_nc, Aerosol_concs& aerosol_concs)
36+ {
37+ if (input_nc.variable_exists (aerosol_name))
38+ {
39+ std::map<std::string, int > dims = input_nc.get_variable_dimensions (aerosol_name);
40+ const int n_dims = dims.size ();
41+
42+ if (n_dims == 1 )
43+ {
44+ if (dims.at (" lay" ) == n_lay)
45+ aerosol_concs.set_vmr (aerosol_name,
46+ Array<Float,1 >(input_nc.get_variable <Float>(aerosol_name, {n_lay}), {n_lay}));
47+ else
48+ throw std::runtime_error (" Illegal dimensions of \" " + aerosol_name + " \" in input" );
49+ }
50+ else if (n_dims == 3 )
51+ {
52+ if (dims.at (" lay" ) == n_lay && dims.at (" y" ) == n_col_y && dims.at (" x" ) == n_col_x)
53+ aerosol_concs.set_vmr (aerosol_name,
54+ Array<Float,2 >(input_nc.get_variable <Float>(aerosol_name, {n_lay, n_col_y, n_col_x}), {n_col_x * n_col_y, n_lay}));
55+ else
56+ throw std::runtime_error (" Illegal dimensions of \" " + aerosol_name + " \" in input" );
57+ }
58+ else
59+ throw std::runtime_error (" Illegal dimensions of \" " + aerosol_name + " \" in input" );
60+ }
61+ else
62+ {
63+ throw std::runtime_error (" Aerosol type \" " + aerosol_name + " \" not available in input file." );
64+ }
65+ }
3166
3267void read_and_set_vmr (
3368 const std::string& gas_name, const int n_col_x, const int n_col_y, const int n_lay,
@@ -164,6 +199,11 @@ void print_command_line_options(
164199 " cf4" , " no2"
165200 };
166201
202+ std::vector<std::string> aerosol_names = {
203+ " aermr01" , " aermr02" , " aermr03" , " aermr04" , " aermr05" , " aermr06" , " aermr07" ,
204+ " aermr08" , " aermr09" , " aermr10" ," aermr11"
205+ };
206+
167207 Status::print_message (" ###### Starting Script ######" );
168208
169209 // //// FLOW CONTROL SWITCHES //////
@@ -172,6 +212,7 @@ void print_command_line_options(
172212 {" cloud-optics" , { false , " Enable cloud optics (both liquid and ice)." }},
173213 {" liq-cloud-optics" , { false , " liquid only cloud optics." }},
174214 {" ice-cloud-optics" , { false , " ice only cloud optics." }},
215+ {" aerosol-optics" , { false , " aerosol optics." }},
175216 {" tilt-sza" , { false , " tilt provided value of sza in input file. IN DEGREES. '--tilt-sza 50': use a sza of 50 degrees" }},
176217 {" tilt-azi" , { false , " tilt provided value of azi in input file. FROM POS Y, CLOCKWISE, IN DEGREES. '--tilt-azi 240': use of azi of 240 degrees" }}};
177218
@@ -185,6 +226,7 @@ void print_command_line_options(
185226 bool switch_cloud_optics = command_line_switches.at (" cloud-optics" ).first ;
186227 bool switch_liq_cloud_optics = command_line_switches.at (" liq-cloud-optics" ).first ;
187228 bool switch_ice_cloud_optics = command_line_switches.at (" ice-cloud-optics" ).first ;
229+ const bool switch_aerosol_optics = command_line_switches.at (" aerosol-optics" ).first ;
188230 const bool switch_tilt_sza = command_line_switches.at (" tilt-sza" ).first ;
189231 const bool switch_tilt_azi = command_line_switches.at (" tilt-azi" ).first ;
190232
@@ -276,6 +318,27 @@ void print_command_line_options(
276318 read_and_set_vmr (" cf4" , n_col_x, n_col_y, n_lay, input_nc, gas_concs);
277319 read_and_set_vmr (" no2" , n_col_x, n_col_y, n_lay, input_nc, gas_concs);
278320
321+ Array<Float,2 > rh;
322+ Aerosol_concs aerosol_concs;
323+
324+ if (switch_aerosol_optics)
325+ {
326+ rh.set_dims ({n_col, n_lay});
327+ rh = std::move (input_nc.get_variable <Float>(" rh" , {n_lay, n_col_y, n_col_x}));
328+
329+ read_and_set_aer (" aermr01" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
330+ read_and_set_aer (" aermr02" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
331+ read_and_set_aer (" aermr03" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
332+ read_and_set_aer (" aermr04" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
333+ read_and_set_aer (" aermr05" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
334+ read_and_set_aer (" aermr06" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
335+ read_and_set_aer (" aermr07" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
336+ read_and_set_aer (" aermr08" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
337+ read_and_set_aer (" aermr09" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
338+ read_and_set_aer (" aermr10" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
339+ read_and_set_aer (" aermr11" , n_col_x, n_col_y, n_lay, input_nc, aerosol_concs);
340+ }
341+
279342 for (const auto & gas_name : gas_names) {
280343 if (!gas_concs.exists (gas_name)) {
281344 continue ;
@@ -320,6 +383,8 @@ void print_command_line_options(
320383 Array<Float,2 > p_lay_out = p_lay;
321384 Array<Float,2 > p_lev_out = p_lev;
322385 Gas_concs gas_concs_out = gas_concs;
386+ Aerosol_concs aerosol_concs_out = aerosol_concs;
387+ Array<Float,2 > rh_out = rh;
323388
324389 Array<Float,2 > lwp_out;
325390 lwp_out.set_dims ({n_col, n_z_in});
@@ -336,13 +401,13 @@ void print_command_line_options(
336401 n_lay, n_lev, n_z_in, n_zh_in ,
337402 xh, yh, zh, z,
338403 p_lay, t_lay, p_lev, t_lev,
339- lwp, iwp, rel, dei,
340- gas_concs,
404+ lwp, iwp, rel, dei, rh,
405+ gas_concs, aerosol_concs,
341406 p_lay_out, t_lay_out, p_lev_out, t_lev_out,
342- lwp_out, iwp_out, rel_out, dei_out,
343- gas_concs_out,
344- gas_names,
345- switch_cloud_optics, switch_liq_cloud_optics, switch_ice_cloud_optics
407+ lwp_out, iwp_out, rel_out, dei_out, rh_out,
408+ gas_concs_out, aerosol_concs_out,
409+ gas_names, aerosol_names,
410+ switch_cloud_optics, switch_liq_cloud_optics, switch_ice_cloud_optics, switch_aerosol_optics
346411 );
347412
348413 std::vector<Float> z_out_compress = linspace (z.v ()[0 ], z.v ()[n_z_in - 1 ], n_z_in);
0 commit comments