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