ARTS 2.5.4 (git: bcd8c674)
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
50void chk_if_bool(const String& x_name, const Index& x);
51
52void chk_if_in_range(const String& x_name,
53 const Index& x,
54 const Index& x_low,
55 const Index& x_high);
56
57void chk_if_increasing(const String& x_name, const ArrayOfIndex& x);
58
59void chk_not_negative(const String& x_name, const Numeric& x);
60
61void chk_if_in_range(const String& x_name,
62 const Numeric& x,
63 const Numeric& x_low,
64 const Numeric& x_high);
65
66void 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
71void 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
76void chk_if_in_range_exclude(const String& x_name,
77 const Numeric& x,
78 const Numeric& x_low,
79 const Numeric& x_high);
80
81void chk_vector_length(const String& x_name, ConstVectorView x, const Index& l);
82
83void chk_vector_length(const String& x1_name,
84 const String& x2_name,
87
88void chk_if_increasing(const String& x_name, ConstVectorView x);
89
90void chk_if_decreasing(const String& x_name, ConstVectorView x);
91
92void chk_if_equal(const String& x1_name,
93 const String& x2_name,
96 Numeric margin = 1e-6);
97
98void chk_matrix_ncols(const String& x_name, ConstMatrixView x, const Index& l);
99
100void chk_matrix_nrows(const String& x_name, ConstMatrixView x, const Index& l);
101
108class runtime_error_not_found : public runtime_error {
109 public:
110 runtime_error_not_found(const string& s) : runtime_error(s) {}
111};
112
119class 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
148template <class T>
149Index 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
200template <class T>
201void chk_size(const String& x_name, const Array<T>& x, const Index& c) {
202 ARTS_USER_ERROR_IF (x.nelem() != c,
203 "The array *", x_name, "*\n"
204 "does not have the right size.\n"
205 "The size should be: ", c,"\n"
206 "but it is: ", x.nelem())
207}
208
209/*===========================================================================
210 === Functions for Tensors
211 ===========================================================================*/
212
213void chk_size(const String& x_name, ConstVectorView x, const Index& c);
214
215void chk_size(const String& x_name,
217 const Index& r,
218 const Index& c);
219
220void chk_size(const String& x_name,
222 const Index& p,
223 const Index& r,
224 const Index& c);
225
226void chk_size(const String& x_name,
228 const Index& b,
229 const Index& p,
230 const Index& r,
231 const Index& c);
232
233void chk_size(const String& x_name,
235 const Index& s,
236 const Index& b,
237 const Index& p,
238 const Index& r,
239 const Index& c);
240
241void chk_size(const String& x_name,
243 const Index& v,
244 const Index& s,
245 const Index& b,
246 const Index& p,
247 const Index& r,
248 const Index& c);
249
250void chk_size(const String& x_name,
252 const Index& l,
253 const Index& v,
254 const Index& s,
255 const Index& b,
256 const Index& p,
257 const Index& r,
258 const Index& c);
259
260void chk_not_empty(const String& x_name, const Agenda& x);
261
263 Index& ing_max,
264 const String& which_interpolation,
265 ConstVectorView old_grid,
266 ConstVectorView new_grid,
267 ConstVectorView data,
268 const Index order = 1);
269
271 Index& ing_min,
272 Index& ing_max,
273 const String& which_interpolation,
274 ConstVectorView old_grid,
275 ConstVectorView new_grid,
276 const Index order = 1);
277
279 Index& ing_min,
280 Index& ing_max,
281 const String& which_interpolation,
282 ConstVectorView old_pgrid,
283 ConstVectorView new_pgrid,
284 const Index order = 1);
285
287 Index& ing_max,
288 const String& which_interpolation,
289 ConstVectorView old_grid,
290 ConstVectorView new_grid,
291 ConstVectorView data);
292
293void chk_interpolation_grids(const String& which_interpolation,
294 ConstVectorView old_grid,
295 ConstVectorView new_grid,
296 const Index order = 1,
297 const Numeric& extpolfac = 0.5,
298 const bool islog = false);
299
300void chk_interpolation_grids(const String& which_interpolation,
301 ConstVectorView old_grid,
302 const Numeric& new_grid,
303 const Index order = 1,
304 const Numeric& extpolfac = 0.5);
305
306void chk_interpolation_pgrids(const String& which_interpolation,
307 ConstVectorView old_pgrid,
308 ConstVectorView new_pgrid,
309 const Index order = 1,
310 const Numeric& extpolfac = 0.5);
311
312void chk_atm_grids(const Index& dim,
313 ConstVectorView p_grid,
314 ConstVectorView lat_grid,
315 ConstVectorView lon_grid);
316
317void chk_atm_field(const String& x_name,
319 const Index& dim,
320 ConstVectorView p_grid,
321 ConstVectorView lat_grid,
322 ConstVectorView lon_grid,
323 const bool& chk_lat90 = 1);
324
325void chk_atm_field(const String& x_name,
327 const Index& dim,
328 const Index& nspecies,
329 ConstVectorView p_grid,
330 ConstVectorView lat_grid,
331 ConstVectorView lon_grid,
332 const bool& check_nan = 1);
333
334void chk_atm_vecfield_lat90(const String& x1_name,
336 const String& x2_name,
338 const Index& dim,
339 ConstVectorView lat_grid,
340 const Numeric& threshold = 1e-3);
341// const Numeric& threshold = 2*DBL_EPSILON );
342
343void chk_latlon_true(const Index& atmosphere_dim,
344 ConstVectorView lat_grid,
345 ConstVectorView lat_true,
346 ConstVectorView lon_true);
347
348void chk_atm_surface(const String& x_name,
349 const Matrix& x,
350 const Index& dim,
351 ConstVectorView lat_grid,
352 ConstVectorView lon_grid);
353
354void chk_rte_pos(const Index& atmosphere_dim,
355 ConstVectorView rte_pos,
356 const bool& is_rte_pos2 = false);
357
358void chk_rte_los(const Index& atmosphere_dim, ConstVectorView rte_los);
359
361 const Index gridindex,
362 const String& gridname);
363
364void chk_met_mm_backend(const Matrix& bdsp);
365
366#endif // checkinput_h
Declarations for agendas.
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition: array.h:212
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:380
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:345
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:65
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:627
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:665
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:399
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:180
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:813
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:86
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:230
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:906
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:325
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_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:703
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:111
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:205
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:853
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:257
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:134
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
The Agenda class.
Definition: agenda_class.h:69
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
A constant view of a Matrix.
Definition: matpackI.h:1064
A constant view of a Tensor3.
Definition: matpackIII.h:130
A constant view of a Tensor4.
Definition: matpackIV.h:131
A constant view of a Tensor5.
Definition: matpackV.h:141
A constant view of a Tensor6.
Definition: matpackVI.h:147
A constant view of a Tensor7.
Definition: matpackVII.h:145
A constant view of a Vector.
Definition: matpackI.h:530
The Matrix class.
Definition: matpackI.h:1283
Subclasses of runtime_error.
Definition: check_input.h:108
runtime_error_not_found(const string &s)
Definition: check_input.h:110
Subclasses of runtime_error.
Definition: check_input.h:119
runtime_error_not_unique(const string &s)
Definition: check_input.h:121
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
The declarations of all the exception classes.
Implementation of gridded fields.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
This file contains the definition of String, the ARTS string class.
constexpr Numeric l(const Index p0, const Index n, const Numeric x, const SortedVectorType &xi, const Index j, const std::pair< Numeric, Numeric > cycle={ -180, 180}) noexcept
#define v
#define c
#define b