ARTS 2.5.11 (git: 6827797f)
m_general.cc
Go to the documentation of this file.
1/*===========================================================================
2 === File description
3 ===========================================================================*/
4
18/*===========================================================================
19 === External declarations
20 ===========================================================================*/
21
22#include "arts.h"
23
24#include <chrono>
25#include <cstdlib>
26#include <ratio>
27#include <stdexcept>
28
29#include "array.h"
30#include "arts_constants.h"
31#include "check_input.h"
32#include "m_general.h"
33#include "messages.h"
34#include "mystring.h"
35
36#include "math_funcs.h"
37#include "wsv_aux.h"
38
39#include "auto_md.h"
40#include "workspace_ng.h"
41
42#include "sensor.h"
43
44#include "fastem.h"
45#include "tessem.h"
46
48
49/*===========================================================================
50 === The functions (in alphabetical order)
51 ===========================================================================*/
52
53/* Workspace method: Doxygen documentation will be auto-generated */
54void INCLUDE(const Verbosity&) {}
55
56/* Workspace method: Doxygen documentation will be auto-generated */
58 // WS Generic Input:
59 const Agenda& x,
60 // Keywords:
61 const Index& level,
62 const Verbosity& verbosity) {
63 ostringstream os;
64 os << " " << x.name() << " {\n";
65 x.print(os, " ");
66 os << " "
67 << "}";
69 SWITCH_OUTPUT(level, os.str());
70}
71
72/* Workspace method: Doxygen documentation will be auto-generated */
74 // WS Generic Input:
75 const ArrayOfAgenda& x,
76 // Keywords:
77 const Index& level,
78 const Verbosity& verbosity) {
79 ostringstream os;
80 os << " " << x.nelem() << " agendas: {\n";
81 for (Index i = 0; i < x.nelem(); i++) {
82 os << " " << x[i].name() << ": {\n";
83 x[i].print(os, " ");
84 os << " "
85 << "}\n";
86 }
87 os << " "
88 << "}";
90 SWITCH_OUTPUT(level, os.str());
91}
92
93/* Workspace method: Doxygen documentation will be auto-generated */
94void Print( // WS Generic Input:
95 const ArrayOfGridPos& x,
96 // Keywords:
97 const Index& level,
98 const Verbosity& verbosity) {
99 ostringstream os;
100 for (Index i = 0; i < x.nelem(); i++) {
101 if (i) os << '\n';
102 os << " " << x[i].idx << " " << x[i].fd[0] << " " << x[i].fd[1];
103 }
105 SWITCH_OUTPUT(level, os.str());
106}
107
108/* Workspace method: Doxygen documentation will be auto-generated */
109void Print( // WS Generic Input:
110 const ArrayOfCIARecord& cia_data,
111 // Keywords:
112 const Index& level,
113 const Verbosity& verbosity) {
115
116 ostringstream os;
117 os << " CIA tag; Spectral range [cm-1]; Temp range [K]; # of sets\n";
118 for (Index i = 0; i < cia_data.nelem(); i++)
119 for (Index j = 0; j < cia_data[i].DatasetCount(); j++) {
120 Vector temp_grid{cia_data[i].TemperatureGrid(j)};
121 Vector freq_grid{cia_data[i].FrequencyGrid(j)};
122
123 os << setprecision(2) << std::fixed << " " << cia_data[i].MoleculeName(0)
124 << "-CIA-" << cia_data[i].MoleculeName(1) << "-" << j << "; "
125 << freq_grid[0] / 100. / SPEED_OF_LIGHT << " - "
126 << freq_grid[freq_grid.nelem() - 1] / 100. / SPEED_OF_LIGHT
127 << std::fixed << "; " << temp_grid[0] << " - "
128 << temp_grid[temp_grid.nelem() - 1] << "; " << temp_grid.nelem()
129 << "\n";
130 }
131 SWITCH_OUTPUT(level, os.str());
132}
133
134/* Workspace method: Doxygen documentation will be auto-generated */
135void Print( // WS Generic Input:
136 const ArrayOfString& x,
137 // Keywords:
138 const Index& level,
139 const Verbosity& verbosity) {
140 ostringstream os;
141 for (Index i = 0; i < x.nelem(); i++) {
142 if (i) os << '\n';
143 os << " " << x[i];
144 }
146 SWITCH_OUTPUT(level, os.str());
147}
148
149/* Workspace method: Doxygen documentation will be auto-generated */
150void Print( // WS Generic Input:
151 const ArrayOfPpath& x,
152 // Keywords:
153 const Index& level,
154 const Verbosity& verbosity) {
156 for (Index i = 0; i < x.nelem(); i++) {
157 ostringstream os;
158 os << "Ppath element " << i << ": ";
159 SWITCH_OUTPUT(level, os.str());
160 Print(x[i], level, verbosity);
161 }
162}
163
164/* Workspace method: Doxygen documentation will be auto-generated */
165void Print( // WS Generic Input:
166 const Timer& timer,
167 // Keywords:
168 const Index& level,
169 const Verbosity& verbosity) {
171 if (!timer.finished) {
173 level,
174 "Timer error: Nothing to output. Use timerStart/timerStop first.");
175 return;
176 }
177
178 ostringstream os;
179
180 const auto cputime =
181 static_cast<double>(timer.cputime_end - timer.cputime_start) /
182 CLOCKS_PER_SEC;
183 const auto walltime = std::chrono::duration<double, std::ratio<1>>(
184 timer.realtime_end - timer.realtime_start)
185 .count();
186 os << std::fixed << setprecision(2) << " * Timing: CPU " << cputime << "s, "
187 << "Wall " << walltime << "s, " << 100. * cputime / walltime << "%CPU\n";
188
189 SWITCH_OUTPUT(level, os.str());
190}
191
192/* Workspace method: Doxygen documentation will be auto-generated */
193void Print( // WS Generic Input:
194 const TessemNN& x,
195 // Keywords:
196 const Index& level,
197 const Verbosity& verbosity) {
199 ostringstream os;
200 os << "TessemNN size: Inputs = " << x.nb_inputs
201 << ", Outputs = " << x.nb_outputs << ", Cache = " << x.nb_cache;
202 SWITCH_OUTPUT(level, os.str());
203}
204
205/* Workspace method: Doxygen documentation will be auto-generated */
206void PrintWorkspace( // Workspace reference
207 Workspace& ws,
208 // Keywords:
209 const Index& only_allocated,
210 const Index& level,
211 const Verbosity& verbosity) {
212 ostringstream os;
213
214 if (only_allocated)
215 os << " Allocated workspace variables: \n";
216 else
217 os << " Workspace variables: \n";
218 for (Index i = 0; i < ws.nelem(); i++) {
219 if (!only_allocated) {
220 os << " ";
221 ws.PrintWsvName(os, i);
222 if (ws.is_initialized(i)) os << ws.depth(i);
223 os << "\n";
224 } else if (ws.is_initialized(i)) {
225 os << " ";
226 ws.PrintWsvName(os, i);
227 os << ws.depth(i) << "\n";
228 }
229 }
231 SWITCH_OUTPUT(level, os.str());
232}
233
234/* Workspace method: Doxygen documentation will be auto-generated */
236 const String& in1,
237 const String& in2,
238 const String& in3,
239 const String& in4,
240 const String& in5,
241 const String& in6,
242 const String& in7,
243 const String& in8,
244 const String& in9,
245 const String& in10,
246 const Verbosity&) {
247 out = in1 + in2 + in3 + in4 + in5 + in6 + in7 + in8 + in9 + in10;
248}
249
250/* Workspace method: Doxygen documentation will be auto-generated */
251void timerStart( // WS Output
252 Timer& timer,
253 const Verbosity&) {
254 timer.cputime_start = std::clock();
255 timer.realtime_start = std::chrono::high_resolution_clock::now();
256
257 timer.running = true;
258 timer.finished = false;
259}
260
261/* Workspace method: Doxygen documentation will be auto-generated */
262void timerStop( // WS Input
263 Timer& timer,
264 const Verbosity&) {
266 "Timer error: Unable to stop timer that's not running.");
267
268 timer.realtime_end = std::chrono::high_resolution_clock::now();
269 timer.cputime_end = std::clock();
270
271 timer.running = false;
272 timer.finished = true;
273}
274
275/* Workspace method: Doxygen documentation will be auto-generated */
276void Error(const String& msg, const Verbosity& verbosity) {
278 ARTS_USER_ERROR ( msg);
279}
280
281/* Workspace method: Doxygen documentation will be auto-generated */
282void Exit(const Verbosity& verbosity) {
284 out1 << " Forced exit.\n";
285 arts_exit(EXIT_SUCCESS);
286}
287
288/* Workspace method: Doxygen documentation will be auto-generated */
290 const ArrayOfAgenda& test_agenda_array,
291 const Index& index,
292 const Verbosity&) {
293 ostringstream os;
294 os << " Local value of iy_unit, agenda #" << index << " of "
295 << test_agenda_array.nelem();
296 test_agenda_arrayExecute(ws, index, os.str(), test_agenda_array);
297}
298
299void Test(const Verbosity&) {
300 Numeric za, aa, dza_new, daa_new;
301 const Numeric za0 = 67, aa0 = 12, dza = 9, daa = 11;
302 add_za_aa(za, aa, za0, aa0, dza, daa);
303 cout << za << " " << aa << endl;
304 diff_za_aa(dza_new, daa_new, za0, aa0, za, aa);
305 cout << dza_new << " " << daa_new << endl;
306}
307
308/* Workspace method: Doxygen documentation will be auto-generated */
309void verbosityInit( // WS Output:
310 Verbosity& verbosity) {
312
316}
317
318/* Workspace method: Doxygen documentation will be auto-generated */
319void verbositySet( // WS Output:
320 Verbosity& verbosity,
321 // WS Generic Input:
322 const Index& agenda,
323 const Index& screen,
324 const Index& file) {
325 verbosity.set_agenda_verbosity(agenda);
326 verbosity.set_screen_verbosity(screen);
327 verbosity.set_file_verbosity(file);
328}
329
330/* Workspace method: Doxygen documentation will be auto-generated */
331void verbositySetAgenda( // WS Output:
332 Verbosity& verbosity,
333 // WS Generic Input:
334 const Index& level) {
335 verbosity.set_agenda_verbosity(level);
336}
337
338/* Workspace method: Doxygen documentation will be auto-generated */
339void verbositySetFile( // WS Output:
340 Verbosity& verbosity,
341 // WS Generic Input:
342 const Index& level) {
343 verbosity.set_file_verbosity(level);
344}
345
346/* Workspace method: Doxygen documentation will be auto-generated */
347void verbositySetScreen( // WS Output:
348 Verbosity& verbosity,
349 // WS Generic Input:
350 const Index& level) {
351 verbosity.set_screen_verbosity(level);
352}
353
354/* Workspace method: Doxygen documentation will be auto-generated */
355void GetEnvironmentVariable( // WS Generic Output:
356 String& str,
357 // WS Generic Input:
358 const String& envvar,
359 const Verbosity& /* verbosity */) {
360 char* cstr;
361 cstr = std::getenv(envvar.c_str());
362 ARTS_USER_ERROR_IF (cstr == NULL,
363 "Environment variable ", envvar, " does not exist.")
364 str = cstr != NULL ? String(cstr) : "";
365}
366
367/* Workspace method: Doxygen documentation will be auto-generated */
368void GetNumberOfThreads(Index& nthreads, const Verbosity& /* verbosity */) {
369 nthreads = arts_omp_get_max_threads();
370}
371
372/* Workspace method: Doxygen documentation will be auto-generated */
373void GetEnvironmentVariable( // WS Generic Output:
374 Index& i,
375 // WS Generic Input:
376 const String& envvar,
377 const Verbosity& /* verbosity */) {
378 char* cstr;
379 cstr = std::getenv(envvar.c_str());
380 ARTS_USER_ERROR_IF (cstr == NULL || std::strlen(cstr) == 0,
381 "Environment variable ", envvar, " "
382 "is empty or does not exist.")
383 std::istringstream is(cstr);
384 is >> i;
385 ARTS_USER_ERROR_IF (!is.eof(),
386 "Cannot convert environment variable ", envvar, " "
387 "to Index: ", cstr)
388}
389
390/* Workspace method: Doxygen documentation will be auto-generated */
391#ifdef _OPENMP
392void SetNumberOfThreads(const Index& nthreads,
393 const Verbosity& /* verbosity */) {
394 omp_set_num_threads((int)nthreads);
395}
396#else
397void SetNumberOfThreads(const Index& /* nthreads */,
398 const Verbosity& verbosity) {
400 out1 << "No OpenMP support. Can't change number of threads.\n";
401}
402#endif
This file contains the definition of Array.
void arts_exit(int status)
This is the exit function of ARTS.
Definition: arts.cc:25
The global header file for ARTS.
Constants of physical expressions as constexpr.
int arts_omp_get_max_threads()
Wrapper for omp_get_max_threads.
Definition: arts_omp.cc:29
void test_agenda_arrayExecute(Workspace &ws, const Index agenda_array_index, const String &iy_unit, const ArrayOfAgenda &input_agenda_array)
Definition: auto_md.cc:26089
The Agenda class.
Definition: agenda_class.h:52
void print(ostream &os, const String &indent) const
Print an agenda.
String name() const
Agenda name.
This can be used to make arrays out of anything.
Definition: array.h:31
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:75
Index get_screen_verbosity() const
Definition: messages.h:48
Index get_agenda_verbosity() const
Definition: messages.h:47
void set_screen_verbosity(Index v)
Definition: messages.h:53
void set_agenda_verbosity(Index v)
Definition: messages.h:52
Index get_file_verbosity() const
Definition: messages.h:49
void set_file_verbosity(Index v)
Definition: messages.h:54
Workspace class.
Definition: workspace_ng.h:36
void PrintWsvName(OutputStream &outstream, Index i) const
Print WSV name to output stream.
Definition: workspace_ng.h:193
bool is_initialized(Index i) const
Checks existence of the given WSV.
Index nelem() const
Get the number of workspace variables.
Definition: workspace_ng.h:164
Index depth(Index i) const
Return scoping level of the given WSV.
#define _U_
Definition: config.h:177
#define ARTS_USER_ERROR(...)
Definition: debug.h:151
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:135
This file contains functions that are adapted from FASTEM code which is used to calculate surface emi...
void GetEnvironmentVariable(String &str, const String &envvar, const Verbosity &)
WORKSPACE METHOD: GetEnvironmentVariable.
Definition: m_general.cc:355
void GetNumberOfThreads(Index &nthreads, const Verbosity &)
WORKSPACE METHOD: GetNumberOfThreads.
Definition: m_general.cc:368
void Test(const Verbosity &)
WORKSPACE METHOD: Test.
Definition: m_general.cc:299
constexpr Numeric SPEED_OF_LIGHT
Definition: m_general.cc:47
void timerStart(Timer &timer, const Verbosity &)
WORKSPACE METHOD: timerStart.
Definition: m_general.cc:251
void verbositySetAgenda(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetAgenda.
Definition: m_general.cc:331
void SetNumberOfThreads(const Index &, const Verbosity &verbosity)
WORKSPACE METHOD: SetNumberOfThreads.
Definition: m_general.cc:397
void INCLUDE(const Verbosity &)
WORKSPACE METHOD: INCLUDE.
Definition: m_general.cc:54
void verbosityInit(Verbosity &verbosity)
WORKSPACE METHOD: verbosityInit.
Definition: m_general.cc:309
void TestArrayOfAgenda(Workspace &ws, const ArrayOfAgenda &test_agenda_array, const Index &index, const Verbosity &)
WORKSPACE METHOD: TestArrayOfAgenda.
Definition: m_general.cc:289
void Error(const String &msg, const Verbosity &verbosity)
WORKSPACE METHOD: Error.
Definition: m_general.cc:276
void Exit(const Verbosity &verbosity)
WORKSPACE METHOD: Exit.
Definition: m_general.cc:282
void timerStop(Timer &timer, const Verbosity &)
WORKSPACE METHOD: timerStop.
Definition: m_general.cc:262
void verbositySet(Verbosity &verbosity, const Index &agenda, const Index &screen, const Index &file)
WORKSPACE METHOD: verbositySet.
Definition: m_general.cc:319
void verbositySetFile(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetFile.
Definition: m_general.cc:339
void StringJoin(String &out, const String &in1, const String &in2, const String &in3, const String &in4, const String &in5, const String &in6, const String &in7, const String &in8, const String &in9, const String &in10, const Verbosity &)
WORKSPACE METHOD: StringJoin.
Definition: m_general.cc:235
void verbositySetScreen(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetScreen.
Definition: m_general.cc:347
void PrintWorkspace(Workspace &ws, const Index &only_allocated, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:206
void Print(Workspace &ws, const Agenda &x, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:57
Template functions for general supergeneric ws methods.
#define SWITCH_OUTPUT(x, y)
Definition: m_general.h:28
Verbosity verbosity_at_launch
The global message verbosity settings:
Definition: messages.cc:17
Declarations having to do with the four output streams.
#define CREATE_OUT1
Definition: messages.h:187
#define CREATE_OUTS
Definition: messages.h:191
#define CREATE_OUT0
Definition: messages.h:186
This file contains the definition of String, the ARTS string class.
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:199
constexpr Numeric speed_of_light
Speed of light [m/s] From: https://en.wikipedia.org/wiki/2019_redefinition_of_SI_base_units Date: 201...
void diff_za_aa(Numeric &dza, Numeric &daa, const Numeric &za0, const Numeric &aa0, const Numeric &za, const Numeric &aa)
Takes the difference of zenith and azimuth angles.
Definition: ppath.cc:413
void add_za_aa(Numeric &za, Numeric &aa, const Numeric &za0, const Numeric &aa0, const Numeric &dza, const Numeric &daa)
Adds up zenith and azimuth angles.
Definition: ppath.cc:375
Sensor modelling functions.
Index nb_outputs
Definition: tessem.h:16
Index nb_inputs
Definition: tessem.h:15
Index nb_cache
Definition: tessem.h:17
std::clock_t cputime_end
Definition: timer_struct.h:11
bool running
Definition: timer_struct.h:7
std::chrono::time_point< std::chrono::high_resolution_clock > realtime_start
Definition: timer_struct.h:10
bool finished
Definition: timer_struct.h:8
std::clock_t cputime_start
Definition: timer_struct.h:9
std::chrono::time_point< std::chrono::high_resolution_clock > realtime_end
Definition: timer_struct.h:12
This file contains functions that are adapted from TESSEM code which is used to calculate surface emi...
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.