00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 #ifndef checkinput_h
00037 #define checkinput_h
00038
00039
00040
00041
00042
00043
00044
00045 #include "agenda_class.h"
00046 #include "exceptions.h"
00047 #include "matpackVII.h"
00048 #include "mystring.h"
00049
00050
00051
00052
00053
00054
00055 void chk_if_bool(
00056 const String& x_name,
00057 const Index& x );
00058
00059 void chk_if_in_range(
00060 const String& x_name,
00061 const Index& x,
00062 const Index& x_low,
00063 const Index& x_high );
00064
00065 void chk_if_increasing(
00066 const String& x_name,
00067 const ArrayOfIndex& x );
00068
00069 void chk_if_over_0(
00070 const String& x_name,
00071 const Numeric& x );
00072
00073 void chk_if_in_range(
00074 const String& x_name,
00075 const Numeric& x,
00076 const Numeric& x_low,
00077 const Numeric& x_high );
00078
00079 void chk_vector_length(
00080 const String& x_name,
00081 ConstVectorView x,
00082 const Index& l );
00083
00084 void chk_vector_length(
00085 const String& x1_name,
00086 const String& x2_name,
00087 ConstVectorView x1,
00088 ConstVectorView x2 );
00089
00090 void chk_if_increasing(
00091 const String& x_name,
00092 ConstVectorView x );
00093
00094 void chk_if_decreasing(
00095 const String& x_name,
00096 ConstVectorView x );
00097
00098 void chk_interpolation_grids(const String& which_interpolation,
00099 ConstVectorView old_grid,
00100 ConstVectorView new_grid,
00101 const Numeric& extpolfac=0.5 );
00102
00103 void chk_interpolation_grids(const String& which_interpolation,
00104 ConstVectorView old_grid,
00105 const Numeric& new_grid,
00106 const Numeric& extpolfac=0.5 );
00107
00108 void chk_matrix_ncols(
00109 const String& x_name,
00110 ConstMatrixView x,
00111 const Index& l );
00112
00113 void chk_matrix_nrows(
00114 const String& x_name,
00115 ConstMatrixView x,
00116 const Index& l );
00117
00118 void chk_atm_grids(
00119 const Index& dim,
00120 ConstVectorView p_grid,
00121 ConstVectorView lat_grid,
00122 ConstVectorView lon_grid );
00123
00124 void chk_atm_field(
00125 const String& x_name,
00126 ConstTensor3View x,
00127 const Index& dim,
00128 ConstVectorView p_grid,
00129 ConstVectorView lat_grid,
00130 ConstVectorView lon_grid );
00131
00132 void chk_atm_field(
00133 const String& x_name,
00134 ConstTensor4View x,
00135 const Index& dim,
00136 const Index& nspecies,
00137 ConstVectorView p_grid,
00138 ConstVectorView lat_grid,
00139 ConstVectorView lon_grid );
00140
00141 void chk_atm_surface(
00142 const String& x_name,
00143 const Matrix& x,
00144 const Index& dim,
00145 ConstVectorView lat_grid,
00146 ConstVectorView lon_grid );
00147
00148 void chk_cloudbox(
00149 const Index& dim,
00150 ConstVectorView p_grid,
00151 ConstVectorView lat_grid,
00152 ConstVectorView lon_grid,
00153 const Index& cloudbox_on,
00154 const ArrayOfIndex& cloudbox_limits );
00155
00156 void chk_not_empty(
00157 const String& x_name,
00158 const Agenda& x );
00159
00160
00161
00162
00163
00164
00166
00183 template <class T>
00184 Index chk_contains( const String& x_name,
00185 const Array<T>& x,
00186 const T& what )
00187 {
00188
00189 ostringstream os;
00190
00191
00192 ArrayOfIndex pos;
00193
00194
00195 find_all( pos, x, what );
00196
00197 switch ( pos.nelem() ){
00198
00199 case 0:
00200
00201 os << "The array *" << x_name
00202 << "* must contain the element " << what << ",\n"
00203 << "but it does not.";
00204 throw runtime_error( os.str() );
00205 break;
00206
00207 case 1:
00208
00209 return pos[0];
00210
00211 default:
00212
00213 os << "The array *" << x_name
00214 << "* must contain the element " << what << "\n"
00215 << "exactly once, but it does contain it "
00216 << pos.nelem() << " times.";
00217 throw runtime_error( os.str() );
00218 break;
00219 }
00220
00221 return -1;
00222 }
00223
00225
00240 template <class T>
00241 void chk_size( const String& x_name,
00242 const Array<T>& x,
00243 const Index& c )
00244 {
00245 if ( x.nelem() != c )
00246 {
00247 ostringstream os;
00248 os << "The array *" << x_name << "*\n"
00249 << "does not have the right size.\n"
00250 << "The size should be: " << c << "\n"
00251 << "but it is: " << x.nelem();
00252 throw runtime_error( os.str() );
00253 }
00254 }
00255
00256
00257
00258
00259
00260
00261
00262 void chk_size( const String& x_name,
00263 ConstVectorView x,
00264 const Index& c );
00265
00266 void chk_size( const String& x_name,
00267 ConstMatrixView x,
00268 const Index& r,
00269 const Index& c );
00270
00271 void chk_size( const String& x_name,
00272 ConstTensor3View x,
00273 const Index& p,
00274 const Index& r,
00275 const Index& c );
00276
00277 void chk_size( const String& x_name,
00278 ConstTensor4View x,
00279 const Index& b,
00280 const Index& p,
00281 const Index& r,
00282 const Index& c );
00283
00284 void chk_size( const String& x_name,
00285 ConstTensor5View x,
00286 const Index& s,
00287 const Index& b,
00288 const Index& p,
00289 const Index& r,
00290 const Index& c );
00291
00292 void chk_size( const String& x_name,
00293 ConstTensor6View x,
00294 const Index& v,
00295 const Index& s,
00296 const Index& b,
00297 const Index& p,
00298 const Index& r,
00299 const Index& c );
00300
00301 void chk_size( const String& x_name,
00302 ConstTensor7View x,
00303 const Index& l,
00304 const Index& v,
00305 const Index& s,
00306 const Index& b,
00307 const Index& p,
00308 const Index& r,
00309 const Index& c );
00310
00311 #endif // checkinput_h