ARTS 2.5.11 (git: 725533f0)
check_input.h
Go to the documentation of this file.
1/*===========================================================================
2 === File description
3 ===========================================================================*/
4
13#ifndef checkinput_h
14#define checkinput_h
15
16/*===========================================================================
17 === External declarations
18 ===========================================================================*/
19
20#include "exceptions.h"
21#include "gridded_fields.h"
22#include "matpack_data.h"
23#include "mystring.h"
24
26class Agenda;
27
28/*===========================================================================
29 === Functions in check_input.cc
30 ===========================================================================*/
31
32void chk_if_bool(const String& x_name, const Index& x);
33
34void chk_if_in_range(const String& x_name,
35 const Index& x,
36 const Index& x_low,
37 const Index& x_high);
38
39void chk_if_increasing(const String& x_name, const ArrayOfIndex& x);
40
41void chk_not_negative(const String& x_name, const Numeric& x);
42
43void chk_if_in_range(const String& x_name,
44 const Numeric& x,
45 const Numeric& x_low,
46 const Numeric& x_high);
47
48void chk_if_in_range_exclude_low(const String& x_name,
49 const Numeric& x,
50 const Numeric& x_low,
51 const Numeric& x_high);
52
53void chk_if_in_range_exclude_high(const String& x_name,
54 const Numeric& x,
55 const Numeric& x_low,
56 const Numeric& x_high);
57
58void chk_if_in_range_exclude(const String& x_name,
59 const Numeric& x,
60 const Numeric& x_low,
61 const Numeric& x_high);
62
63void chk_vector_length(const String& x_name, ConstVectorView x, const Index& l);
64
65void chk_vector_length(const String& x1_name,
66 const String& x2_name,
67 ConstVectorView x1,
68 ConstVectorView x2);
69
70void chk_if_increasing(const String& x_name, ConstVectorView x);
71
72void chk_if_decreasing(const String& x_name, ConstVectorView x);
73
74void chk_if_equal(const String& x1_name,
75 const String& x2_name,
76 ConstVectorView v1,
77 ConstVectorView v2,
78 Numeric margin = 1e-6);
79
80void chk_matrix_ncols(const String& x_name, ConstMatrixView x, const Index& l);
81
82void chk_matrix_nrows(const String& x_name, ConstMatrixView x, const Index& l);
83
90class runtime_error_not_found : public std::runtime_error {
91 public:
92 runtime_error_not_found(const std::string& s) : std::runtime_error(s) {}
93};
94
101class runtime_error_not_unique : public std::runtime_error {
102 public:
103 runtime_error_not_unique(const std::string& s) : std::runtime_error(s) {}
104};
105
106/*===========================================================================
107 === Template Functions for Arrays
108 ===========================================================================*/
109
111
130template <class T>
131Index chk_contains(const String& x_name, const Array<T>& x, const T& what) {
132 // To generate error messages:
133 std::ostringstream os;
134
135 // To store the positions:
136 ArrayOfIndex pos;
137
138 // Find all positions of what in x and store in pos:
139 find_all(pos, x, what);
140
141 switch (pos.nelem()) {
142 case 0:
143 // Not found.
144 os << "The array *" << x_name << "* must contain the element " << what
145 << ",\n"
146 << "but it does not.";
147 throw runtime_error_not_found(os.str());
148 break;
149
150 case 1:
151 // Found once, this is what we want!
152 return pos[0];
153
154 default:
155 // Found more than once.
156 os << "The array *" << x_name << "* must contain the element " << what
157 << "\n"
158 << "exactly once, but it does contain it " << pos.nelem() << " times.";
159 throw runtime_error_not_unique(os.str());
160 break;
161 }
162
163 return -1;
164}
165
167
182template <class T>
183void chk_size(const String& x_name, const Array<T>& x, const Index& c) {
184 ARTS_USER_ERROR_IF (x.nelem() != c,
185 "The array *", x_name, "*\n"
186 "does not have the right size.\n"
187 "The size should be: ", c,"\n"
188 "but it is: ", x.nelem())
189}
190
191/*===========================================================================
192 === Functions for Tensors
193 ===========================================================================*/
194
195void chk_size(const String& x_name, ConstVectorView x, const Index& c);
196
197void chk_size(const String& x_name,
198 ConstMatrixView x,
199 const Index& r,
200 const Index& c);
201
202void chk_size(const String& x_name,
203 ConstTensor3View x,
204 const Index& p,
205 const Index& r,
206 const Index& c);
207
208void chk_size(const String& x_name,
209 ConstTensor4View x,
210 const Index& b,
211 const Index& p,
212 const Index& r,
213 const Index& c);
214
215void chk_size(const String& x_name,
216 ConstTensor5View x,
217 const Index& s,
218 const Index& b,
219 const Index& p,
220 const Index& r,
221 const Index& c);
222
223void chk_size(const String& x_name,
224 ConstTensor6View x,
225 const Index& v,
226 const Index& s,
227 const Index& b,
228 const Index& p,
229 const Index& r,
230 const Index& c);
231
232void chk_size(const String& x_name,
233 ConstTensor7View x,
234 const Index& l,
235 const Index& v,
236 const Index& s,
237 const Index& b,
238 const Index& p,
239 const Index& r,
240 const Index& c);
241
242void chk_not_empty(const String& x_name, const Agenda& x);
243
244void chk_interpolation_grids_loose(Index& ing_min,
245 Index& ing_max,
246 const String& which_interpolation,
247 ConstVectorView old_grid,
248 ConstVectorView new_grid,
249 ConstVectorView data,
250 const Index order = 1);
251
253 Index& ing_min,
254 Index& ing_max,
255 const String& which_interpolation,
256 ConstVectorView old_grid,
257 ConstVectorView new_grid,
258 const Index order = 1);
259
261 Index& ing_min,
262 Index& ing_max,
263 const String& which_interpolation,
264 ConstVectorView old_pgrid,
265 ConstVectorView new_pgrid,
266 const Index order = 1);
267
269 Index& ing_max,
270 const String& which_interpolation,
271 ConstVectorView old_grid,
272 ConstVectorView new_grid,
273 ConstVectorView data);
274
275void chk_interpolation_grids(const String& which_interpolation,
276 ConstVectorView old_grid,
277 ConstVectorView new_grid,
278 const Index order = 1,
279 const Numeric& extpolfac = 0.5,
280 const bool islog = false);
281
282void chk_interpolation_grids(const String& which_interpolation,
283 ConstVectorView old_grid,
284 const Numeric& new_grid,
285 const Index order = 1,
286 const Numeric& extpolfac = 0.5);
287
288void chk_interpolation_pgrids(const String& which_interpolation,
289 ConstVectorView old_pgrid,
290 ConstVectorView new_pgrid,
291 const Index order = 1,
292 const Numeric& extpolfac = 0.5);
293
294void chk_atm_grids(const Index& dim,
295 ConstVectorView p_grid,
296 ConstVectorView lat_grid,
297 ConstVectorView lon_grid);
298
299void chk_atm_field(const String& x_name,
300 ConstTensor3View x,
301 const Index& dim,
302 ConstVectorView p_grid,
303 ConstVectorView lat_grid,
304 ConstVectorView lon_grid,
305 const bool& chk_lat90 = 1);
306
307void chk_atm_field(const String& x_name,
308 ConstTensor4View x,
309 const Index& dim,
310 const Index& nspecies,
311 ConstVectorView p_grid,
312 ConstVectorView lat_grid,
313 ConstVectorView lon_grid,
314 const bool& check_nan = 1);
315
316void chk_atm_vecfield_lat90(const String& x1_name,
317 ConstTensor3View x1,
318 const String& x2_name,
319 ConstTensor3View x2,
320 const Index& dim,
321 ConstVectorView lat_grid,
322 const Numeric& threshold = 1e-3);
323// const Numeric& threshold = 2*DBL_EPSILON );
324
325void chk_latlon_true(const Index& atmosphere_dim,
326 ConstVectorView lat_grid,
327 ConstVectorView lat_true,
328 ConstVectorView lon_true);
329
330void chk_atm_surface(const String& x_name,
331 const Matrix& x,
332 const Index& dim,
333 ConstVectorView lat_grid,
334 ConstVectorView lon_grid);
335
336void chk_rte_pos(const Index& atmosphere_dim,
337 ConstVectorView rte_pos,
338 const bool& is_rte_pos2 = false);
339
340void chk_rte_los(const Index& atmosphere_dim, ConstVectorView rte_los);
341
343 const Index gridindex,
344 const String& gridname);
345
346void chk_met_mm_backend(const Matrix& bdsp);
347
348#endif // checkinput_h
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition array.h:195
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
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_if_equal(const String &x1_name, const String &x2_name, ConstVectorView v1, ConstVectorView v2, Numeric margin=1e-6)
chk_if_equal
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
void chk_atm_grids(const Index &dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid)
chk_atm_grids
void chk_rte_pos(const Index &atmosphere_dim, ConstVectorView rte_pos, const bool &is_rte_pos2=false)
chk_rte_pos
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
void chk_rte_los(const Index &atmosphere_dim, ConstVectorView rte_los)
chk_rte_los
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
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.
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)
void chk_met_mm_backend(const Matrix &bdsp)
Check met_mm_backend.
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
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
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.
void chk_griddedfield_gridname(const GriddedField &gf, const Index gridindex, const String &gridname)
Check name of grid in GriddedField.
void chk_latlon_true(const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lat_true, ConstVectorView lon_true)
chk_latlon_true
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(const String &x_name, const Index &x, const Index &x_low, const Index &x_high)
chk_if_in_range
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
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.
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
void chk_size(const String &x_name, const Array< T > &x, const Index &c)
Check the size of an array.
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.
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
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
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.
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Index chk_contains(const String &x_name, const Array< T > &x, const T &what)
Check if an array contains a value.
The Agenda class.
Index nelem() const ARTS_NOEXCEPT
Definition array.h:75
Subclasses of runtime_error.
Definition check_input.h:90
runtime_error_not_found(const std::string &s)
Definition check_input.h:92
Subclasses of runtime_error.
runtime_error_not_unique(const std::string &s)
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
The declarations of all the exception classes.
Implementation of gridded fields.
This file contains the definition of String, the ARTS string class.
#define v
#define c
#define b