ARTS  2.2.66
check_input.h
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 
36 #ifndef checkinput_h
37 #define checkinput_h
38 
39 
40 
41 /*===========================================================================
42  === External declarations
43  ===========================================================================*/
44 
45 #include "agenda_class.h"
46 #include "exceptions.h"
47 #include "matpackVII.h"
48 #include "mystring.h"
49 #include "gridded_fields.h"
50 //#include <cfloat>
51 
52 
53 /*===========================================================================
54  === Functions in check_input.cc
55  ===========================================================================*/
56 
57 void chk_if_bool(
58  const String& x_name,
59  const Index& x );
60 
61 void chk_if_in_range(
62  const String& x_name,
63  const Index& x,
64  const Index& x_low,
65  const Index& x_high );
66 
67 void chk_if_increasing(
68  const String& x_name,
69  const ArrayOfIndex& x );
70 
71 void chk_not_negative(
72  const String& x_name,
73  const Numeric& x );
74 
75 void chk_if_in_range(
76  const String& x_name,
77  const Numeric& x,
78  const Numeric& x_low,
79  const Numeric& x_high );
80 
81 void chk_vector_length(
82  const String& x_name,
84  const Index& l );
85 
86 void chk_vector_length(
87  const String& x1_name,
88  const String& x2_name,
89  ConstVectorView x1,
90  ConstVectorView x2 );
91 
92 void chk_if_increasing(
93  const String& x_name,
94  ConstVectorView x );
95 
96 void chk_if_decreasing(
97  const String& x_name,
98  ConstVectorView x );
99 
100 void chk_if_equal(
101  const String& x1_name,
102  const String& x2_name,
103  ConstVectorView v1,
104  ConstVectorView v2,
105  Numeric margin=1e-6);
106 
107 void chk_matrix_ncols(
108  const String& x_name,
109  ConstMatrixView x,
110  const Index& l );
111 
112 void chk_matrix_nrows(
113  const String& x_name,
114  ConstMatrixView x,
115  const Index& l );
116 
123 class runtime_error_not_found : public runtime_error {
124 public:
125  runtime_error_not_found(const string& s) : runtime_error(s) {}
126 };
127 
134 class runtime_error_not_unique : public runtime_error {
135 public:
136  runtime_error_not_unique(const string& s) : runtime_error(s) {}
137 };
138 
139 /*===========================================================================
140  === Template Functions for Arrays
141  ===========================================================================*/
142 
144 
163 template <class T>
164 Index chk_contains( const String& x_name,
165  const Array<T>& x,
166  const T& what )
167 {
168  // To generate error messages:
169  ostringstream os;
170 
171  // To store the positions:
172  ArrayOfIndex pos;
173 
174  // Find all positions of what in x and store in pos:
175  find_all( pos, x, what );
176 
177  switch ( pos.nelem() ){
178 
179  case 0:
180  // Not found.
181  os << "The array *" << x_name
182  << "* must contain the element " << what << ",\n"
183  << "but it does not.";
184  throw runtime_error_not_found( os.str() );
185  break;
186 
187  case 1:
188  // Found once, this is what we want!
189  return pos[0];
190 
191  default:
192  // Found more than once.
193  os << "The array *" << x_name
194  << "* must contain the element " << what << "\n"
195  << "exactly once, but it does contain it "
196  << pos.nelem() << " times.";
197  throw runtime_error_not_unique( os.str() );
198  break;
199  }
200 
201  return -1;
202 }
203 
205 
220 template <class T>
221 void chk_size( const String& x_name,
222  const Array<T>& x,
223  const Index& c )
224 {
225  if ( x.nelem() != c )
226  {
227  ostringstream os;
228  os << "The array *" << x_name << "*\n"
229  << "does not have the right size.\n"
230  << "The size should be: " << c << "\n"
231  << "but it is: " << x.nelem();
232  throw runtime_error( os.str() );
233  }
234 }
235 
236 
237 
238 /*===========================================================================
239  === Functions for Tensors
240  ===========================================================================*/
241 
242 void chk_size( const String& x_name,
243  ConstVectorView x,
244  const Index& c );
245 
246 void chk_size( const String& x_name,
247  ConstMatrixView x,
248  const Index& r,
249  const Index& c );
250 
251 void chk_size( const String& x_name,
253  const Index& p,
254  const Index& r,
255  const Index& c );
256 
257 void chk_size( const String& x_name,
259  const Index& b,
260  const Index& p,
261  const Index& r,
262  const Index& c );
263 
264 void chk_size( const String& x_name,
266  const Index& s,
267  const Index& b,
268  const Index& p,
269  const Index& r,
270  const Index& c );
271 
272 void chk_size( const String& x_name,
274  const Index& v,
275  const Index& s,
276  const Index& b,
277  const Index& p,
278  const Index& r,
279  const Index& c );
280 
281 void chk_size( const String& x_name,
283  const Index& l,
284  const Index& v,
285  const Index& s,
286  const Index& b,
287  const Index& p,
288  const Index& r,
289  const Index& c );
290 
291 void chk_not_empty(
292  const String& x_name,
293  const Agenda& x );
294 
296  Index& ing_max,
297  const String& which_interpolation,
298  ConstVectorView old_grid,
299  ConstVectorView new_grid,
300  ConstVectorView data,
301  const Index order=1);
302 
304  Index& ing_max,
305  const String& which_interpolation,
306  ConstVectorView old_grid,
307  ConstVectorView new_grid,
308  const Index order=1);
309 
311  Index& ing_max,
312  const String& which_interpolation,
313  ConstVectorView old_pgrid,
314  ConstVectorView new_pgrid,
315  const Index order=1);
316 
318  Index& ing_max,
319  const String& which_interpolation,
320  ConstVectorView old_grid,
321  ConstVectorView new_grid,
322  ConstVectorView data );
323 
324 void chk_interpolation_grids(const String& which_interpolation,
325  ConstVectorView old_grid,
326  ConstVectorView new_grid,
327  const Index order=1,
328  const Numeric& extpolfac=0.5,
329  const bool islog=false);
330 
331 void chk_interpolation_grids(const String& which_interpolation,
332  ConstVectorView old_grid,
333  const Numeric& new_grid,
334  const Index order=1,
335  const Numeric& extpolfac=0.5 );
336 
337 void chk_interpolation_pgrids(const String& which_interpolation,
338  ConstVectorView old_pgrid,
339  ConstVectorView new_pgrid,
340  const Index order=1,
341  const Numeric& extpolfac=0.5 );
342 
343 void chk_atm_grids(
344  const Index& dim,
345  ConstVectorView p_grid,
346  ConstVectorView lat_grid,
347  ConstVectorView lon_grid );
348 
349 void chk_atm_field(
350  const String& x_name,
351  ConstTensor3View x,
352  const Index& dim,
353  ConstVectorView p_grid,
354  ConstVectorView lat_grid,
355  ConstVectorView lon_grid,
356  const bool& chk_lat90 = 1);
357 
358 void chk_atm_field(
359  const String& x_name,
360  ConstTensor4View x,
361  const Index& dim,
362  const Index& nspecies,
363  ConstVectorView p_grid,
364  ConstVectorView lat_grid,
365  ConstVectorView lon_grid );
366 
368  const String& x1_name,
369  ConstTensor3View x1,
370  const String& x2_name,
371  ConstTensor3View x2,
372  const Index& dim,
373  ConstVectorView lat_grid,
374  const Numeric& threshold = 1e-3 );
375 // const Numeric& threshold = 2*DBL_EPSILON );
376 
377 void chk_latlon_true(
378  const Index& atmosphere_dim,
379  ConstVectorView lat_grid,
380  ConstVectorView lat_true,
381  ConstVectorView lon_true );
382 
383 void chk_atm_surface(
384  const String& x_name,
385  const Matrix& x,
386  const Index& dim,
387  ConstVectorView lat_grid,
388  ConstVectorView lon_grid );
389 
390 void chk_rte_pos(
391  const Index& atmosphere_dim,
392  ConstVectorView rte_pos,
393  const bool& is_rte_pos2=false );
394 
395 void chk_rte_los(
396  const Index& atmosphere_dim,
397  ConstVectorView rte_los );
398 
400  const Index gridindex,
401  const String& gridname);
402 
404  Workspace& ws,
405  const Agenda& blackbody_radiation_agenda );
406 
407 #endif // checkinput_h
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
Definition: check_input.cc:768
void chk_atm_surface(const String &x_name, const Matrix &x, const Index &dim, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_surface
void chk_atm_vecfield_lat90(const String &x1_name, ConstTensor3View x1, const String &x2_name, ConstTensor3View x2, const Index &dim, ConstVectorView lat_grid, const Numeric &threshold=1e-3)
chk_atm_vecfield_lat90
The Agenda class.
Definition: agenda_class.h:44
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:402
Index nelem() const
Number of elements.
Definition: array.h:176
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
Definition: check_input.cc:431
A constant view of a Tensor7.
Definition: matpackVII.h:162
void chk_if_equal(const String &x1_name, const String &x2_name, ConstVectorView v1, ConstVectorView v2, Numeric margin=1e-6)
chk_if_equal
Definition: check_input.cc:356
A constant view of a Tensor6.
Definition: matpackVI.h:159
void chk_interpolation_pgrids_loose_no_data_check(Index &ing_min, Index &ing_max, const String &which_interpolation, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Index order=1)
Check log pressure interpolation grids.
Definition: check_input.cc:989
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:166
void chk_latlon_true(const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lat_true, ConstVectorView lon_true)
chk_latlon_true
void chk_size(const String &x_name, const Array< T > &x, const Index &c)
Check the size of an array.
Definition: check_input.h:221
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:132
void chk_interpolation_grids_loose(Index &ing_min, Index &ing_max, const String &which_interpolation, ConstVectorView old_grid, ConstVectorView new_grid, ConstVectorView data, const Index order=1)
Check interpolation grids.
Definition: check_input.cc:819
A constant view of a Tensor4.
Definition: matpackIV.h:141
void chk_interpolation_grids(const String &which_interpolation, ConstVectorView old_grid, ConstVectorView new_grid, const Index order=1, const Numeric &extpolfac=0.5, const bool islog=false)
Check interpolation grids.
bool chk_if_std_blackbody_agenda(Workspace &ws, const Agenda &blackbody_radiation_agenda)
Checks if blackbody_radiation_agenda returns frequency based radiance.
The implementation for String, the ARTS string class.
Definition: mystring.h:63
void chk_interpolation_grids_loose_check_data(Index &ing_min, Index &ing_max, const String &which_interpolation, ConstVectorView old_grid, ConstVectorView new_grid, ConstVectorView data)
Check interpolation grids.
Index chk_contains(const String &x_name, const Array< T > &x, const T &what)
Check if an array contains a value.
Definition: check_input.h:164
Declarations for agendas.
runtime_error_not_unique(const string &s)
Definition: check_input.h:136
void chk_rte_pos(const Index &atmosphere_dim, ConstVectorView rte_pos, const bool &is_rte_pos2=false)
chk_rte_pos
Subclasses of runtime_error.
Definition: check_input.h:134
The declarations of all the exception classes.
void chk_atm_grids(const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_grids
void chk_interpolation_grids_loose_no_data_check(Index &ing_min, Index &ing_max, const String &which_interpolation, ConstVectorView old_grid, ConstVectorView new_grid, const Index order=1)
Check interpolation grids.
Definition: check_input.cc:859
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:233
A constant view of a Tensor5.
Definition: matpackV.h:152
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
The Matrix class.
Definition: matpackI.h:788
void chk_rte_los(const Index &atmosphere_dim, ConstVectorView rte_los)
chk_rte_los
void chk_atm_field(const String &x_name, ConstTensor3View x, const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, const bool &chk_lat90=1)
chk_atm_field (simple fields)
This can be used to make arrays out of anything.
Definition: array.h:40
void chk_if_in_range(const String &x_name, const Index &x, const Index &x_low, const Index &x_high)
chk_if_in_range
Definition: check_input.cc:101
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:73
A constant view of a Tensor3.
Definition: matpackIII.h:139
A constant view of a Vector.
Definition: matpackI.h:292
A constant view of a Matrix.
Definition: matpackI.h:596
Workspace class.
Definition: workspace_ng.h:47
void chk_interpolation_pgrids(const String &which_interpolation, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Index order=1, const Numeric &extpolfac=0.5)
Check log pressure interpolation grids.
Implementation of gridded fields.
Subclasses of runtime_error.
Definition: check_input.h:123
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition: array.h:306
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:327
runtime_error_not_found(const string &s)
Definition: check_input.h:125
This file contains the definition of String, the ARTS string class.
void chk_griddedfield_gridname(const GriddedField &gf, const Index gridindex, const String &gridname)
Check name of grid in GriddedField.