ARTS 2.5.0 (git: 9ee3ac6c)
gridded_fields.h
Go to the documentation of this file.
1/* Copyright (C) 2008-2012 Oliver Lemke <olemke@core-dump.info>
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
33#ifndef gridded_fields_h
34#define gridded_fields_h
35
36#include <stdexcept>
37#include "array.h"
38#include "matpackVI.h"
39#include "mystring.h"
40
43
45
46#define CHECK_ERROR_BOILERPLATE \
47 "size mismatch between grids and data.\n" \
48 "Note that a grid is allowed to be empty, but in the\n" \
49 "data that dimension must have exactly one element.\n"
50
51template <Index N, typename GriddedFieldType>
52String metaErrorData(const GriddedFieldType& gf) {
53 std::ostringstream os;
54 os << "GriddedField" << N << " ";
55 if (gf.get_name().length()) os << "(" << gf.get_name() << ") ";
57 for (Index i = 0; i < N; i++) {
58 os << "Grid";
59 if (gf.get_grid_name(i).nelem()) os << " (" << gf.get_grid_name(i) << ")";
60 os << " = " << gf.get_grid_size(i) << "\n";
61 }
62 os << "Data =";
63 if constexpr (N > 6)
64 os << ' ' <<gf.data.nlibraries();
65 if constexpr (N > 5)
66 os << ' ' <<gf.data.nvitrines();
67 if constexpr (N > 4)
68 os << ' ' <<gf.data.nshelves();
69 if constexpr (N > 3)
70 os << ' ' <<gf.data.nbooks();
71 if constexpr (N > 2)
72 os << ' ' <<gf.data.npages();
73 if constexpr (N > 1)
74 os << ' ' <<gf.data.nrows() << ' ' << gf.data.ncols();
75 else
76 os << ' ' << gf.data.nelem();
77 return os.str();
78}
79
82 private:
89
90 protected:
92
97 : dim(0),
98 mname(),
99 mgridtypes(),
100 mgridnames(),
101 mstringgrids(),
102 mnumericgrids() { /* Nothing to do here */
103 }
104
106
115 GriddedField(const Index d, const String& s)
116 : dim(d),
117 mname(s),
119 mgridnames(d),
121 mnumericgrids(d) { /* Nothing to do here */
122 }
123
124 public:
126
127 Index get_dim() const { return dim; }
128
129 void copy_grids(const GriddedField& gf);
130
132
138 const String& get_grid_name(Index i) const { return mgridnames[i]; }
139
141
148 Index ret = 0;
149 ARTS_ASSERT(i < dim);
150 switch (mgridtypes[i]) {
152 ret = mnumericgrids[i].nelem();
153 break;
154 case GRID_TYPE_STRING:
155 ret = mstringgrids[i].nelem();
156 break;
157 }
158
159 return ret;
160 }
161
163
169 GridType get_grid_type(Index i) const { return mgridtypes[i]; }
170
171 const Vector& get_numeric_grid(Index i) const;
172
174
175 const ArrayOfString& get_string_grid(Index i) const;
176
178
180
181 const String& get_name() const { return mname; }
182
183 void set_grid(Index i, const Vector& g);
184
185 void set_grid(Index i, const ArrayOfString& g);
186
188
194 void set_grid_name(Index i, const String& s) {
195 ARTS_ASSERT(i < dim);
196 mgridnames[i] = s;
197 }
198
200
201 void set_name(const String& s) { mname = s; }
202
204
211 virtual bool checksize() const = 0;
212
214
217 virtual void checksize_strict() const = 0;
218
220 virtual ~GriddedField() {}
221
222 friend std::ostream& operator<<(std::ostream& os, const GriddedField& gf);
223};
224
225class GriddedField1 final : public GriddedField {
226 public:
230
231 GriddedField1(const String& s) : GriddedField(1, s) {}
232
233 bool checksize() const final {
234 return (!get_grid_size(0) && data.nelem() == 1) ||
235 data.nelem() == get_grid_size(0);
236 }
237
238 void checksize_strict() const final {
239 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<1, GriddedField1>(*this))
240 }
241
243
244 void resize(const GriddedField1& gf) { data.resize(gf.get_grid_size(0)); }
245
247
248 void resize(Index n) { data.resize(n); }
249
250 friend std::ostream& operator<<(std::ostream& os, const GriddedField1& gf);
251
252 friend String metaErrorData<1, GriddedField1>(const GriddedField1& gf);
253
255};
256
257class GriddedField2 final : public GriddedField {
258 public:
262
263 GriddedField2(const String& s) : GriddedField(2, s) {}
264
265 bool checksize() const final {
266 return ((!get_grid_size(1) && data.ncols() == 1) ||
267 data.ncols() == get_grid_size(1)) &&
268 ((!get_grid_size(0) && data.nrows() == 1) ||
269 data.nrows() == get_grid_size(0));
270 }
271
272 void checksize_strict() const final {
273 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<2, GriddedField2>(*this))
274 }
275
277
278 void resize(const GriddedField2& gf) {
280 }
281
283
284 void resize(Index r, Index c) { data.resize(r, c); }
285
286 friend std::ostream& operator<<(std::ostream& os, const GriddedField2& gf);
287
288 friend String metaErrorData<2, GriddedField2>(const GriddedField2& gf);
289
291};
292
293class GriddedField3 final : public GriddedField {
294 public:
298
299 GriddedField3(const String& s) : GriddedField(3, s) {}
300
302 data = n;
303
304 return *this;
305 }
306
307 bool checksize() const final {
308 return ((!get_grid_size(2) && data.ncols() == 1) ||
309 data.ncols() == get_grid_size(2)) &&
310 ((!get_grid_size(1) && data.nrows() == 1) ||
311 data.nrows() == get_grid_size(1)) &&
312 ((!get_grid_size(0) && data.npages() == 1) ||
313 data.npages() == get_grid_size(0));
314 }
315
316 void checksize_strict() const final {
317 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<3, GriddedField3>(*this))
318 }
319
321
322 void resize(const GriddedField3& gf) {
324 }
325
327
328 void resize(Index p, Index r, Index c) { data.resize(p, r, c); }
329
330 friend std::ostream& operator<<(std::ostream& os, const GriddedField3& gf);
331
332 friend String metaErrorData<3, GriddedField3>(const GriddedField3& gf);
333
335};
336
337class GriddedField4 final : public GriddedField {
338 public:
342
343 GriddedField4(const String& s) : GriddedField(4, s) {}
344
345 bool checksize() const final {
346 return ((!get_grid_size(3) && data.ncols() == 1) ||
347 data.ncols() == get_grid_size(3)) &&
348 ((!get_grid_size(2) && data.nrows() == 1) ||
349 data.nrows() == get_grid_size(2)) &&
350 ((!get_grid_size(1) && data.npages() == 1) ||
351 data.npages() == get_grid_size(1)) &&
352 ((!get_grid_size(0) && data.nbooks() == 1) ||
353 data.nbooks() == get_grid_size(0));
354 }
355
356 void checksize_strict() const final {
357 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<4, GriddedField4>(*this))
358 }
359
361
362 void resize(const GriddedField4& gf) {
364 gf.get_grid_size(1),
365 gf.get_grid_size(2),
366 gf.get_grid_size(3));
367 }
368
370
371 void resize(Index b, Index p, Index r, Index c) { data.resize(b, p, r, c); }
372
373 friend std::ostream& operator<<(std::ostream& os, const GriddedField4& gf);
374
375 friend String metaErrorData<4, GriddedField4>(const GriddedField4& gf);
376
378};
379
380class GriddedField5 final : public GriddedField {
381 public:
385
386 GriddedField5(const String& s) : GriddedField(5, s) {}
387
388 bool checksize() const final {
389 return ((!get_grid_size(4) && data.ncols() == 1) ||
390 data.ncols() == get_grid_size(4)) &&
391 ((!get_grid_size(3) && data.nrows() == 1) ||
392 data.nrows() == get_grid_size(3)) &&
393 ((!get_grid_size(2) && data.npages() == 1) ||
394 data.npages() == get_grid_size(2)) &&
395 ((!get_grid_size(1) && data.nbooks() == 1) ||
396 data.nbooks() == get_grid_size(1)) &&
397 ((!get_grid_size(0) && data.nshelves() == 1) ||
398 data.nshelves() == get_grid_size(0));
399 }
400
401 void checksize_strict() const final {
402 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<5, GriddedField5>(*this))
403 }
404
406
407 void resize(const GriddedField5& gf) {
409 gf.get_grid_size(1),
410 gf.get_grid_size(2),
411 gf.get_grid_size(3),
412 gf.get_grid_size(4));
413 }
414
416
417 void resize(Index s, Index b, Index p, Index r, Index c) {
418 data.resize(s, b, p, r, c);
419 }
420
421 friend std::ostream& operator<<(std::ostream& os, const GriddedField5& gf);
422
423 friend String metaErrorData<5, GriddedField5>(const GriddedField5& gf);
424
426};
427
428class GriddedField6 final : public GriddedField {
429 public:
433
434 GriddedField6(const String& s) : GriddedField(6, s) {}
435
436 bool checksize() const final {
437 return ((!get_grid_size(5) && data.ncols() == 1) ||
438 data.ncols() == get_grid_size(5)) &&
439 ((!get_grid_size(4) && data.nrows() == 1) ||
440 data.nrows() == get_grid_size(4)) &&
441 ((!get_grid_size(3) && data.npages() == 1) ||
442 data.npages() == get_grid_size(3)) &&
443 ((!get_grid_size(2) && data.nbooks() == 1) ||
444 data.nbooks() == get_grid_size(2)) &&
445 ((!get_grid_size(1) && data.nshelves() == 1) ||
446 data.nshelves() == get_grid_size(1)) &&
447 ((!get_grid_size(0) && data.nvitrines() == 1) ||
449 }
450
451 void checksize_strict() const final {
452 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<6, GriddedField6>(*this))
453 }
454
456
457 void resize(const GriddedField6& gf) {
459 gf.get_grid_size(1),
460 gf.get_grid_size(2),
461 gf.get_grid_size(3),
462 gf.get_grid_size(4),
463 gf.get_grid_size(5));
464 }
465
467
468 void resize(Index v, Index s, Index b, Index p, Index r, Index c) {
469 data.resize(v, s, b, p, r, c);
470 }
471
472 friend std::ostream& operator<<(std::ostream& os, const GriddedField6& gf);
473
474 friend String metaErrorData<6, GriddedField6>(const GriddedField6& gf);
475
477};
478
479/********** Output operators **********/
480
481std::ostream& operator<<(std::ostream& os, const GriddedField& gf);
482std::ostream& operator<<(std::ostream& os, const GriddedField1& gf);
483std::ostream& operator<<(std::ostream& os, const GriddedField2& gf);
484std::ostream& operator<<(std::ostream& os, const GriddedField3& gf);
485std::ostream& operator<<(std::ostream& os, const GriddedField4& gf);
486std::ostream& operator<<(std::ostream& os, const GriddedField5& gf);
487std::ostream& operator<<(std::ostream& os, const GriddedField6& gf);
488
489/************ Array types *************/
490
499
500#undef CHECK_ERROR_BOILERPLATE
501
502#endif
This file contains the definition of Array.
This can be used to make arrays out of anything.
Definition: array.h:107
Index nelem() const ARTS_NOEXCEPT
Number of elements.
Definition: array.h:195
Index nrows() const ARTS_NOEXCEPT
Returns the number of rows.
Definition: matpackI.cc:433
Index ncols() const ARTS_NOEXCEPT
Returns the number of columns.
Definition: matpackI.cc:436
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:144
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:147
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:150
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:58
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:55
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:64
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:61
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:44
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:50
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:47
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:57
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:51
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:54
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:45
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:48
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:42
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
void checksize_strict() const final
Strict consistency check.
void resize(Index n)
Resize the data vector.
GriddedField1(const String &s)
Construct an empty GriddedField1 with the given name.
void resize(const GriddedField1 &gf)
Make this GriddedField1 the same size as the given one.
friend std::ostream & operator<<(std::ostream &os, const GriddedField1 &gf)
GriddedField1()
Construct an empty GriddedField1.
bool checksize() const final
Consistency check.
void resize(const GriddedField2 &gf)
Make this GriddedField2 the same size as the given one.
void checksize_strict() const final
Strict consistency check.
void resize(Index r, Index c)
Resize the data matrix.
bool checksize() const final
Consistency check.
GriddedField2()
Construct an empty GriddedField2.
friend std::ostream & operator<<(std::ostream &os, const GriddedField2 &gf)
GriddedField2(const String &s)
Construct an empty GriddedField2 with the given name.
GriddedField3(const String &s)
Construct an empty GriddedField3 with the given name.
void resize(Index p, Index r, Index c)
Resize the data tensor.
void checksize_strict() const final
Strict consistency check.
GriddedField3 & operator=(Numeric n)
bool checksize() const final
Consistency check.
void resize(const GriddedField3 &gf)
Make this GriddedField3 the same size as the given one.
GriddedField3()
Construct an empty GriddedField3.
friend std::ostream & operator<<(std::ostream &os, const GriddedField3 &gf)
void checksize_strict() const final
Strict consistency check.
GriddedField4(const String &s)
Construct an empty GriddedField4 with the given name.
bool checksize() const final
Consistency check.
friend std::ostream & operator<<(std::ostream &os, const GriddedField4 &gf)
void resize(const GriddedField4 &gf)
Make this GriddedField4 the same size as the given one.
GriddedField4()
Construct an empty GriddedField4.
void resize(Index b, Index p, Index r, Index c)
Resize the data tensor.
GriddedField5()
Construct an empty GriddedField5.
void checksize_strict() const final
Strict consistency check.
GriddedField5(const String &s)
Construct an empty GriddedField5 with the given name.
void resize(Index s, Index b, Index p, Index r, Index c)
Resize the data tensor.
bool checksize() const final
Consistency check.
friend std::ostream & operator<<(std::ostream &os, const GriddedField5 &gf)
void resize(const GriddedField5 &gf)
Make this GriddedField5 the same size as the given one.
bool checksize() const final
Consistency check.
void resize(const GriddedField6 &gf)
Make this GriddedField6 the same size as the given one.
void checksize_strict() const final
Strict consistency check.
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize the data tensor.
GriddedField6()
Construct an empty GriddedField6.
GriddedField6(const String &s)
Construct an empty GriddedField6 with the given name.
friend std::ostream & operator<<(std::ostream &os, const GriddedField6 &gf)
ArrayOfVector mnumericgrids
ArrayOfString mgridnames
Index get_grid_size(Index i) const
Get the size of a grid.
GriddedField()
Construct an empty GriddedField.
Array< ArrayOfString > mstringgrids
const String & get_name() const
Get the name of this gridded field.
virtual bool checksize() const =0
Consistency check.
GriddedField(const Index d, const String &s)
Construct a GriddedField.
friend std::ostream & operator<<(std::ostream &os, const GriddedField &gf)
void set_name(const String &s)
Set name of this gridded field.
const ArrayOfString & get_string_grid(Index i) const
Get a string grid.
Index get_dim() const
Get the dimension of this gridded field.
void copy_grids(const GriddedField &gf)
Copy grids.
void set_grid_name(Index i, const String &s)
Set grid name.
virtual void checksize_strict() const =0
Strict consistency check.
void set_grid(Index i, const Vector &g)
Set a numeric grid.
GridType get_grid_type(Index i) const
Get grid type.
const Vector & get_numeric_grid(Index i) const
Get a numeric grid.
virtual ~GriddedField()
GriddedField virtual destructor.
Array< GridType > mgridtypes
const String & get_grid_name(Index i) const
Get grid name.
The Matrix class.
Definition: matpackI.h:1225
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
The Tensor3 class.
Definition: matpackIII.h:339
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:658
The Tensor4 class.
Definition: matpackIV.h:421
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1058
The Tensor5 class.
Definition: matpackV.h:506
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:1741
The Tensor6 class.
Definition: matpackVI.h:1088
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2171
The Vector class.
Definition: matpackI.h:876
void resize(Index n)
Resize function.
Definition: matpackI.cc:408
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
GridType
@ GRID_TYPE_NUMERIC
@ GRID_TYPE_STRING
Array< Array< GriddedField1 > > ArrayOfArrayOfGriddedField1
Array< GriddedField5 > ArrayOfGriddedField5
std::ostream & operator<<(std::ostream &os, const GriddedField &gf)
Array< GriddedField2 > ArrayOfGriddedField2
#define CHECK_ERROR_BOILERPLATE
Array< Array< GriddedField2 > > ArrayOfArrayOfGriddedField2
Array< GriddedField3 > ArrayOfGriddedField3
Array< GriddedField1 > ArrayOfGriddedField1
Array< Array< GriddedField3 > > ArrayOfArrayOfGriddedField3
Array< GriddedField4 > ArrayOfGriddedField4
Array< GridType > ArrayOfGridType
String metaErrorData(const GriddedFieldType &gf)
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
This file contains the definition of String, the ARTS string class.
#define d
#define v
#define c
#define b
#define N
Definition: rng.cc:164