ARTS  2.0.49
gridded_fields.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 Claudia Emde <claudia.emde@dlr.de>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA.
17 */
18 
34 #ifndef gridded_fields_h
35 #define gridded_fields_h
36 
37 #include "matpackIV.h"
38 #include "array.h"
39 #include "mystring.h"
40 
42 enum GridType {
45 };
46 
48 
51 {
52 private:
59 
60 protected:
62 
66  GriddedField() : dim(0),
67  mname(),
68  mgridtypes(),
69  mgridnames(),
70  mstringgrids(),
72  { /* Nothing to do here */ }
73 
75 
84  GriddedField(const Index d, const String& s) : dim(d),
85  mname(s),
87  mgridnames(d),
88  mstringgrids(d),
89  mnumericgrids(d)
90  { /* Nothing to do here */ }
91 
92 
93 public:
95 
96  Index get_dim () const { return dim; }
97 
98  void copy_grids (const GriddedField& gf);
99 
101 
107  const String& get_grid_name (Index i) const { return mgridnames[i]; }
108 
110 
117  {
118  Index ret = 0;
119  assert (i < dim);
120  switch (mgridtypes[i])
121  {
122  case GRID_TYPE_NUMERIC: ret = mnumericgrids[i].nelem(); break;
123  case GRID_TYPE_STRING: ret = mstringgrids[i].nelem(); break;
124  }
125 
126  return ret;
127  }
128 
130 
136  GridType get_grid_type (Index i) const { return mgridtypes[i]; }
137 
139 
141 
142  const ArrayOfString& get_string_grid (Index i) const;
143 
145 
147 
148  const String& get_name () const { return mname; }
149 
150  void set_grid (Index i, const Vector& g);
151 
152  void set_grid (Index i, const ArrayOfString& g);
153 
155 
161  void set_grid_name (Index i, const String& s)
162  {
163  assert (i < dim);
164  mgridnames[i] = s;
165  }
166 
168 
169  void set_name (const String& s) { mname = s; }
170 
172 
179  virtual bool checksize() const { return false; }
180 
182  virtual ~GriddedField() { }
183 
184  friend ostream& operator<<(ostream& os, const GriddedField& gf);
185 };
186 
187 
189 {
190 public:
194 
195  GriddedField1(const String& s) : GriddedField(1, s) {}
196 
198 
203  virtual bool checksize() const
204  {
205  return (((!get_grid_size(0) && data.nelem() == 1)
206  || data.nelem() == get_grid_size(0)));
207  }
208 
210 
211  void resize(const GriddedField1& gf)
212  {
213  data.resize(gf.get_grid_size(0));
214  }
215 
217 
218  void resize(Index n)
219  {
220  data.resize(n);
221  }
222 
223  friend ostream& operator<<(ostream& os, const GriddedField1& gf);
224 
226 };
227 
228 
230 {
231 public:
235 
236  GriddedField2(const String& s) : GriddedField(2, s) {}
237 
239 
244  virtual bool checksize() const
245  {
246  return (((!get_grid_size(1) && data.ncols() == 1)
247  || data.ncols() == get_grid_size(1))
248  && ((!get_grid_size(0) && data.nrows() == 1)
249  || data.nrows() == get_grid_size(0)));
250  }
251 
253 
254  void resize(const GriddedField2& gf)
255  {
256  data.resize(gf.get_grid_size(0),
257  gf.get_grid_size(1));
258  }
259 
261 
262  void resize(Index r, Index c)
263  {
264  data.resize(r, c);
265  }
266 
267  friend ostream& operator<<(ostream& os, const GriddedField2& gf);
268 
270 };
271 
272 
274 {
275 public:
279 
280  GriddedField3(const String& s) : GriddedField(3, s) {}
281 
283  {
284  data=n;
285 
286  return *this;
287  }
288 
290 
295  virtual bool checksize() const
296  {
297  return (((!get_grid_size(2) && data.ncols() == 1)
298  || data.ncols() == get_grid_size(2))
299  && ((!get_grid_size(1) && data.nrows() == 1)
300  || data.nrows() == get_grid_size(1))
301  && ((!get_grid_size(0) && data.npages() == 1)
302  || data.npages() == get_grid_size(0)));
303  }
304 
306 
307  void resize(const GriddedField3& gf)
308  {
309  data.resize(gf.get_grid_size(0),
310  gf.get_grid_size(1),
311  gf.get_grid_size(2));
312  }
313 
315 
316  void resize(Index p, Index r, Index c)
317  {
318  data.resize(p, r, c);
319  }
320 
321  friend ostream& operator<<(ostream& os, const GriddedField3& gf);
322 
324 };
325 
326 
328 {
329 public:
333 
334  GriddedField4(const String& s) : GriddedField(4, s) {}
335 
337 
342  virtual bool checksize() const
343  {
344  return (((!get_grid_size(3) && data.ncols() == 1)
345  || data.ncols() == get_grid_size(3))
346  && ((!get_grid_size(2) && data.nrows() == 1)
347  || data.nrows() == get_grid_size(2))
348  && ((!get_grid_size(1) && data.npages() == 1)
349  || data.npages() == get_grid_size(1))
350  && ((!get_grid_size(0) && data.nbooks() == 1)
351  || data.nbooks() == get_grid_size(0)));
352  }
353 
355 
356  void resize(const GriddedField4& gf)
357  {
358  data.resize(gf.get_grid_size(0),
359  gf.get_grid_size(1),
360  gf.get_grid_size(2),
361  gf.get_grid_size(3));
362  }
363 
365 
366  void resize(Index b, Index p, Index r, Index c)
367  {
368  data.resize(b, p, r, c);
369  }
370 
371  friend ostream& operator<<(ostream& os, const GriddedField4& gf);
372 
374 };
375 
376 
377 /********** Output operators **********/
378 
379 ostream& operator<<(ostream& os, const GriddedField& gf);
380 ostream& operator<<(ostream& os, const GriddedField1& gf);
381 ostream& operator<<(ostream& os, const GriddedField2& gf);
382 ostream& operator<<(ostream& os, const GriddedField3& gf);
383 ostream& operator<<(ostream& os, const GriddedField4& gf);
384 
385 /**************************************/
386 
387 
394 
395 #endif
396 
GriddedField2
Definition: gridded_fields.h:230
Matrix
The Matrix class.
Definition: matpackI.h:767
GriddedField::get_string_grid
const ArrayOfString & get_string_grid(Index i) const
Get a string grid.
Definition: gridded_fields.cc:157
GriddedField::mname
String mname
Definition: gridded_fields.h:54
GriddedField::set_grid_name
void set_grid_name(Index i, const String &s)
Set grid name.
Definition: gridded_fields.h:161
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1404
GriddedField1::resize
void resize(Index n)
Resize the data vector.
Definition: gridded_fields.h:218
ArrayOfGriddedField3
Array< GriddedField3 > ArrayOfGriddedField3
Definition: gridded_fields.h:390
GriddedField4::resize
void resize(Index b, Index p, Index r, Index c)
Resize the data tensor.
Definition: gridded_fields.h:366
GriddedField
Definition: gridded_fields.h:51
Tensor3
The Tensor3 class.
Definition: matpackIII.h:340
GriddedField::mgridtypes
Array< GridType > mgridtypes
Definition: gridded_fields.h:55
GriddedField2::GriddedField2
GriddedField2()
Construct an empty GriddedField2.
Definition: gridded_fields.h:233
ArrayOfGridType
Array< GridType > ArrayOfGridType
Definition: gridded_fields.h:47
GRID_TYPE_NUMERIC
@ GRID_TYPE_NUMERIC
Definition: gridded_fields.h:43
GriddedField3::operator=
GriddedField3 & operator=(Numeric n)
Definition: gridded_fields.h:282
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.cc:771
GriddedField::get_dim
Index get_dim() const
Get the dimension of this gridded field.
Definition: gridded_fields.h:96
ArrayOfArrayOfGriddedField1
Array< Array< GriddedField1 > > ArrayOfArrayOfGriddedField1
Definition: gridded_fields.h:392
GriddedField::operator<<
friend ostream & operator<<(ostream &os, const GriddedField &gf)
Output operator for GriddedField.
Definition: gridded_fields.cc:255
GriddedField1::data
Vector data
Definition: gridded_fields.h:225
GriddedField::GriddedField
GriddedField(const Index d, const String &s)
Construct a GriddedField.
Definition: gridded_fields.h:84
ConstMatrixView::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:796
GriddedField::mnumericgrids
ArrayOfVector mnumericgrids
Definition: gridded_fields.h:58
GriddedField2::operator<<
friend ostream & operator<<(ostream &os, const GriddedField2 &gf)
Output operator for GriddedField2.
Definition: gridded_fields.cc:300
GriddedField::get_numeric_grid
ConstVectorView get_numeric_grid(Index i) const
Get a numeric grid.
Definition: gridded_fields.cc:91
GriddedField2::data
Matrix data
Definition: gridded_fields.h:269
GriddedField4::checksize
virtual bool checksize() const
Consistency check.
Definition: gridded_fields.h:342
Tensor4
The Tensor4 class.
Definition: matpackIV.h:375
array.h
This file contains the definition of Array.
GriddedField2::resize
void resize(Index r, Index c)
Resize the data matrix.
Definition: gridded_fields.h:262
GriddedField3::GriddedField3
GriddedField3(const String &s)
Construct an empty GriddedField3 with the given name.
Definition: gridded_fields.h:280
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:863
GriddedField3
Definition: gridded_fields.h:274
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:151
matpackIV.h
GriddedField::dim
Index dim
Definition: gridded_fields.h:53
GriddedField::get_grid_size
Index get_grid_size(Index i) const
Get the size of a grid.
Definition: gridded_fields.h:116
GriddedField2::GriddedField2
GriddedField2(const String &s)
Construct an empty GriddedField2 with the given name.
Definition: gridded_fields.h:236
GriddedField::get_grid_type
GridType get_grid_type(Index i) const
Get grid type.
Definition: gridded_fields.h:136
Array< GridType >
GriddedField::mstringgrids
Array< ArrayOfString > mstringgrids
Definition: gridded_fields.h:57
GriddedField3::resize
void resize(Index p, Index r, Index c)
Resize the data tensor.
Definition: gridded_fields.h:316
GriddedField3::data
Tensor3 data
Definition: gridded_fields.h:323
GriddedField::GriddedField
GriddedField()
Construct an empty GriddedField.
Definition: gridded_fields.h:66
GriddedField::mgridnames
ArrayOfString mgridnames
Definition: gridded_fields.h:56
ConstMatrixView::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:802
my_basic_string< char >
ArrayOfGriddedField4
Array< GriddedField4 > ArrayOfGriddedField4
Definition: gridded_fields.h:391
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:175
VectorView
The VectorView class.
Definition: matpackI.h:373
GridType
GridType
Definition: gridded_fields.h:42
GriddedField3::GriddedField3
GriddedField3()
Construct an empty GriddedField3.
Definition: gridded_fields.h:277
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:78
GRID_TYPE_STRING
@ GRID_TYPE_STRING
Definition: gridded_fields.h:44
GriddedField4::GriddedField4
GriddedField4(const String &s)
Construct an empty GriddedField4 with the given name.
Definition: gridded_fields.h:334
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
GriddedField1::GriddedField1
GriddedField1(const String &s)
Construct an empty GriddedField1 with the given name.
Definition: gridded_fields.h:195
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:66
GriddedField4
Definition: gridded_fields.h:328
GriddedField::copy_grids
void copy_grids(const GriddedField &gf)
Copy grids.
Definition: gridded_fields.cc:59
GriddedField::set_name
void set_name(const String &s)
Set name of this gridded field.
Definition: gridded_fields.h:169
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:60
GriddedField::get_name
const String & get_name() const
Get the name of this gridded field.
Definition: gridded_fields.h:148
GriddedField3::resize
void resize(const GriddedField3 &gf)
Make this GriddedField3 the same size as the given one.
Definition: gridded_fields.h:307
GriddedField4::resize
void resize(const GriddedField4 &gf)
Make this GriddedField4 the same size as the given one.
Definition: gridded_fields.h:356
Matrix::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1549
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:154
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:72
GriddedField::checksize
virtual bool checksize() const
Consistency check.
Definition: gridded_fields.h:179
GriddedField4::operator<<
friend ostream & operator<<(ostream &os, const GriddedField4 &gf)
Output operator for GriddedField4.
Definition: gridded_fields.cc:326
GriddedField2::checksize
virtual bool checksize() const
Consistency check.
Definition: gridded_fields.h:244
GriddedField::set_grid
void set_grid(Index i, const Vector &g)
Set a numeric grid.
Definition: gridded_fields.cc:223
GriddedField3::checksize
virtual bool checksize() const
Consistency check.
Definition: gridded_fields.h:295
GriddedField1::GriddedField1
GriddedField1()
Construct an empty GriddedField1.
Definition: gridded_fields.h:192
operator<<
ostream & operator<<(ostream &os, const GriddedField &gf)
Output operator for GriddedField.
Definition: gridded_fields.cc:255
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:157
GriddedField4::GriddedField4
GriddedField4()
Construct an empty GriddedField4.
Definition: gridded_fields.h:331
ArrayOfGriddedField1
Array< GriddedField1 > ArrayOfGriddedField1
Definition: gridded_fields.h:388
GriddedField1
Definition: gridded_fields.h:189
GriddedField::~GriddedField
virtual ~GriddedField()
GriddedField destructor.
Definition: gridded_fields.h:182
GriddedField3::operator<<
friend ostream & operator<<(ostream &os, const GriddedField3 &gf)
Output operator for GriddedField3.
Definition: gridded_fields.cc:313
GriddedField1::resize
void resize(const GriddedField1 &gf)
Make this GriddedField1 the same size as the given one.
Definition: gridded_fields.h:211
ArrayOfArrayOfGriddedField3
Array< Array< GriddedField3 > > ArrayOfArrayOfGriddedField3
Definition: gridded_fields.h:393
ArrayOfGriddedField2
Array< GriddedField2 > ArrayOfGriddedField2
Definition: gridded_fields.h:389
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
GriddedField::get_grid_name
const String & get_grid_name(Index i) const
Get grid name.
Definition: gridded_fields.h:107
GriddedField1::checksize
virtual bool checksize() const
Consistency check.
Definition: gridded_fields.h:203
GriddedField4::data
Tensor4 data
Definition: gridded_fields.h:373
Vector
The Vector class.
Definition: matpackI.h:555
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
mystring.h
This file contains the definition of String, the ARTS string class.
GriddedField2::resize
void resize(const GriddedField2 &gf)
Make this GriddedField2 the same size as the given one.
Definition: gridded_fields.h:254
GriddedField1::operator<<
friend ostream & operator<<(ostream &os, const GriddedField1 &gf)
Output operator for GriddedField1.
Definition: gridded_fields.cc:287