ARTS  2.2.66
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 
22 /*===========================================================================
23  === File description
24  ===========================================================================*/
25 
41 /*===========================================================================
42  === External declarations
43  ===========================================================================*/
44 
45 #include "arts.h"
46 
47 #include <stdexcept>
48 #ifdef TIME_SUPPORT
49 #include <unistd.h>
50 #endif
51 
52 #include "m_general.h"
53 #include "array.h"
54 #include "check_input.h"
55 #include "messages.h"
56 #include "mystring.h"
57 
58 #include "math_funcs.h"
59 #include "make_vector.h"
60 #include "wsv_aux.h"
61 
62 #include "auto_md.h"
63 #include "workspace_ng.h"
64 
65 #include "sensor.h"
66 
67 
68 extern const Numeric SPEED_OF_LIGHT;
69 
70 /*===========================================================================
71  === The functions (in alphabetical order)
72  ===========================================================================*/
73 
74 /* Workspace method: Doxygen documentation will be auto-generated */
75 void INCLUDE(const Verbosity&)
76 {
77 }
78 
79 
80 /* Workspace method: Doxygen documentation will be auto-generated */
81 void Print(Workspace& ws _U_,
82  // WS Generic Input:
83  const Agenda& x,
84  // Keywords:
85  const Index& level,
86  const Verbosity& verbosity)
87 {
88  ostringstream os;
89  os << " " << x.name() << " {\n";
90  x.print(os, " ");
91  os << " " << "}";
93  SWITCH_OUTPUT (level, os.str ());
94 }
95 
96 
97 /* Workspace method: Doxygen documentation will be auto-generated */
98 void Print(// WS Generic Input:
99  const ArrayOfGridPos& x,
100  // Keywords:
101  const Index& level,
102  const Verbosity& verbosity)
103 {
104  ostringstream os;
105  for( Index i=0; i<x.nelem(); i++ )
106  {
107  if (i) os << '\n';
108  os << " " << x[i].idx << " " << x[i].fd[0] << " " << x[i].fd[1];
109  }
110  CREATE_OUTS;
111  SWITCH_OUTPUT (level, os.str ());
112 }
113 
114 
115 /* Workspace method: Doxygen documentation will be auto-generated */
116 void Print(// WS Generic Input:
117  const ArrayOfCIARecord& cia_data,
118  // Keywords:
119  const Index& level,
120  const Verbosity& verbosity)
121 {
122  CREATE_OUTS;
123 
124  ostringstream os;
125  os << " CIA tag; Spectral range [cm-1]; Temp range [K]; # of sets\n";
126  for (Index i = 0; i < cia_data.nelem(); i++)
127  for (Index j = 0; j < cia_data[i].DatasetCount(); j++)
128  {
129  Vector temp_grid = cia_data[i].TemperatureGrid(j);
130  Vector freq_grid = cia_data[i].FrequencyGrid(j);
131 
132  os << setprecision(2) << std::fixed << " "
133  << cia_data[i].MoleculeName(0) << "-CIA-" << cia_data[i].MoleculeName(1)
134  << "-" << j
135  << "; " << freq_grid[0] / 100. / SPEED_OF_LIGHT
136  << " - " << freq_grid[freq_grid.nelem()-1] / 100. / SPEED_OF_LIGHT
137  << std::fixed
138  << "; " << temp_grid[0] << " - " << temp_grid[temp_grid.nelem()-1]
139  << "; " << temp_grid.nelem()
140  << "\n";
141  }
142  SWITCH_OUTPUT(level, os.str());
143 }
144 
145 
146 /* Workspace method: Doxygen documentation will be auto-generated */
147 void Print(// WS Generic Input:
148  const ArrayOfString& x,
149  // Keywords:
150  const Index& level,
151  const Verbosity& verbosity)
152 {
153  ostringstream os;
154  for( Index i=0; i<x.nelem(); i++ )
155  {
156  if (i) os << '\n';
157  os << " " << x[i];
158  }
159  CREATE_OUTS;
160  SWITCH_OUTPUT (level, os.str ());
161 }
162 
163 
164 /* Workspace method: Doxygen documentation will be auto-generated */
165 void
166 Print(// WS Generic Input:
167  const Ppath& x,
168  // Keywords:
169  const Index& level,
170  const Verbosity& verbosity)
171 {
172  CREATE_OUTS;
173  SWITCH_OUTPUT (level, "dim: ");
174  Print( x.dim, level, verbosity );
175  SWITCH_OUTPUT (level, "np: ");
176  Print( x.np, level, verbosity );
177  SWITCH_OUTPUT (level, "constant: ");
178  Print( x.constant, level, verbosity );
179  SWITCH_OUTPUT (level, "background: ");
180  Print( x.background, level, verbosity );
181  SWITCH_OUTPUT (level, "start_pos: ");
182  Print( x.start_pos, level, verbosity );
183  SWITCH_OUTPUT (level, "start_los: ");
184  Print( x.start_los, level, verbosity );
185  SWITCH_OUTPUT (level, "start_lstep: ");
186  Print( x.start_lstep, level, verbosity );
187  SWITCH_OUTPUT (level, "pos: ");
188  Print( x.pos, level, verbosity );
189  SWITCH_OUTPUT (level, "los: ");
190  Print( x.los, level, verbosity );
191  SWITCH_OUTPUT (level, "r: ");
192  Print( x.r, level, verbosity );
193  SWITCH_OUTPUT (level, "lstep: ");
194  Print( x.lstep, level, verbosity );
195  SWITCH_OUTPUT (level, "end_pos: ");
196  Print( x.end_pos, level, verbosity );
197  SWITCH_OUTPUT (level, "end_los: ");
198  Print( x.end_los, level, verbosity );
199  SWITCH_OUTPUT (level, "end_lstep: ");
200  Print( x.end_lstep, level, verbosity );
201  SWITCH_OUTPUT (level, "nreal: ");
202  Print( x.nreal, level, verbosity );
203  SWITCH_OUTPUT (level, "ngroup: ");
204  Print( x.ngroup, level, verbosity );
205  SWITCH_OUTPUT (level, "gp_p: ");
206  Print( x.gp_p, level, verbosity );
207  if( x.dim >= 2 )
208  {
209  SWITCH_OUTPUT (level, "gp_lat: ");
210  Print( x.gp_lat, level, verbosity );
211  }
212  if( x.dim == 3 )
213  {
214  SWITCH_OUTPUT (level, "gp_lon: ");
215  Print( x.gp_lon, level, verbosity );
216  }
217 }
218 
219 
220 /* Workspace method: Doxygen documentation will be auto-generated */
221 void Print(// WS Generic Input:
222  const ArrayOfPpath& x,
223  // Keywords:
224  const Index& level,
225  const Verbosity& verbosity)
226 {
227  CREATE_OUTS;
228  for( Index i=0; i<x.nelem(); i++ )
229  {
230  ostringstream os;
231  os << "Ppath element " << i << ": ";
232  SWITCH_OUTPUT (level, os.str ());
233  Print( x[i], level, verbosity );
234  }
235 }
236 
237 
238 /* Workspace method: Doxygen documentation will be auto-generated */
239 #ifdef TIME_SUPPORT
240 void Print(// WS Generic Input:
241  const Timer& timer,
242  // Keywords:
243  const Index& level,
244  const Verbosity& verbosity)
245 {
246  CREATE_OUTS;
247 
248  if (!timer.finished)
249  {
250  SWITCH_OUTPUT(level, "Timer error: Nothing to output. Use timerStart/timerStop first.");
251  return;
252  }
253 
254  ostringstream os;
255  os.setf (ios::showpoint | ios::fixed);
256 
257  static long clktck = 0;
258 
259  if (clktck == 0)
260  if ((clktck = sysconf (_SC_CLK_TCK)) < 0)
261  throw runtime_error ("Timer error: Unable to determine CPU clock ticks");
262 
263  os << " * CPU time total: " << setprecision (2)
264  << (Numeric)((timer.cputime_end.tms_stime - timer.cputime_start.tms_stime)
265  + (timer.cputime_end.tms_utime - timer.cputime_start.tms_utime))
266  / (Numeric)clktck;
267 
268  os << " user: " << setprecision (2)
269  << (Numeric)(timer.cputime_end.tms_utime - timer.cputime_start.tms_utime)
270  / (Numeric)clktck;
271 
272  os << " system: " << setprecision (2)
273  << (Numeric)(timer.cputime_end.tms_stime - timer.cputime_end.tms_stime)
274  / (Numeric)clktck;
275 
276  os << "\n real: " << setprecision (2)
277  << (Numeric)(timer.realtime_end - timer.realtime_start) / (Numeric)clktck;
278 
279  os << " " << setprecision (2)
280  << (Numeric)((timer.cputime_end.tms_stime - timer.cputime_start.tms_stime)
281  + (timer.cputime_end.tms_utime - timer.cputime_start.tms_utime))
282  / (Numeric)(timer.realtime_end - timer.realtime_start) * 100.
283  << "%CPU\n";
284 
285  SWITCH_OUTPUT(level, os.str());
286 }
287 #else
288 void Print(// WS Generic Input:
289  const Timer&,
290  // Keywords:
291  const Index& level,
292  const Verbosity& verbosity)
293 {
294  SWITCH_OUTPUT (level, "Timer error: ARTS was compiled without timer support");
295 }
296 #endif
297 
298 
299 /* Workspace method: Doxygen documentation will be auto-generated */
300 void PrintWorkspace(// Workspace reference
301  Workspace& ws,
302  // Keywords:
303  const Index& only_allocated,
304  const Index& level,
305  const Verbosity& verbosity)
306 {
307  ostringstream os;
308 
309  if (only_allocated)
310  os << " Allocated workspace variables: \n";
311  else
312  os << " Workspace variables: \n";
313  for (Index i = 0; i < ws.nelem(); i++)
314  {
315  if (!only_allocated)
316  {
317  os << " ";
318  PrintWsvName (os, i);
319  if (ws.is_initialized(i)) os << "+";
320  os << "\n";
321  }
322  else if (ws.is_initialized(i))
323  {
324  os << " ";
325  PrintWsvName (os, i);
326  os << "\n";
327  }
328  }
329  CREATE_OUTS;
330  SWITCH_OUTPUT (level, os.str ());
331 }
332 
333 
334 /* Workspace method: Doxygen documentation will be auto-generated */
335 void
337  const String& in1,
338  const String& in2,
339  const String& in3,
340  const String& in4,
341  const String& in5,
342  const String& in6,
343  const String& in7,
344  const String& in8,
345  const String& in9,
346  const String& in10,
347  const Verbosity&
348  )
349 {
350  out = in1 + in2 + in3 + in4 + in5 + in6 + in7 + in8 + in9 + in10;
351 }
352 
353 
354 /* Workspace method: Doxygen documentation will be auto-generated */
355 #ifdef TIME_SUPPORT
356 void
357 timerStart (// WS Output
358  Timer& timer,
359  const Verbosity&)
360 {
361  if ((timer.realtime_start = times (&timer.cputime_start)) == (clock_t)-1)
362  throw runtime_error ("Timer error: Unable to get current CPU time");
363 
364  timer.running = true;
365  timer.finished = false;
366 }
367 #else
368 void
369 timerStart (// WS Output
370  Timer& /*starttime*/,
371  const Verbosity&)
372 {
373  throw runtime_error ("Timer error: ARTS was compiled without POSIX support, thus timer\nfunctions are not available.");
374 }
375 #endif
376 
377 
378 /* Workspace method: Doxygen documentation will be auto-generated */
379 #ifdef TIME_SUPPORT
380 void
381 timerStop (// WS Input
382  Timer& timer,
383  const Verbosity&)
384 {
385  if (!timer.running)
386  throw runtime_error("Timer error: Unable to stop timer that's not running.");
387 
388  if ((timer.realtime_end = times (&(timer.cputime_end))) == (clock_t)-1)
389  throw runtime_error ("Timer error: Unable to get current CPU time");
390 
391  timer.running = false;
392  timer.finished = true;
393 }
394 #else
395 void
396 timerStop (// WS Input
397  const Timer&,
398  const Verbosity&)
399 {
400  throw runtime_error ("Timer error: ARTS was compiled without POSIX support, thus timer\nfunctions are not available.");
401 }
402 #endif
403 
404 /* Workspace method: Doxygen documentation will be auto-generated */
405 void Error(const String& msg, const Verbosity& verbosity)
406 {
407  CREATE_OUT0;
408  throw runtime_error(msg);
409 }
410 
411 
412 
413 /* Workspace method: Doxygen documentation will be auto-generated */
414 void Exit(const Verbosity& verbosity)
415 {
416  CREATE_OUT1;
417  out1 << " Forced exit.\n";
418  arts_exit (EXIT_SUCCESS);
419 }
420 
421 
422 
423 /* Workspace method: Doxygen documentation will be auto-generated */
424 void Test(const Verbosity& verbosity )
425 {
426  // Let response be y=x for x=0:0.2:2
427  Vector xr,yr;
428  VectorLinSpace( xr, 0, 2.01, 0.2, verbosity );
429  xr[4] += 0.021;
430  yr = xr;
431 
432  // Let spectrum also be y=x, but defined on -0.05:0.4:3.05
433  Vector xs;
434  VectorLinSpace( xs, -0.05, 3.05, 0.4, verbosity );
435  xs[3] -= 0.01;
436  Vector ys(xs.nelem());
437  for( Index i=0; i<xs.nelem(); i++ )
438  { ys[i] = xs[i]; };
439 
440  // Determine ingeration vector
441  Vector h(xs.nelem());
442  sensor_integration_vector( h, yr, xr, xs );
443 
444  // Integrate by using h
445  cout << "Result of 1:th integration: " << h*ys << endl;
446  //cout << h << endl;
447 
448  sensor_integration_vector2( h, yr, xr, xs );
449  cout << "Result of 2:nd integration: " << h*ys << endl;
450  cout << "Expected result : " << (2.0+2.0/3.0) << endl;
451  //cout << h << endl;
452 }
453 
454 
455 
456 /* Workspace method: Doxygen documentation will be auto-generated */
457 void verbosityInit(// WS Output:
458  Verbosity& verbosity)
459 {
461 
462  verbosity.set_screen_verbosity(verbosity_at_launch.get_screen_verbosity());
463  verbosity.set_agenda_verbosity(verbosity_at_launch.get_agenda_verbosity());
464  verbosity.set_file_verbosity(verbosity_at_launch.get_file_verbosity());
465 }
466 
467 
468 /* Workspace method: Doxygen documentation will be auto-generated */
469 void verbositySet(// WS Output:
470  Verbosity& verbosity,
471  // WS Generic Input:
472  const Index& agenda,
473  const Index& screen,
474  const Index& file)
475 {
476  verbosity.set_agenda_verbosity(agenda);
477  verbosity.set_screen_verbosity(screen);
478  verbosity.set_file_verbosity(file);
479 }
480 
481 
482 /* Workspace method: Doxygen documentation will be auto-generated */
483 void verbositySetAgenda(// WS Output:
484  Verbosity& verbosity,
485  // WS Generic Input:
486  const Index& level)
487 {
488  verbosity.set_agenda_verbosity(level);
489 }
490 
491 
492 /* Workspace method: Doxygen documentation will be auto-generated */
493 void verbositySetFile(// WS Output:
494  Verbosity& verbosity,
495  // WS Generic Input:
496  const Index& level)
497 {
498  verbosity.set_file_verbosity(level);
499 }
500 
501 
502 /* Workspace method: Doxygen documentation will be auto-generated */
503 void verbositySetScreen(// WS Output:
504  Verbosity& verbosity,
505  // WS Generic Input:
506  const Index& level)
507 {
508  verbosity.set_screen_verbosity(level);
509 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Template functions for general supergeneric ws methods.
ArrayOfGridPos gp_lat
Definition: ppath.h:77
void verbositySetScreen(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetScreen.
Definition: m_general.cc:503
Numeric constant
Definition: ppath.h:62
Index get_agenda_verbosity() const
Definition: messages.h:64
void Print(Workspace &ws, const Agenda &x, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:81
The Agenda class.
Definition: agenda_class.h:44
String name() const
Agenda name.
Index nelem() const
Number of elements.
Definition: array.h:176
void verbositySetAgenda(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetAgenda.
Definition: m_general.cc:483
void arts_exit(int status)
This is the exit function of ARTS.
Definition: arts.cc:42
Declarations having to do with the four output streams.
void verbositySetFile(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetFile.
Definition: m_general.cc:493
Matrix los
Definition: ppath.h:68
void Error(const String &msg, const Verbosity &verbosity)
WORKSPACE METHOD: Error.
Definition: m_general.cc:405
The Vector class.
Definition: matpackI.h:556
Vector end_pos
Definition: ppath.h:71
Index dim
Definition: ppath.h:60
Vector lstep
Definition: ppath.h:70
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:84
Matrix pos
Definition: ppath.h:67
void set_agenda_verbosity(Index v)
Definition: messages.h:69
Vector ngroup
Definition: ppath.h:75
void timerStart(Timer &, const Verbosity &)
WORKSPACE METHOD: timerStart.
Definition: m_general.cc:369
Vector start_pos
Definition: ppath.h:64
void StringCompose(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: StringCompose.
Definition: m_general.cc:336
Vector r
Definition: ppath.h:69
void Test(const Verbosity &verbosity)
WORKSPACE METHOD: Test.
Definition: m_general.cc:424
void sensor_integration_vector2(VectorView h, ConstVectorView f, ConstVectorView x_f, ConstVectorView x_g_in)
sensor_integration_vector
Definition: sensor.cc:886
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:180
Numeric end_lstep
Definition: ppath.h:73
void sensor_integration_vector(VectorView h, ConstVectorView f, ConstVectorView x_f_in, ConstVectorView x_g_in)
sensor_integration_vector
Definition: sensor.cc:723
This file contains the definition of Array.
This file contains the declaration and partly the implementation of the workspace class...
Sensor modelling functions.
Vector end_los
Definition: ppath.h:72
The implementation for String, the ARTS string class.
Definition: mystring.h:63
void verbosityInit(Verbosity &verbosity)
WORKSPACE METHOD: verbosityInit.
Definition: m_general.cc:457
The global header file for ARTS.
String background
Definition: ppath.h:63
void verbositySet(Verbosity &verbosity, const Index &agenda, const Index &screen, const Index &file)
WORKSPACE METHOD: verbositySet.
Definition: m_general.cc:469
#define CREATE_OUTS
Definition: messages.h:216
bool finished
Definition: m_general.h:63
void set_file_verbosity(Index v)
Definition: messages.h:71
Index nelem()
Definition: workspace_ng.h:96
Numeric start_lstep
Definition: ppath.h:66
#define CREATE_OUT1
Definition: messages.h:212
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:110
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
bool running
Definition: m_general.h:62
Vector nreal
Definition: ppath.h:74
const Numeric SPEED_OF_LIGHT
void PrintWorkspace(Workspace &ws, const Index &only_allocated, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:300
void print(ostream &os, const String &indent) const
Print an agenda.
The class MakeVector is a special kind of Vector that can be initialized explicitly from one or more ...
Index np
Definition: ppath.h:61
ArrayOfGridPos gp_lon
Definition: ppath.h:78
void Exit(const Verbosity &verbosity)
WORKSPACE METHOD: Exit.
Definition: m_general.cc:414
Index get_file_verbosity() const
Definition: messages.h:66
Vector start_los
Definition: ppath.h:65
Workspace class.
Definition: workspace_ng.h:47
#define _U_
Definition: config.h:167
#define CREATE_OUT0
Definition: messages.h:211
Verbosity verbosity_at_launch
Definition: messages.cc:34
The structure to describe a propagation path and releated quantities.
Definition: ppath.h:59
void INCLUDE(const Verbosity &)
WORKSPACE METHOD: INCLUDE.
Definition: m_general.cc:75
Index get_screen_verbosity() const
Definition: messages.h:65
#define SWITCH_OUTPUT(x, y)
Definition: m_general.h:45
void VectorLinSpace(Vector &x, const Numeric &start, const Numeric &stop, const Numeric &step, const Verbosity &verbosity)
WORKSPACE METHOD: VectorLinSpace.
ArrayOfGridPos gp_p
Definition: ppath.h:76
void timerStop(const Timer &, const Verbosity &)
Definition: m_general.cc:396
This file contains the definition of String, the ARTS string class.
void set_screen_verbosity(Index v)
Definition: messages.h:70
Auxiliary header stuff related to workspace variable groups.