ARTS 2.5.4 (git: 31ce4f0e)
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 <utility>
38
39#include "array.h"
40#include "matpackVI.h"
41#include "mystring.h"
42
48inline constexpr Index GFIELD1_F_GRID = 0;
49
54inline constexpr Index GFIELD3_P_GRID = 0;
55
60inline constexpr Index GFIELD3_LAT_GRID = 1;
61
66inline constexpr Index GFIELD3_LON_GRID = 2;
67
72inline constexpr Index GFIELD4_FIELD_NAMES = 0;
73
78inline constexpr Index GFIELD4_IA_GRID = 0;
79
84inline constexpr Index GFIELD4_P_GRID = 1;
85
90inline constexpr Index GFIELD4_F_GRID = 1;
91
96inline constexpr Index GFIELD4_LAT_GRID = 2;
97
102inline constexpr Index GFIELD4_ZA_GRID = 2;
103
108inline constexpr Index GFIELD4_LON_GRID = 3;
109
114inline constexpr Index GFIELD4_AA_GRID = 3;
115} // namespace GriddedFieldGrids
116
119
121
122#define CHECK_ERROR_BOILERPLATE \
123 "size mismatch between grids and data.\n" \
124 "Note that a grid is allowed to be empty, but in the\n" \
125 "data that dimension must have exactly one element.\n"
126
127template <Index N, typename GriddedFieldType>
128String metaErrorData(const GriddedFieldType& gf) {
129 std::ostringstream os;
130 os << "GriddedField" << N << " ";
131 if (gf.get_name().length()) os << "(" << gf.get_name() << ") ";
133 for (Index i = 0; i < N; i++) {
134 os << "Grid";
135 if (gf.get_grid_name(i).nelem()) os << " (" << gf.get_grid_name(i) << ")";
136 os << " = " << gf.get_grid_size(i) << "\n";
137 }
138 os << "Data =";
139 if constexpr (N > 6)
140 os << ' ' <<gf.data.nlibraries();
141 if constexpr (N > 5)
142 os << ' ' <<gf.data.nvitrines();
143 if constexpr (N > 4)
144 os << ' ' <<gf.data.nshelves();
145 if constexpr (N > 3)
146 os << ' ' <<gf.data.nbooks();
147 if constexpr (N > 2)
148 os << ' ' <<gf.data.npages();
149 if constexpr (N > 1)
150 os << ' ' <<gf.data.nrows() << ' ' << gf.data.ncols();
151 else
152 os << ' ' << gf.data.nelem();
153 return os.str();
154}
155
158 private:
165
166 protected:
168
173 : dim(0),
174 mname(),
175 mgridtypes(),
176 mgridnames(),
177 mstringgrids(),
178 mnumericgrids() { /* Nothing to do here */
179 }
180
182
192 : dim(d),
193 mname(std::move(s)),
195 mgridnames(d),
197 mnumericgrids(d) { /* Nothing to do here */
198 }
199
200 public:
202 virtual ~GriddedField() = default;
203 GriddedField(const GriddedField&) = default;
207
209
210 [[nodiscard]] Index get_dim() const { return dim; }
211
212 void copy_grids(const GriddedField& gf);
213
215
221 [[nodiscard]] const String& get_grid_name(Index i) const { return mgridnames[i]; }
222
224
230 [[nodiscard]] Index get_grid_size(Index i) const {
231 Index ret = 0;
232 ARTS_ASSERT(i < dim);
233 switch (mgridtypes[i]) {
235 ret = mnumericgrids[i].nelem();
236 break;
237 case GRID_TYPE_STRING:
238 ret = mstringgrids[i].nelem();
239 break;
240 }
241
242 return ret;
243 }
244
246
252 [[nodiscard]] GridType get_grid_type(Index i) const { return mgridtypes[i]; }
253
254 [[nodiscard]] const Vector& get_numeric_grid(Index i) const;
255
257
258 [[nodiscard]] const ArrayOfString& get_string_grid(Index i) const;
259
261
263
264 [[nodiscard]] const String& get_name() const { return mname; }
265
266 void set_grid(Index i, const Vector& g);
267
268 void set_grid(Index i, const ArrayOfString& g);
269
271
277 void set_grid_name(Index i, const String& s) {
278 ARTS_ASSERT(i < dim);
279 mgridnames[i] = s;
280 }
281
283
284 void set_name(const String& s) { mname = s; }
285
287
294 [[nodiscard]] virtual bool checksize() const = 0;
295
297
300 virtual void checksize_strict() const = 0;
301
302 friend std::ostream& operator<<(std::ostream& os, const GriddedField& gf);
303};
304
305class GriddedField1 final : public GriddedField {
306 public:
310
311 GriddedField1(const String& s) : GriddedField(1, s) {}
312
313 [[nodiscard]] bool checksize() const final {
314 return (!get_grid_size(0) && data.nelem() == 1) ||
315 data.nelem() == get_grid_size(0);
316 }
317
318 void checksize_strict() const final {
319 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<1, GriddedField1>(*this))
320 }
321
323
324 void resize(const GriddedField1& gf) { data.resize(gf.get_grid_size(0)); }
325
327
328 void resize(Index n) { data.resize(n); }
329
330 friend std::ostream& operator<<(std::ostream& os, const GriddedField1& gf);
331
332 friend String metaErrorData<1, GriddedField1>(const GriddedField1& gf);
333
335};
336
337class GriddedField2 final : public GriddedField {
338 public:
342
343 GriddedField2(const String& s) : GriddedField(2, s) {}
344
345 [[nodiscard]] bool checksize() const final {
346 return ((!get_grid_size(1) && data.ncols() == 1) ||
347 data.ncols() == get_grid_size(1)) &&
348 ((!get_grid_size(0) && data.nrows() == 1) ||
349 data.nrows() == get_grid_size(0));
350 }
351
352 void checksize_strict() const final {
353 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<2, GriddedField2>(*this))
354 }
355
357
358 void resize(const GriddedField2& gf) {
360 }
361
363
364 void resize(Index r, Index c) { data.resize(r, c); }
365
366 friend std::ostream& operator<<(std::ostream& os, const GriddedField2& gf);
367
368 friend String metaErrorData<2, GriddedField2>(const GriddedField2& gf);
369
371};
372
373class GriddedField3 final : public GriddedField {
374 public:
378
379 GriddedField3(const String& s) : GriddedField(3, s) {}
380
382 data = n;
383
384 return *this;
385 }
386
387 [[nodiscard]] bool checksize() const final {
388 return ((!get_grid_size(2) && data.ncols() == 1) ||
389 data.ncols() == get_grid_size(2)) &&
390 ((!get_grid_size(1) && data.nrows() == 1) ||
391 data.nrows() == get_grid_size(1)) &&
392 ((!get_grid_size(0) && data.npages() == 1) ||
393 data.npages() == get_grid_size(0));
394 }
395
396 void checksize_strict() const final {
397 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<3, GriddedField3>(*this))
398 }
399
401
402 void resize(const GriddedField3& gf) {
404 }
405
407
408 void resize(Index p, Index r, Index c) { data.resize(p, r, c); }
409
410 friend std::ostream& operator<<(std::ostream& os, const GriddedField3& gf);
411
412 friend String metaErrorData<3, GriddedField3>(const GriddedField3& gf);
413
415};
416
417class GriddedField4 final : public GriddedField {
418 public:
422
423 GriddedField4(const String& s) : GriddedField(4, s) {}
424
425 [[nodiscard]] bool checksize() const final {
426 return ((!get_grid_size(3) && data.ncols() == 1) ||
427 data.ncols() == get_grid_size(3)) &&
428 ((!get_grid_size(2) && data.nrows() == 1) ||
429 data.nrows() == get_grid_size(2)) &&
430 ((!get_grid_size(1) && data.npages() == 1) ||
431 data.npages() == get_grid_size(1)) &&
432 ((!get_grid_size(0) && data.nbooks() == 1) ||
433 data.nbooks() == get_grid_size(0));
434 }
435
436 void checksize_strict() const final {
437 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<4, GriddedField4>(*this))
438 }
439
441
442 void resize(const GriddedField4& gf) {
444 gf.get_grid_size(1),
445 gf.get_grid_size(2),
446 gf.get_grid_size(3));
447 }
448
450
451 void resize(Index b, Index p, Index r, Index c) { data.resize(b, p, r, c); }
452
453 friend std::ostream& operator<<(std::ostream& os, const GriddedField4& gf);
454
455 friend String metaErrorData<4, GriddedField4>(const GriddedField4& gf);
456
458};
459
460class GriddedField5 final : public GriddedField {
461 public:
465
466 GriddedField5(const String& s) : GriddedField(5, s) {}
467
468 [[nodiscard]] bool checksize() const final {
469 return ((!get_grid_size(4) && data.ncols() == 1) ||
470 data.ncols() == get_grid_size(4)) &&
471 ((!get_grid_size(3) && data.nrows() == 1) ||
472 data.nrows() == get_grid_size(3)) &&
473 ((!get_grid_size(2) && data.npages() == 1) ||
474 data.npages() == get_grid_size(2)) &&
475 ((!get_grid_size(1) && data.nbooks() == 1) ||
476 data.nbooks() == get_grid_size(1)) &&
477 ((!get_grid_size(0) && data.nshelves() == 1) ||
478 data.nshelves() == get_grid_size(0));
479 }
480
481 void checksize_strict() const final {
482 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<5, GriddedField5>(*this))
483 }
484
486
487 void resize(const GriddedField5& gf) {
489 gf.get_grid_size(1),
490 gf.get_grid_size(2),
491 gf.get_grid_size(3),
492 gf.get_grid_size(4));
493 }
494
496
497 void resize(Index s, Index b, Index p, Index r, Index c) {
498 data.resize(s, b, p, r, c);
499 }
500
501 friend std::ostream& operator<<(std::ostream& os, const GriddedField5& gf);
502
503 friend String metaErrorData<5, GriddedField5>(const GriddedField5& gf);
504
506};
507
508class GriddedField6 final : public GriddedField {
509 public:
513
514 GriddedField6(const String& s) : GriddedField(6, s) {}
515
516 [[nodiscard]] bool checksize() const final {
517 return ((!get_grid_size(5) && data.ncols() == 1) ||
518 data.ncols() == get_grid_size(5)) &&
519 ((!get_grid_size(4) && data.nrows() == 1) ||
520 data.nrows() == get_grid_size(4)) &&
521 ((!get_grid_size(3) && data.npages() == 1) ||
522 data.npages() == get_grid_size(3)) &&
523 ((!get_grid_size(2) && data.nbooks() == 1) ||
524 data.nbooks() == get_grid_size(2)) &&
525 ((!get_grid_size(1) && data.nshelves() == 1) ||
526 data.nshelves() == get_grid_size(1)) &&
527 ((!get_grid_size(0) && data.nvitrines() == 1) ||
529 }
530
531 void checksize_strict() const final {
532 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<6, GriddedField6>(*this))
533 }
534
536
537 void resize(const GriddedField6& gf) {
539 gf.get_grid_size(1),
540 gf.get_grid_size(2),
541 gf.get_grid_size(3),
542 gf.get_grid_size(4),
543 gf.get_grid_size(5));
544 }
545
547
548 void resize(Index v, Index s, Index b, Index p, Index r, Index c) {
549 data.resize(v, s, b, p, r, c);
550 }
551
552 friend std::ostream& operator<<(std::ostream& os, const GriddedField6& gf);
553
554 friend String metaErrorData<6, GriddedField6>(const GriddedField6& gf);
555
557};
558
559/************ Array types *************/
560
569
570#undef CHECK_ERROR_BOILERPLATE
571
572#endif
This file contains the definition of Array.
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
Index nrows() const noexcept
Definition: matpackI.h:1055
Index ncols() const noexcept
Definition: matpackI.h:1056
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:140
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:143
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:146
Index ncols() const noexcept
Definition: matpackIV.h:142
Index nrows() const noexcept
Definition: matpackIV.h:141
Index nbooks() const noexcept
Definition: matpackIV.h:139
Index npages() const noexcept
Definition: matpackIV.h:140
Index nrows() const noexcept
Definition: matpackV.h:152
Index ncols() const noexcept
Definition: matpackV.h:153
Index npages() const noexcept
Definition: matpackV.h:151
Index nbooks() const noexcept
Definition: matpackV.h:150
Index nshelves() const noexcept
Definition: matpackV.h:149
Index nbooks() const noexcept
Definition: matpackVI.h:157
Index nvitrines() const noexcept
Definition: matpackVI.h:155
Index ncols() const noexcept
Definition: matpackVI.h:160
Index npages() const noexcept
Definition: matpackVI.h:158
Index nshelves() const noexcept
Definition: matpackVI.h:156
Index nrows() const noexcept
Definition: matpackVI.h:159
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:536
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)
GriddedField(const GriddedField &)=default
ArrayOfVector mnumericgrids
GriddedField & operator=(const GriddedField &)=default
ArrayOfString mgridnames
Index get_grid_size(Index i) const
Get the size of a grid.
GriddedField()
Construct an empty GriddedField.
virtual ~GriddedField()=default
Defaulted con-/de-structors and assignments so unique pointers work w/o warnings.
Array< ArrayOfString > mstringgrids
GriddedField(const Index d, String s)
Construct a GriddedField.
const String & get_name() const
Get the name of this gridded field.
virtual bool checksize() const =0
Consistency check.
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.
GriddedField(GriddedField &&)=default
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.
GriddedField & operator=(GriddedField &&)=default
Array< GridType > mgridtypes
const String & get_grid_name(Index i) const
Get grid name.
The Matrix class.
Definition: matpackI.h:1261
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1010
The Tensor3 class.
Definition: matpackIII.h:346
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:661
The Tensor4 class.
Definition: matpackIV.h:429
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1054
The Tensor5 class.
Definition: matpackV.h:516
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:1741
The Tensor6 class.
Definition: matpackVI.h:1099
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2176
The Vector class.
Definition: matpackI.h:899
void resize(Index n)
Resize function.
Definition: matpackI.cc:390
#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
#define CHECK_ERROR_BOILERPLATE
String metaErrorData(const GriddedFieldType &gf)
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 Index GFIELD3_LON_GRID
Global constant, Index of the longitude grid in GriddedField3.
constexpr Index GFIELD4_LAT_GRID
Global constant, Index of the latitude grid in GriddedField4.
constexpr Index GFIELD4_P_GRID
Global constant, Index of the pressure grid in GriddedField4.
constexpr Index GFIELD4_FIELD_NAMES
Global constant, Index of the field names in GriddedField4.
constexpr Index GFIELD1_F_GRID
Global constant, Index of the frequency grid in GriddedField1.
constexpr Index GFIELD4_ZA_GRID
Global constant, Index of the zenith angle grid in GriddedField4.
constexpr Index GFIELD4_IA_GRID
Global constant, Index of incidence angles in GriddedField4.
constexpr Index GFIELD4_F_GRID
Global constant, Index of the frequency grid in GriddedField4.
constexpr Index GFIELD4_AA_GRID
Global constant, Index of the azimuth angle grid in GriddedField4.
constexpr Index GFIELD3_P_GRID
Global constant, Index of the pressure grid in GriddedField3.
constexpr Index GFIELD4_LON_GRID
Global constant, Index of the longitude grid in GriddedField4.
constexpr Index GFIELD3_LAT_GRID
Global constant, Index of the latitude grid in GriddedField3.
VectorView std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys.
Definition: raw.cc:205
#define N
Definition: rng.cc:164
#define d
#define v
#define c
#define b