ARTS 2.5.9 (git: 825fa5f2)
m_general.cc
Go to the documentation of this file.
1/* Copyright (C) 2002-2012
2 Patrick Eriksson <Patrick.Eriksson@chalmers.se>
3 Stefan Buehler <sbuehler@ltu.se>
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
9
10 This program 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 program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 USA. */
19
20/*===========================================================================
21 === File description
22 ===========================================================================*/
23
37/*===========================================================================
38 === External declarations
39 ===========================================================================*/
40
41#include "arts.h"
42
43#include <chrono>
44#include <cstdlib>
45#include <ratio>
46#include <stdexcept>
47
48#include "array.h"
49#include "arts_constants.h"
50#include "check_input.h"
51#include "m_general.h"
52#include "messages.h"
53#include "mystring.h"
54
55#include "math_funcs.h"
56#include "wsv_aux.h"
57
58#include "auto_md.h"
59#include "workspace_ng.h"
60
61#include "sensor.h"
62
63#include "fastem.h"
64#include "tessem.h"
65
67
68/*===========================================================================
69 === The functions (in alphabetical order)
70 ===========================================================================*/
71
72/* Workspace method: Doxygen documentation will be auto-generated */
73void INCLUDE(const Verbosity&) {}
74
75/* Workspace method: Doxygen documentation will be auto-generated */
77 // WS Generic Input:
78 const Agenda& x,
79 // Keywords:
80 const Index& level,
81 const Verbosity& verbosity) {
82 ostringstream os;
83 os << " " << x.name() << " {\n";
84 x.print(os, " ");
85 os << " "
86 << "}";
88 SWITCH_OUTPUT(level, os.str());
89}
90
91/* Workspace method: Doxygen documentation will be auto-generated */
93 // WS Generic Input:
94 const ArrayOfAgenda& x,
95 // Keywords:
96 const Index& level,
97 const Verbosity& verbosity) {
98 ostringstream os;
99 os << " " << x.nelem() << " agendas: {\n";
100 for (Index i = 0; i < x.nelem(); i++) {
101 os << " " << x[i].name() << ": {\n";
102 x[i].print(os, " ");
103 os << " "
104 << "}\n";
105 }
106 os << " "
107 << "}";
109 SWITCH_OUTPUT(level, os.str());
110}
111
112/* Workspace method: Doxygen documentation will be auto-generated */
113void Print( // WS Generic Input:
114 const ArrayOfGridPos& x,
115 // Keywords:
116 const Index& level,
117 const Verbosity& verbosity) {
118 ostringstream os;
119 for (Index i = 0; i < x.nelem(); i++) {
120 if (i) os << '\n';
121 os << " " << x[i].idx << " " << x[i].fd[0] << " " << x[i].fd[1];
122 }
124 SWITCH_OUTPUT(level, os.str());
125}
126
127/* Workspace method: Doxygen documentation will be auto-generated */
128void Print( // WS Generic Input:
129 const ArrayOfCIARecord& cia_data,
130 // Keywords:
131 const Index& level,
132 const Verbosity& verbosity) {
134
135 ostringstream os;
136 os << " CIA tag; Spectral range [cm-1]; Temp range [K]; # of sets\n";
137 for (Index i = 0; i < cia_data.nelem(); i++)
138 for (Index j = 0; j < cia_data[i].DatasetCount(); j++) {
139 Vector temp_grid = cia_data[i].TemperatureGrid(j);
140 Vector freq_grid = cia_data[i].FrequencyGrid(j);
141
142 os << setprecision(2) << std::fixed << " " << cia_data[i].MoleculeName(0)
143 << "-CIA-" << cia_data[i].MoleculeName(1) << "-" << j << "; "
144 << freq_grid[0] / 100. / SPEED_OF_LIGHT << " - "
145 << freq_grid[freq_grid.nelem() - 1] / 100. / SPEED_OF_LIGHT
146 << std::fixed << "; " << temp_grid[0] << " - "
147 << temp_grid[temp_grid.nelem() - 1] << "; " << temp_grid.nelem()
148 << "\n";
149 }
150 SWITCH_OUTPUT(level, os.str());
151}
152
153/* Workspace method: Doxygen documentation will be auto-generated */
154void Print( // WS Generic Input:
155 const ArrayOfString& x,
156 // Keywords:
157 const Index& level,
158 const Verbosity& verbosity) {
159 ostringstream os;
160 for (Index i = 0; i < x.nelem(); i++) {
161 if (i) os << '\n';
162 os << " " << x[i];
163 }
165 SWITCH_OUTPUT(level, os.str());
166}
167
168/* Workspace method: Doxygen documentation will be auto-generated */
169void Print( // WS Generic Input:
170 const ArrayOfPpath& x,
171 // Keywords:
172 const Index& level,
173 const Verbosity& verbosity) {
175 for (Index i = 0; i < x.nelem(); i++) {
176 ostringstream os;
177 os << "Ppath element " << i << ": ";
178 SWITCH_OUTPUT(level, os.str());
179 Print(x[i], level, verbosity);
180 }
181}
182
183/* Workspace method: Doxygen documentation will be auto-generated */
184void Print( // WS Generic Input:
185 const Timer& timer,
186 // Keywords:
187 const Index& level,
188 const Verbosity& verbosity) {
190 if (!timer.finished) {
192 level,
193 "Timer error: Nothing to output. Use timerStart/timerStop first.");
194 return;
195 }
196
197 ostringstream os;
198
199 const auto cputime =
200 static_cast<double>(timer.cputime_end - timer.cputime_start) /
201 CLOCKS_PER_SEC;
202 const auto walltime = std::chrono::duration<double, std::ratio<1>>(
203 timer.realtime_end - timer.realtime_start)
204 .count();
205 os << std::fixed << setprecision(2) << " * Timing: CPU " << cputime << "s, "
206 << "Wall " << walltime << "s, " << 100. * cputime / walltime << "%CPU\n";
207
208 SWITCH_OUTPUT(level, os.str());
209}
210
211/* Workspace method: Doxygen documentation will be auto-generated */
212void Print( // WS Generic Input:
213 const TessemNN& x,
214 // Keywords:
215 const Index& level,
216 const Verbosity& verbosity) {
218 ostringstream os;
219 os << "TessemNN size: Inputs = " << x.nb_inputs
220 << ", Outputs = " << x.nb_outputs << ", Cache = " << x.nb_cache;
221 SWITCH_OUTPUT(level, os.str());
222}
223
224/* Workspace method: Doxygen documentation will be auto-generated */
225void PrintWorkspace( // Workspace reference
226 Workspace& ws,
227 // Keywords:
228 const Index& only_allocated,
229 const Index& level,
230 const Verbosity& verbosity) {
231 ostringstream os;
232
233 if (only_allocated)
234 os << " Allocated workspace variables: \n";
235 else
236 os << " Workspace variables: \n";
237 for (Index i = 0; i < ws.nelem(); i++) {
238 if (!only_allocated) {
239 os << " ";
240 ws.PrintWsvName(os, i);
241 if (ws.is_initialized(i)) os << ws.depth(i);
242 os << "\n";
243 } else if (ws.is_initialized(i)) {
244 os << " ";
245 ws.PrintWsvName(os, i);
246 os << ws.depth(i) << "\n";
247 }
248 }
250 SWITCH_OUTPUT(level, os.str());
251}
252
253/* Workspace method: Doxygen documentation will be auto-generated */
255 const String& in1,
256 const String& in2,
257 const String& in3,
258 const String& in4,
259 const String& in5,
260 const String& in6,
261 const String& in7,
262 const String& in8,
263 const String& in9,
264 const String& in10,
265 const Verbosity&) {
266 out = in1 + in2 + in3 + in4 + in5 + in6 + in7 + in8 + in9 + in10;
267}
268
269/* Workspace method: Doxygen documentation will be auto-generated */
270void timerStart( // WS Output
271 Timer& timer,
272 const Verbosity&) {
273 timer.cputime_start = std::clock();
274 timer.realtime_start = std::chrono::high_resolution_clock::now();
275
276 timer.running = true;
277 timer.finished = false;
278}
279
280/* Workspace method: Doxygen documentation will be auto-generated */
281void timerStop( // WS Input
282 Timer& timer,
283 const Verbosity&) {
285 "Timer error: Unable to stop timer that's not running.");
286
287 timer.realtime_end = std::chrono::high_resolution_clock::now();
288 timer.cputime_end = std::clock();
289
290 timer.running = false;
291 timer.finished = true;
292}
293
294/* Workspace method: Doxygen documentation will be auto-generated */
295void Error(const String& msg, const Verbosity& verbosity) {
297 ARTS_USER_ERROR ( msg);
298}
299
300/* Workspace method: Doxygen documentation will be auto-generated */
301void Exit(const Verbosity& verbosity) {
303 out1 << " Forced exit.\n";
304 arts_exit(EXIT_SUCCESS);
305}
306
307/* Workspace method: Doxygen documentation will be auto-generated */
309 const ArrayOfAgenda& test_agenda_array,
310 const Index& index,
311 const Verbosity&) {
312 ostringstream os;
313 os << " Local value of iy_unit, agenda #" << index << " of "
314 << test_agenda_array.nelem();
315 test_agenda_arrayExecute(ws, index, os.str(), test_agenda_array);
316}
317
318void Test(const Verbosity&) {
319 Numeric za, aa, dza_new, daa_new;
320 const Numeric za0 = 67, aa0 = 12, dza = 9, daa = 11;
321 add_za_aa(za, aa, za0, aa0, dza, daa);
322 cout << za << " " << aa << endl;
323 diff_za_aa(dza_new, daa_new, za0, aa0, za, aa);
324 cout << dza_new << " " << daa_new << endl;
325}
326
327/* Workspace method: Doxygen documentation will be auto-generated */
328void verbosityInit( // WS Output:
329 Verbosity& verbosity) {
331
335}
336
337/* Workspace method: Doxygen documentation will be auto-generated */
338void verbositySet( // WS Output:
339 Verbosity& verbosity,
340 // WS Generic Input:
341 const Index& agenda,
342 const Index& screen,
343 const Index& file) {
344 verbosity.set_agenda_verbosity(agenda);
345 verbosity.set_screen_verbosity(screen);
346 verbosity.set_file_verbosity(file);
347}
348
349/* Workspace method: Doxygen documentation will be auto-generated */
350void verbositySetAgenda( // WS Output:
351 Verbosity& verbosity,
352 // WS Generic Input:
353 const Index& level) {
354 verbosity.set_agenda_verbosity(level);
355}
356
357/* Workspace method: Doxygen documentation will be auto-generated */
358void verbositySetFile( // WS Output:
359 Verbosity& verbosity,
360 // WS Generic Input:
361 const Index& level) {
362 verbosity.set_file_verbosity(level);
363}
364
365/* Workspace method: Doxygen documentation will be auto-generated */
366void verbositySetScreen( // WS Output:
367 Verbosity& verbosity,
368 // WS Generic Input:
369 const Index& level) {
370 verbosity.set_screen_verbosity(level);
371}
372
373/* Workspace method: Doxygen documentation will be auto-generated */
374void GetEnvironmentVariable( // WS Generic Output:
375 String& str,
376 // WS Generic Input:
377 const String& envvar,
378 const Verbosity& /* verbosity */) {
379 char* cstr;
380 cstr = std::getenv(envvar.c_str());
381 ARTS_USER_ERROR_IF (cstr == NULL,
382 "Environment variable ", envvar, " does not exist.")
383 str = cstr != NULL ? String(cstr) : "";
384}
385
386/* Workspace method: Doxygen documentation will be auto-generated */
387void GetNumberOfThreads(Index& nthreads, const Verbosity& /* verbosity */) {
388 nthreads = arts_omp_get_max_threads();
389}
390
391/* Workspace method: Doxygen documentation will be auto-generated */
392void GetEnvironmentVariable( // WS Generic Output:
393 Index& i,
394 // WS Generic Input:
395 const String& envvar,
396 const Verbosity& /* verbosity */) {
397 char* cstr;
398 cstr = std::getenv(envvar.c_str());
399 ARTS_USER_ERROR_IF (cstr == NULL || std::strlen(cstr) == 0,
400 "Environment variable ", envvar, " "
401 "is empty or does not exist.")
402 std::istringstream is(cstr);
403 is >> i;
404 ARTS_USER_ERROR_IF (!is.eof(),
405 "Cannot convert environment variable ", envvar, " "
406 "to Index: ", cstr)
407}
408
409/* Workspace method: Doxygen documentation will be auto-generated */
410#ifdef _OPENMP
411void SetNumberOfThreads(const Index& nthreads,
412 const Verbosity& /* verbosity */) {
413 omp_set_num_threads((int)nthreads);
414}
415#else
416void SetNumberOfThreads(const Index& /* nthreads */,
417 const Verbosity& verbosity) {
419 out1 << "No OpenMP support. Can't change number of threads.\n";
420}
421#endif
This file contains the definition of Array.
void arts_exit(int status)
This is the exit function of ARTS.
Definition: arts.cc:42
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:46
void test_agenda_arrayExecute(Workspace &ws, const Index agenda_array_index, const String &iy_unit, const ArrayOfAgenda &input_agenda_array)
Definition: auto_md.cc:26004
The Agenda class.
Definition: agenda_class.h:69
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:48
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:547
The Vector class.
Definition: matpackI.h:910
Index get_screen_verbosity() const
Definition: messages.h:65
Index get_agenda_verbosity() const
Definition: messages.h:64
void set_screen_verbosity(Index v)
Definition: messages.h:70
void set_agenda_verbosity(Index v)
Definition: messages.h:69
Index get_file_verbosity() const
Definition: messages.h:66
void set_file_verbosity(Index v)
Definition: messages.h:71
Workspace class.
Definition: workspace_ng.h:53
void PrintWsvName(OutputStream &outstream, Index i) const
Print WSV name to output stream.
Definition: workspace_ng.h:207
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:178
Index depth(Index i) const
Return scoping level of the given WSV.
#define _U_
Definition: config.h:180
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
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:374
void GetNumberOfThreads(Index &nthreads, const Verbosity &)
WORKSPACE METHOD: GetNumberOfThreads.
Definition: m_general.cc:387
void Test(const Verbosity &)
WORKSPACE METHOD: Test.
Definition: m_general.cc:318
constexpr Numeric SPEED_OF_LIGHT
Definition: m_general.cc:66
void timerStart(Timer &timer, const Verbosity &)
WORKSPACE METHOD: timerStart.
Definition: m_general.cc:270
void verbositySetAgenda(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetAgenda.
Definition: m_general.cc:350
void SetNumberOfThreads(const Index &, const Verbosity &verbosity)
WORKSPACE METHOD: SetNumberOfThreads.
Definition: m_general.cc:416
void INCLUDE(const Verbosity &)
WORKSPACE METHOD: INCLUDE.
Definition: m_general.cc:73
void verbosityInit(Verbosity &verbosity)
WORKSPACE METHOD: verbosityInit.
Definition: m_general.cc:328
void TestArrayOfAgenda(Workspace &ws, const ArrayOfAgenda &test_agenda_array, const Index &index, const Verbosity &)
WORKSPACE METHOD: TestArrayOfAgenda.
Definition: m_general.cc:308
void Error(const String &msg, const Verbosity &verbosity)
WORKSPACE METHOD: Error.
Definition: m_general.cc:295
void Exit(const Verbosity &verbosity)
WORKSPACE METHOD: Exit.
Definition: m_general.cc:301
void timerStop(Timer &timer, const Verbosity &)
WORKSPACE METHOD: timerStop.
Definition: m_general.cc:281
void verbositySet(Verbosity &verbosity, const Index &agenda, const Index &screen, const Index &file)
WORKSPACE METHOD: verbositySet.
Definition: m_general.cc:338
void verbositySetFile(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetFile.
Definition: m_general.cc:358
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:254
void verbositySetScreen(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetScreen.
Definition: m_general.cc:366
void PrintWorkspace(Workspace &ws, const Index &only_allocated, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:225
void Print(Workspace &ws, const Agenda &x, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:76
Template functions for general supergeneric ws methods.
#define SWITCH_OUTPUT(x, y)
Definition: m_general.h:45
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Verbosity verbosity_at_launch
The global message verbosity settings:
Definition: messages.cc:34
Declarations having to do with the four output streams.
#define CREATE_OUT1
Definition: messages.h:204
#define CREATE_OUTS
Definition: messages.h:208
#define CREATE_OUT0
Definition: messages.h:203
This file contains the definition of String, the ARTS string class.
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:216
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:430
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:392
Sensor modelling functions.
Index nb_outputs
Definition: tessem.h:35
Index nb_inputs
Definition: tessem.h:34
Index nb_cache
Definition: tessem.h:36
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.