ARTS  2.0.49
check_input.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
2  Patrick Eriksson <Patrick.Eriksson@rss.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 
22 /*===========================================================================
23  === File description
24  ===========================================================================*/
25 
36 #ifndef checkinput_h
37 #define checkinput_h
38 
39 
40 
41 /*===========================================================================
42  === External declarations
43  ===========================================================================*/
44 
45 #include "agenda_class.h"
46 #include "exceptions.h"
47 #include "matpackVII.h"
48 #include "mystring.h"
49 #include "gridded_fields.h"
50 
51 
52 /*===========================================================================
53  === Functions in check_input.cc
54  ===========================================================================*/
55 
56 void chk_if_bool(
57  const String& x_name,
58  const Index& x );
59 
60 void chk_if_in_range(
61  const String& x_name,
62  const Index& x,
63  const Index& x_low,
64  const Index& x_high );
65 
66 void chk_if_increasing(
67  const String& x_name,
68  const ArrayOfIndex& x );
69 
70 void chk_not_negative(
71  const String& x_name,
72  const Numeric& x );
73 
74 void chk_if_in_range(
75  const String& x_name,
76  const Numeric& x,
77  const Numeric& x_low,
78  const Numeric& x_high );
79 
80 void chk_vector_length(
81  const String& x_name,
83  const Index& l );
84 
85 void chk_vector_length(
86  const String& x1_name,
87  const String& x2_name,
88  ConstVectorView x1,
89  ConstVectorView x2 );
90 
91 void chk_if_increasing(
92  const String& x_name,
93  ConstVectorView x );
94 
95 void chk_if_decreasing(
96  const String& x_name,
97  ConstVectorView x );
98 
99 void chk_if_equal(
100  const String& x1_name,
101  const String& x2_name,
102  ConstVectorView v1,
103  ConstVectorView v2,
104  Numeric margin=1e-6);
105 
106 void chk_interpolation_grids(const String& which_interpolation,
107  ConstVectorView old_grid,
108  ConstVectorView new_grid,
109  const Index order=1,
110  const Numeric& extpolfac=0.5 );
111 
112 void chk_interpolation_grids(const String& which_interpolation,
113  ConstVectorView old_grid,
114  const Numeric& new_grid,
115  const Index order=1,
116  const Numeric& extpolfac=0.5 );
117 
118 void chk_matrix_ncols(
119  const String& x_name,
120  ConstMatrixView x,
121  const Index& l );
122 
123 void chk_matrix_nrows(
124  const String& x_name,
125  ConstMatrixView x,
126  const Index& l );
127 
128 void chk_atm_grids(
129  const Index& dim,
130  ConstVectorView p_grid,
131  ConstVectorView lat_grid,
132  ConstVectorView lon_grid );
133 
134 void chk_atm_field(
135  const String& x_name,
136  ConstTensor3View x,
137  const Index& dim,
138  ConstVectorView p_grid,
139  ConstVectorView lat_grid,
140  ConstVectorView lon_grid );
141 
142 void chk_atm_field(
143  const String& x_name,
144  ConstTensor4View x,
145  const Index& dim,
146  const Index& nspecies,
147  ConstVectorView p_grid,
148  ConstVectorView lat_grid,
149  ConstVectorView lon_grid );
150 
151 void chk_atm_surface(
152  const String& x_name,
153  const Matrix& x,
154  const Index& dim,
155  ConstVectorView lat_grid,
156  ConstVectorView lon_grid );
157 
158 void chk_not_empty(
159  const String& x_name,
160  const Agenda& x );
161 
163  const Index& dim,
164  const ArrayOfGriddedField3& pnd_field_raw,
165  ConstVectorView p_grid,
166  ConstVectorView lat_grid,
167  ConstVectorView lon_grid,
168  const ArrayOfIndex& cloudbox_limits);
169 
170 /*===========================================================================
171  === Template Functions for Arrays
172  ===========================================================================*/
173 
175 
192 template <class T>
193 Index chk_contains( const String& x_name,
194  const Array<T>& x,
195  const T& what )
196 {
197  // To generate error messages:
198  ostringstream os;
199 
200  // To store the positions:
201  ArrayOfIndex pos;
202 
203  // Find all positions of what in x and store in pos:
204  find_all( pos, x, what );
205 
206  switch ( pos.nelem() ){
207 
208  case 0:
209  // Not found.
210  os << "The array *" << x_name
211  << "* must contain the element " << what << ",\n"
212  << "but it does not.";
213  throw runtime_error( os.str() );
214  break;
215 
216  case 1:
217  // Found once, this is what we want!
218  return pos[0];
219 
220  default:
221  // Found more than once.
222  os << "The array *" << x_name
223  << "* must contain the element " << what << "\n"
224  << "exactly once, but it does contain it "
225  << pos.nelem() << " times.";
226  throw runtime_error( os.str() );
227  break;
228  }
229 
230  return -1;
231 }
232 
234 
249 template <class T>
250 void chk_size( const String& x_name,
251  const Array<T>& x,
252  const Index& c )
253 {
254  if ( x.nelem() != c )
255  {
256  ostringstream os;
257  os << "The array *" << x_name << "*\n"
258  << "does not have the right size.\n"
259  << "The size should be: " << c << "\n"
260  << "but it is: " << x.nelem();
261  throw runtime_error( os.str() );
262  }
263 }
264 
265 
266 
267 /*===========================================================================
268  === Functions for Tensors
269  ===========================================================================*/
270 
271 void chk_size( const String& x_name,
272  ConstVectorView x,
273  const Index& c );
274 
275 void chk_size( const String& x_name,
276  ConstMatrixView x,
277  const Index& r,
278  const Index& c );
279 
280 void chk_size( const String& x_name,
282  const Index& p,
283  const Index& r,
284  const Index& c );
285 
286 void chk_size( const String& x_name,
288  const Index& b,
289  const Index& p,
290  const Index& r,
291  const Index& c );
292 
293 void chk_size( const String& x_name,
295  const Index& s,
296  const Index& b,
297  const Index& p,
298  const Index& r,
299  const Index& c );
300 
301 void chk_size( const String& x_name,
303  const Index& v,
304  const Index& s,
305  const Index& b,
306  const Index& p,
307  const Index& r,
308  const Index& c );
309 
310 void chk_size( const String& x_name,
312  const Index& l,
313  const Index& v,
314  const Index& s,
315  const Index& b,
316  const Index& p,
317  const Index& r,
318  const Index& c );
319 
320 #endif // checkinput_h
Matrix
The Matrix class.
Definition: matpackI.h:767
gridded_fields.h
Implementation of gridded fields.
exceptions.h
The declarations of all the exception classes.
ConstTensor7View
A constant view of a Tensor7.
Definition: matpackVII.h:169
chk_vector_length
void chk_vector_length(const String &x_name, ConstVectorView x, const Index &l)
chk_vector_length
Definition: check_input.cc:222
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:821
chk_not_empty
void chk_not_empty(const String &x_name, const Agenda &x)
chk_not_empty
Definition: check_input.cc:880
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:603
chk_if_bool
void chk_if_bool(const String &x_name, const Index &x)
chk_if_bool
Definition: check_input.cc:67
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)
chk_atm_field (simple fields)
Definition: check_input.cc:683
Agenda
The Agenda class.
Definition: agenda_class.h:44
chk_not_negative
void chk_not_negative(const String &x_name, const Numeric &x)
chk_not_negative
Definition: check_input.cc:157
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:149
Array< Index >
agenda_class.h
Declarations for agendas.
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
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:250
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:343
ConstTensor6View
A constant view of a Tensor6.
Definition: matpackVI.h:167
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
chk_matrix_nrows
void chk_matrix_nrows(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_nrows
Definition: check_input.cc:568
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
chk_if_increasing
void chk_if_increasing(const String &x_name, const ArrayOfIndex &x)
chk_if_increasing
Definition: check_input.cc:126
chk_if_decreasing
void chk_if_decreasing(const String &x_name, ConstVectorView x)
chk_if_decreasing
Definition: check_input.cc:316
find_all
void find_all(ArrayOfIndex &pos, const Array< base > &x, const base &w)
Find all occurances.
Definition: array.h:302
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:147
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:193
chk_matrix_ncols
void chk_matrix_ncols(const String &x_name, ConstMatrixView x, const Index &l)
chk_matrix_ncols
Definition: check_input.cc:539
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:95
chk_pnd_field_raw_only_in_cloudbox
void chk_pnd_field_raw_only_in_cloudbox(const Index &dim, const ArrayOfGriddedField3 &pnd_field_raw, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, const ArrayOfIndex &cloudbox_limits)
chk_pnd_field_raw_only_in_cloudbox
Definition: check_input.cc:1211
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)
Check interpolation grids.
Definition: check_input.cc:390
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:160
mystring.h
This file contains the definition of String, the ARTS string class.
matpackVII.h