ARTS  2.0.49
m_general.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
2  Patrick Eriksson <Patrick.Eriksson@rss.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 "workspace_ng.h"
63 
64 /*===========================================================================
65  === The functions (in alphabetical order)
66  ===========================================================================*/
67 
68 /* Workspace method: Doxygen documentation will be auto-generated */
69 void INCLUDE(const Verbosity&)
70 {
71 }
72 
73 
74 /* Workspace method: Doxygen documentation will be auto-generated */
75 void Print(Workspace& ws _U_,
76  // WS Generic Input:
77  const Agenda& x,
78  // Keywords:
79  const Index& level,
80  const Verbosity& verbosity)
81 {
82  ostringstream os;
83  os << " " << x << "\n";
85  SWITCH_OUTPUT (level, os.str ())
86 }
87 
88 
89 /* Workspace method: Doxygen documentation will be auto-generated */
90 void Print(// WS Generic Input:
91  const ArrayOfGridPos& x,
92  // Keywords:
93  const Index& level,
94  const Verbosity& verbosity)
95 {
96  ostringstream os;
97  for( Index i=0; i<x.nelem(); i++ )
98  os << " " << x[i].idx << " " << x[i].fd[0] << " " << x[i].fd[1]
99  << "\n";
101  SWITCH_OUTPUT (level, os.str ())
102 }
103 
104 
105 /* Workspace method: Doxygen documentation will be auto-generated */
106 void Print(// WS Generic Input:
107  const ArrayOfIndex& x,
108  // Keywords:
109  const Index& level,
110  const Verbosity& verbosity)
111 {
112  ostringstream os;
113  for( Index i=0; i<x.nelem(); i++ )
114  os << x[i] << " ";
116  SWITCH_OUTPUT (level, os.str () << '\n')
117 }
118 
119 
120 /* Workspace method: Doxygen documentation will be auto-generated */
121 void Print(// WS Generic Input:
122  const ArrayOfString& x,
123  // Keywords:
124  const Index& level,
125  const Verbosity& verbosity)
126 {
127  ostringstream os;
128  for( Index i=0; i<x.nelem(); i++ )
129  os << x[i] << '\n';
131  SWITCH_OUTPUT (level, os.str ())
132 }
133 
134 
135 /* Workspace method: Doxygen documentation will be auto-generated */
136 void
137 Print(// WS Generic Input:
138  const Ppath& x,
139  // Keywords:
140  const Index& level,
141  const Verbosity& verbosity)
142 {
144  SWITCH_OUTPUT (level, "dim: ")
145  Print( x.dim, level, verbosity );
146  SWITCH_OUTPUT (level, "np: ")
147  Print( x.np, level, verbosity );
148  SWITCH_OUTPUT (level, "constant: ")
149  Print( x.constant, level, verbosity );
150  SWITCH_OUTPUT (level, "pos: ")
151  Print( x.pos, level, verbosity );
152  SWITCH_OUTPUT (level, "z: ")
153  Print( x.z, level, verbosity );
154  SWITCH_OUTPUT (level, "l_step: ")
155  Print( x.l_step, level, verbosity );
156  SWITCH_OUTPUT (level, "gp_p: ")
157  Print( x.gp_p, level, verbosity );
158  if( x.dim >= 2 )
159  {
160  SWITCH_OUTPUT (level, "gp_lat: ")
161  Print( x.gp_lat, level, verbosity );
162  }
163  if( x.dim == 3 )
164  {
165  SWITCH_OUTPUT (level, "gp_lon: ")
166  Print( x.gp_lon, level, verbosity );
167  }
168  SWITCH_OUTPUT (level, "los: ")
169  Print( x.los, level, verbosity );
170  SWITCH_OUTPUT (level, "background: ")
171  Print( x.background, level, verbosity );
172  if( x.tan_pos.nelem() )
173  {
174  SWITCH_OUTPUT (level, "tan_pos: ")
175  Print( x.tan_pos, level, verbosity );
176  }
177  if( x.geom_tan_pos.nelem() )
178  {
179  SWITCH_OUTPUT (level, "geom_tan_pos: ")
180  Print( x.geom_tan_pos, level, verbosity );
181  }
182 }
183 
184 
185 /* Workspace method: Doxygen documentation will be auto-generated */
186 void Print(// WS Generic Input:
187  const ArrayOfPpath& x,
188  // Keywords:
189  const Index& level,
190  const Verbosity& verbosity)
191 {
193  for( Index i=0; i<x.nelem(); i++ )
194  {
195  ostringstream os;
196  os << "Ppath element " << i << ": ";
197  SWITCH_OUTPUT (level, os.str ())
198  Print( x[i], level, verbosity );
199  }
200 }
201 
202 
203 /* Workspace method: Doxygen documentation will be auto-generated */
204 void Print(// WS Generic Input:
205  const Timer& /* x */,
206  // Keywords:
207  const Index& /* level */,
208  const Verbosity&)
209 {
210 /* ostringstream os;
211  CREATE_OUTS
212  cout << " *" << x_name <<"* =";
213  SWITCH_OUTPUT (level, " *" << x_name << "*:\n")
214  for( Index i=0; i<x.nelem(); i++ )
215  os << x[i] << '\n';
216  SWITCH_OUTPUT (level, os.str ()) */
217 }
218 
219 
220 /* Workspace method: Doxygen documentation will be auto-generated */
221 void PrintWorkspace(// Workspace reference
222  Workspace& ws,
223  // Keywords:
224  const Index& only_allocated,
225  const Index& level,
226  const Verbosity& verbosity)
227 {
228  ostringstream os;
229 
230  if (only_allocated)
231  os << " Allocated workspace variables: \n";
232  else
233  os << " Workspace variables: \n";
234  for (Index i = 0; i < ws.nelem(); i++)
235  {
236  if (!only_allocated)
237  {
238  os << " ";
239  PrintWsvName (os, i);
240  if (ws.is_initialized(i)) os << "+";
241  os << "\n";
242  }
243  else if (ws.is_initialized(i))
244  {
245  os << " ";
246  PrintWsvName (os, i);
247  os << "\n";
248  }
249  }
251  SWITCH_OUTPUT (level, os.str ());
252 }
253 
254 
255 /* Workspace method: Doxygen documentation will be auto-generated */
256 #ifdef TIME_SUPPORT
257 void
258 timerStart (// WS Output
259  Timer& starttime,
260  const Verbosity&)
261 {
262  if ((starttime.realtime = times (&starttime.cputime)) == (clock_t)-1)
263  throw runtime_error ("Timer error: Unable to get current CPU time");
264 }
265 #else
266 void
267 timerStart (// WS Output
268  Timer& /*starttime*/,
269  const Verbosity&)
270 {
271  throw runtime_error ("Timer error: ARTS was compiled without POSIX support, thus timer\nfunctions are not available.");
272 }
273 #endif
274 
275 
276 /* Workspace method: Doxygen documentation will be auto-generated */
277 #ifdef TIME_SUPPORT
278 void
279 timerStop (// WS Input
280  const Timer& starttime,
281  const Verbosity& verbosity)
282 {
284 
285  Timer endtime;
286  static long clktck = 0;
287 
288  if (clktck == 0)
289  if ((clktck = sysconf (_SC_CLK_TCK)) < 0)
290  throw runtime_error ("Timer error: Unable to determine CPU clock ticks");
291 
292  if ((endtime.realtime = times (&endtime.cputime)) == (clock_t)-1)
293  throw runtime_error ("Timer error: Unable to get current CPU time");
294 
295  // FIXME: out1 does not have setf, but we need to set it here
296  cout.setf (ios::showpoint | ios::fixed);
297 
298  out1 << " * CPU time total: " << setprecision (2)
299  << (Numeric)((endtime.cputime.tms_stime - starttime.cputime.tms_stime)
300  + (endtime.cputime.tms_utime - starttime.cputime.tms_utime))
301  / (Numeric)clktck;
302 
303  out1 << " user: " << setprecision (2)
304  << (Numeric)(endtime.cputime.tms_utime - starttime.cputime.tms_utime)
305  / (Numeric)clktck;
306 
307  out1 << " system: " << setprecision (2)
308  << (Numeric)(endtime.cputime.tms_stime - starttime.cputime.tms_stime)
309  / (Numeric)clktck;
310 
311  out1 << "\n real: " << setprecision (2)
312  << (Numeric)(endtime.realtime - starttime.realtime) / (Numeric)clktck;
313 
314  out1 << " " << setprecision (2)
315  << (Numeric)((endtime.cputime.tms_stime - starttime.cputime.tms_stime)
316  + (endtime.cputime.tms_utime - starttime.cputime.tms_utime))
317  / (Numeric)(endtime.realtime - starttime.realtime) * 100.
318  << "%CPU\n";
319 }
320 #else
321 void
322 timerStop (// WS Input
323  const Timer&,
324  const Verbosity&)
325 {
326  throw runtime_error ("Timer error: ARTS was compiled without POSIX support, thus timer\nfunctions are not available.");
327 }
328 #endif
329 
330 /* Workspace method: Doxygen documentation will be auto-generated */
331 void Error(const String& msg, const Verbosity& verbosity)
332 {
334  out0 << msg << "\n";
335  arts_exit();
336 }
337 
338 
339 /* Workspace method: Doxygen documentation will be auto-generated */
340 void Exit(const Verbosity& verbosity)
341 {
343  out1 << " Forced exit.\n";
344  arts_exit (EXIT_SUCCESS);
345 }
346 
347 
348 /* Workspace method: Doxygen documentation will be auto-generated */
349 void Test(const Verbosity& verbosity)
350 {
351  // This function can be used to test stuff.
352 
353  Vector x( 1, 5, 1 );
354 
355  Vector y( 0.5, 6, 1 );
356 
357  ArrayOfGridPos gp(y.nelem());
358 
359  gridpos( gp, x, y, 1 );
360 
361  Print( gp, 0, verbosity );
362 }
363 
364 
365 /* Workspace method: Doxygen documentation will be auto-generated */
366 void verbosityInit(// WS Output:
367  Verbosity& verbosity)
368 {
370 
374 }
375 
376 
377 /* Workspace method: Doxygen documentation will be auto-generated */
378 void verbositySet(// WS Output:
379  Verbosity& verbosity,
380  // WS Generic Input:
381  const Index& agenda,
382  const Index& screen,
383  const Index& file)
384 {
385  verbosity.set_agenda_verbosity(agenda);
386  verbosity.set_screen_verbosity(screen);
387  verbosity.set_file_verbosity(file);
388 }
389 
390 
391 /* Workspace method: Doxygen documentation will be auto-generated */
392 void verbositySetAgenda(// WS Output:
393  Verbosity& verbosity,
394  // WS Generic Input:
395  const Index& level)
396 {
397  verbosity.set_agenda_verbosity(level);
398 }
399 
400 
401 /* Workspace method: Doxygen documentation will be auto-generated */
402 void verbositySetFile(// WS Output:
403  Verbosity& verbosity,
404  // WS Generic Input:
405  const Index& level)
406 {
407  verbosity.set_file_verbosity(level);
408 }
409 
410 
411 /* Workspace method: Doxygen documentation will be auto-generated */
412 void verbositySetScreen(// WS Output:
413  Verbosity& verbosity,
414  // WS Generic Input:
415  const Index& level)
416 {
417  verbosity.set_screen_verbosity(level);
418 }
Timer
Definition: m_general.h:54
timerStart
void timerStart(Timer &, const Verbosity &)
WORKSPACE METHOD: timerStart.
Definition: m_general.cc:267
Exit
void Exit(const Verbosity &verbosity)
WORKSPACE METHOD: Exit.
Definition: m_general.cc:340
Print
void Print(Workspace &ws, const Agenda &x, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:75
gridpos
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
Definition: interpolation.cc:167
verbositySetFile
void verbositySetFile(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetFile.
Definition: m_general.cc:402
Ppath::background
String background
Definition: ppath.h:70
SWITCH_OUTPUT
#define SWITCH_OUTPUT(x, y)
Definition: m_general.h:44
array.h
This file contains the definition of Array.
Ppath
The structure to describe a propagation path and releated quantities.
Definition: ppath.h:59
Ppath::gp_p
ArrayOfGridPos gp_p
Definition: ppath.h:66
CREATE_OUT1
#define CREATE_OUT1
Definition: messages.h:206
Agenda
The Agenda class.
Definition: agenda_class.h:44
Array< GridPos >
verbositySetAgenda
void verbositySetAgenda(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetAgenda.
Definition: m_general.cc:392
Test
void Test(const Verbosity &verbosity)
WORKSPACE METHOD: Test.
Definition: m_general.cc:349
CREATE_OUT0
#define CREATE_OUT0
Definition: messages.h:205
Ppath::gp_lat
ArrayOfGridPos gp_lat
Definition: ppath.h:67
messages.h
Declarations having to do with the four output streams.
verbosity_at_launch
Verbosity verbosity_at_launch
Definition: messages.cc:34
_U_
#define _U_
Definition: config.h:158
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
Ppath::los
Matrix los
Definition: ppath.h:69
verbositySetScreen
void verbositySetScreen(Verbosity &verbosity, const Index &level)
WORKSPACE METHOD: verbositySetScreen.
Definition: m_general.cc:412
Ppath::gp_lon
ArrayOfGridPos gp_lon
Definition: ppath.h:68
timerStop
void timerStop(const Timer &, const Verbosity &)
WORKSPACE METHOD: timerStop.
Definition: m_general.cc:322
Ppath::np
Index np
Definition: ppath.h:61
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:175
Ppath::z
Vector z
Definition: ppath.h:64
Ppath::tan_pos
Vector tan_pos
Definition: ppath.h:71
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Verbosity
Definition: messages.h:50
Ppath::l_step
Vector l_step
Definition: ppath.h:65
Verbosity::set_agenda_verbosity
void set_agenda_verbosity(Index v)
Definition: messages.h:69
Verbosity::get_agenda_verbosity
Index get_agenda_verbosity() const
Definition: messages.h:64
verbositySet
void verbositySet(Verbosity &verbosity, const Index &agenda, const Index &screen, const Index &file)
WORKSPACE METHOD: verbositySet.
Definition: m_general.cc:378
math_funcs.h
Workspace::nelem
Index nelem()
Definition: workspace_ng.h:91
make_vector.h
The class MakeVector is a special kind of Vector that can be initialized explicitly from one or more ...
INCLUDE
void INCLUDE(const Verbosity &)
WORKSPACE METHOD: INCLUDE.
Definition: m_general.cc:69
PrintWsvName
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:105
PrintWorkspace
void PrintWorkspace(Workspace &ws, const Index &only_allocated, const Index &level, const Verbosity &verbosity)
Definition: m_general.cc:221
Error
void Error(const String &msg, const Verbosity &verbosity)
WORKSPACE METHOD: Error.
Definition: m_general.cc:331
Ppath::constant
Numeric constant
Definition: ppath.h:62
workspace_ng.h
This file contains the declaration and partly the implementation of the workspace class.
Verbosity::set_file_verbosity
void set_file_verbosity(Index v)
Definition: messages.h:71
Workspace
Workspace class.
Definition: workspace_ng.h:47
Verbosity::get_screen_verbosity
Index get_screen_verbosity() const
Definition: messages.h:65
Ppath::geom_tan_pos
Vector geom_tan_pos
Definition: ppath.h:72
Workspace::is_initialized
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:79
Verbosity::get_file_verbosity
Index get_file_verbosity() const
Definition: messages.h:66
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
verbosityInit
void verbosityInit(Verbosity &verbosity)
WORKSPACE METHOD: verbosityInit.
Definition: m_general.cc:366
arts_exit
void arts_exit(int status)
This is the exit function of ARTS.
Definition: arts.cc:42
check_input.h
Ppath::dim
Index dim
Definition: ppath.h:60
Vector
The Vector class.
Definition: matpackI.h:555
Verbosity::set_screen_verbosity
void set_screen_verbosity(Index v)
Definition: messages.h:70
Ppath::pos
Matrix pos
Definition: ppath.h:63
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.
mystring.h
This file contains the definition of String, the ARTS string class.
CREATE_OUTS
#define CREATE_OUTS
Definition: messages.h:210
arts.h
The global header file for ARTS.
m_general.h
Template functions for general supergeneric ws methods.