ARTS  2.3.1285(git:92a29ea9-dirty)
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  === File description
22  ===========================================================================*/
23 
32 #ifndef checkinput_h
33 #define checkinput_h
34 
35 /*===========================================================================
36  === External declarations
37  ===========================================================================*/
38 
39 #include "agenda_class.h"
40 #include "exceptions.h"
41 #include "gridded_fields.h"
42 #include "matpackVII.h"
43 #include "mystring.h"
44 //#include <cfloat>
45 
46 /*===========================================================================
47  === Functions in check_input.cc
48  ===========================================================================*/
49 
50 void chk_if_bool(const String& x_name, const Index& x);
51 
52 void chk_if_in_range(const String& x_name,
53  const Index& x,
54  const Index& x_low,
55  const Index& x_high);
56 
57 void chk_if_increasing(const String& x_name, const ArrayOfIndex& x);
58 
59 void chk_not_negative(const String& x_name, const Numeric& x);
60 
61 void chk_if_in_range(const String& x_name,
62  const Numeric& x,
63  const Numeric& x_low,
64  const Numeric& x_high);
65 
66 void chk_if_in_range_exclude_low(const String& x_name,
67  const Numeric& x,
68  const Numeric& x_low,
69  const Numeric& x_high);
70 
71 void chk_if_in_range_exclude_high(const String& x_name,
72  const Numeric& x,
73  const Numeric& x_low,
74  const Numeric& x_high);
75 
76 void chk_if_in_range_exclude(const String& x_name,
77  const Numeric& x,
78  const Numeric& x_low,
79  const Numeric& x_high);
80 
81 void chk_vector_length(const String& x_name, ConstVectorView x, const Index& l);
82 
83 void chk_vector_length(const String& x1_name,
84  const String& x2_name,
87 
88 void chk_if_increasing(const String& x_name, ConstVectorView x);
89 
90 void chk_if_decreasing(const String& x_name, ConstVectorView x);
91 
92 void chk_if_equal(const String& x1_name,
93  const String& x2_name,
94  ConstVectorView v1,
95  ConstVectorView v2,
96  Numeric margin = 1e-6);
97 
98 void chk_matrix_ncols(const String& x_name, ConstMatrixView x, const Index& l);
99 
100 void chk_matrix_nrows(const String& x_name, ConstMatrixView x, const Index& l);
101 
108 class runtime_error_not_found : public runtime_error {
109  public:
110  runtime_error_not_found(const string& s) : runtime_error(s) {}
111 };
112 
119 class runtime_error_not_unique : public runtime_error {
120  public:
121  runtime_error_not_unique(const string& s) : runtime_error(s) {}
122 };
123 
124 /*===========================================================================
125  === Template Functions for Arrays
126  ===========================================================================*/
127 
129 
148 template <class T>
149 Index chk_contains(const String& x_name, const Array<T>& x, const T& what) {
150  // To generate error messages:
151  ostringstream os;
152 
153  // To store the positions:
154  ArrayOfIndex pos;
155 
156  // Find all positions of what in x and store in pos:
157  find_all(pos, x, what);
158 
159  switch (pos.nelem()) {
160  case 0:
161  // Not found.
162  os << "The array *" << x_name << "* must contain the element " << what
163  << ",\n"
164  << "but it does not.";
165  throw runtime_error_not_found(os.str());
166  break;
167 
168  case 1:
169  // Found once, this is what we want!
170  return pos[0];
171 
172  default:
173  // Found more than once.
174  os << "The array *" << x_name << "* must contain the element " << what
175  << "\n"
176  << "exactly once, but it does contain it " << pos.nelem() << " times.";
177  throw runtime_error_not_unique(os.str());
178  break;
179  }
180 
181  return -1;
182 }
183 
185 
200 template <class T>
201 void chk_size(const String& x_name, const Array<T>& x, const Index& c) {
202  if (x.nelem() != c) {
203  ostringstream os;
204  os << "The array *" << x_name << "*\n"
205  << "does not have the right size.\n"
206  << "The size should be: " << c << "\n"
207  << "but it is: " << x.nelem();
208  throw runtime_error(os.str());
209  }
210 }
211 
212 /*===========================================================================
213  === Functions for Tensors
214  ===========================================================================*/
215 
216 void chk_size(const String& x_name, ConstVectorView x, const Index& c);
217 
218 void chk_size(const String& x_name,
219  ConstMatrixView x,
220  const Index& r,
221  const Index& c);
222 
223 void chk_size(const String& x_name,
225  const Index& p,
226  const Index& r,
227  const Index& c);
228 
229 void chk_size(const String& x_name,
231  const Index& b,
232  const Index& p,
233  const Index& r,
234  const Index& c);
235 
236 void chk_size(const String& x_name,
238  const Index& s,
239  const Index& b,
240  const Index& p,
241  const Index& r,
242  const Index& c);
243 
244 void chk_size(const String& x_name,
246  const Index& v,
247  const Index& s,
248  const Index& b,
249  const Index& p,
250  const Index& r,
251  const Index& c);
252 
253 void chk_size(const String& x_name,
255  const Index& l,
256  const Index& v,
257  const Index& s,
258  const Index& b,
259  const Index& p,
260  const Index& r,
261  const Index& c);
262 
263 void chk_not_empty(const String& x_name, const Agenda& x);
264 
266  Index& ing_max,
267  const String& which_interpolation,
268  ConstVectorView old_grid,
269  ConstVectorView new_grid,
271  const Index order = 1);
272 
274  Index& ing_min,
275  Index& ing_max,
276  const String& which_interpolation,
277  ConstVectorView old_grid,
278  ConstVectorView new_grid,
279  const Index order = 1);
280 
282  Index& ing_min,
283  Index& ing_max,
284  const String& which_interpolation,
285  ConstVectorView old_pgrid,
286  ConstVectorView new_pgrid,
287  const Index order = 1);
288 
290  Index& ing_max,
291  const String& which_interpolation,
292  ConstVectorView old_grid,
293  ConstVectorView new_grid,
294  ConstVectorView data);
295 
296 void chk_interpolation_grids(const String& which_interpolation,
297  ConstVectorView old_grid,
298  ConstVectorView new_grid,
299  const Index order = 1,
300  const Numeric& extpolfac = 0.5,
301  const bool islog = false);
302 
303 void chk_interpolation_grids(const String& which_interpolation,
304  ConstVectorView old_grid,
305  const Numeric& new_grid,
306  const Index order = 1,
307  const Numeric& extpolfac = 0.5);
308 
309 void chk_interpolation_pgrids(const String& which_interpolation,
310  ConstVectorView old_pgrid,
311  ConstVectorView new_pgrid,
312  const Index order = 1,
313  const Numeric& extpolfac = 0.5);
314 
315 void chk_atm_grids(const Index& dim,
316  ConstVectorView p_grid,
317  ConstVectorView lat_grid,
318  ConstVectorView lon_grid);
319 
320 void chk_atm_field(const String& x_name,
322  const Index& dim,
323  ConstVectorView p_grid,
324  ConstVectorView lat_grid,
325  ConstVectorView lon_grid,
326  const bool& chk_lat90 = 1);
327 
328 void chk_atm_field(const String& x_name,
330  const Index& dim,
331  const Index& nspecies,
332  ConstVectorView p_grid,
333  ConstVectorView lat_grid,
334  ConstVectorView lon_grid,
335  const bool& check_nan = 1);
336 
337 void chk_atm_vecfield_lat90(const String& x1_name,
339  const String& x2_name,
341  const Index& dim,
342  ConstVectorView lat_grid,
343  const Numeric& threshold = 1e-3);
344 // const Numeric& threshold = 2*DBL_EPSILON );
345 
346 void chk_latlon_true(const Index& atmosphere_dim,
347  ConstVectorView lat_grid,
348  ConstVectorView lat_true,
349  ConstVectorView lon_true);
350 
351 void chk_atm_surface(const String& x_name,
352  const Matrix& x,
353  const Index& dim,
354  ConstVectorView lat_grid,
355  ConstVectorView lon_grid);
356 
357 void chk_rte_pos(const Index& atmosphere_dim,
358  ConstVectorView rte_pos,
359  const bool& is_rte_pos2 = false);
360 
361 void chk_rte_los(const Index& atmosphere_dim, ConstVectorView rte_los);
362 
364  const Index gridindex,
365  const String& gridname);
366 
367 void chk_met_mm_backend(const Matrix& bdsp);
368 
369 #endif // checkinput_h
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
Definition: check_input.cc:694
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
#define x2
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:419
Index nelem() const
Number of elements.
Definition: array.h:195
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
Definition: check_input.cc:441
void chk_met_mm_backend(const Matrix &bdsp)
Check met_mm_backend.
A constant view of a Tensor7.
Definition: matpackVII.h:147
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:381
A constant view of a Tensor6.
Definition: matpackVI.h:149
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:890
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:143
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:201
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:117
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
#define x1
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:735
A constant view of a Tensor4.
Definition: matpackIV.h:133
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.
Definition: check_input.cc:989
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.
Definition: check_input.cc:930
_CS_string_type str() const
Definition: sstream.h:491
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:149
Declarations for agendas.
runtime_error_not_unique(const string &s)
Definition: check_input.h:121
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:119
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:773
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:281
A constant view of a Tensor5.
Definition: matpackV.h:143
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
The Matrix class.
Definition: matpackI.h:1193
void chk_if_in_range_exclude(const String &x_name, const Numeric &x, const Numeric &x_low, const Numeric &x_high)
chk_if_in_range_exclude
Definition: check_input.cc:251
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:89
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:65
A constant view of a Tensor3.
Definition: matpackIII.h:132
A constant view of a Vector.
Definition: matpackI.h:476
A constant view of a Matrix.
Definition: matpackI.h:982
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.
void chk_if_in_range_exclude_low(const String &x_name, const Numeric &x, const Numeric &x_low, const Numeric &x_high)
chk_if_in_range_exclude_low
Definition: check_input.cc:195
Implementation of gridded fields.
Subclasses of runtime_error.
Definition: check_input.h:108
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition: array.h:314
void chk_if_in_range_exclude_high(const String &x_name, const Numeric &x, const Numeric &x_low, const Numeric &x_high)
chk_if_in_range_exclude_high
Definition: check_input.cc:223
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:358
runtime_error_not_found(const string &s)
Definition: check_input.h:110
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.