ARTS  2.4.0(git:4fb77825)
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,
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,
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,
319 
320 void chk_atm_field(const String& x_name,
322  const Index& dim,
326  const bool& chk_lat90 = 1);
327 
328 void chk_atm_field(const String& x_name,
330  const Index& dim,
331  const Index& nspecies,
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,
343  const Numeric& threshold = 1e-3);
344 // const Numeric& threshold = 2*DBL_EPSILON );
345 
350 
351 void chk_atm_surface(const String& x_name,
352  const Matrix& x,
353  const Index& dim,
356 
357 void chk_rte_pos(const Index& atmosphere_dim,
359  const bool& is_rte_pos2 = false);
360 
362 
364  const Index gridindex,
365  const String& gridname);
366 
367 void chk_met_mm_backend(const Matrix& bdsp);
368 
369 #endif // checkinput_h
Matrix
The Matrix class.
Definition: matpackI.h:1193
ARTS::Var::atmosphere_dim
Index atmosphere_dim(Workspace &ws) noexcept
Definition: autoarts.h:2510
gridded_fields.h
Implementation of gridded fields.
exceptions.h
The declarations of all the exception classes.
GriddedField
Definition: gridded_fields.h:52
chk_interpolation_grids
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
ARTS::Var::lat_grid
Vector lat_grid(Workspace &ws) noexcept
Definition: autoarts.h:3962
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:147
chk_interpolation_grids_loose
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
chk_interpolation_pgrids
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.
Definition: check_input.cc:1166
chk_vector_length
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:281
chk_interpolation_grids_loose_no_data_check
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
chk_atm_surface
void chk_atm_surface(const String &x_name, const Matrix &x, const Index &dim, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_surface
Definition: check_input.cc:1689
runtime_error_not_unique::runtime_error_not_unique
runtime_error_not_unique(const string &s)
Definition: check_input.h:121
chk_griddedfield_gridname
void chk_griddedfield_gridname(const GriddedField &gf, const Index gridindex, const String &gridname)
Check name of grid in GriddedField.
Definition: check_input.cc:1891
runtime_error_not_unique
Subclasses of runtime_error.
Definition: check_input.h:119
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
chk_not_empty
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
Definition: check_input.cc:694
chk_if_in_range_exclude
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
chk_if_in_range_exclude_high
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
chk_atm_grids
void chk_atm_grids(const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_grids
Definition: check_input.cc:1201
chk_if_bool
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:65
Agenda
The Agenda class.
Definition: agenda_class.h:44
chk_interpolation_pgrids_loose_no_data_check
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
ARTS::Var::lon_true
Vector lon_true(Workspace &ws) noexcept
Definition: autoarts.h:4113
chk_not_negative
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:143
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:133
Array
This can be used to make arrays out of anything.
Definition: array.h:108
agenda_class.h
Declarations for agendas.
ARTS::Var::rte_pos
Vector rte_pos(Workspace &ws) noexcept
Definition: autoarts.h:5672
chk_met_mm_backend
void chk_met_mm_backend(const Matrix &bdsp)
Check met_mm_backend.
Definition: check_input.cc:1931
my_basic_string< char >
chk_if_in_range_exclude_low
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
chk_size
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
chk_rte_los
void chk_rte_los(const Index &atmosphere_dim, ConstVectorView rte_los)
chk_rte_los
Definition: check_input.cc:1839
chk_atm_vecfield_lat90
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
Definition: check_input.cc:1540
chk_if_equal
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
ARTS::Var::rte_los
Vector rte_los(Workspace &ws) noexcept
Definition: autoarts.h:5651
ARTS::Var::p_grid
Vector p_grid(Workspace &ws) noexcept
Definition: autoarts.h:4763
runtime_error_not_found::runtime_error_not_found
runtime_error_not_found(const string &s)
Definition: check_input.h:110
ConstTensor6View
A constant view of a Tensor6.
Definition: matpackVI.h:149
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ARTS::Var::lat_true
Vector lat_true(Workspace &ws) noexcept
Definition: autoarts.h:3985
runtime_error_not_found
Subclasses of runtime_error.
Definition: check_input.h:108
chk_matrix_nrows
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
Definition: check_input.cc:441
ARTS::Var::lon_grid
Vector lon_grid(Workspace &ws) noexcept
Definition: autoarts.h:4090
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:982
chk_if_increasing
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:117
chk_if_decreasing
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:358
chk_interpolation_grids_loose_check_data
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
chk_latlon_true
void chk_latlon_true(const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lat_true, ConstVectorView lon_true)
chk_latlon_true
Definition: check_input.cc:1652
find_all
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition: array.h:314
chk_rte_pos
void chk_rte_pos(const Index &atmosphere_dim, ConstVectorView rte_pos, const bool &is_rte_pos2=false)
chk_rte_pos
Definition: check_input.cc:1770
x1
#define x1
Definition: lineshapemodel.h:414
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:132
chk_contains
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
chk_matrix_ncols
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:419
ARTS::Var::x
Vector x(Workspace &ws) noexcept
Definition: autoarts.h:7346
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
chk_if_in_range
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
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:476
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195
chk_atm_field
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)
Definition: check_input.cc:1268
x2
#define x2
Definition: lineshapemodel.h:415
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:143
mystring.h
This file contains the definition of String, the ARTS string class.
matpackVII.h