ARTS 2.5.11 (git: 725533f0)
gridded_fields.h
Go to the documentation of this file.
1
15#ifndef gridded_fields_h
16#define gridded_fields_h
17
18#include <stdexcept>
19#include <utility>
20
21#include "array.h"
22#include "matpack_arrays.h"
23#include "matpack_data.h"
24#include "mystring.h"
25
31inline constexpr Index GFIELD1_F_GRID = 0;
32
37inline constexpr Index GFIELD3_P_GRID = 0;
38
43inline constexpr Index GFIELD3_LAT_GRID = 1;
44
49inline constexpr Index GFIELD3_LON_GRID = 2;
50
55inline constexpr Index GFIELD4_FIELD_NAMES = 0;
56
61inline constexpr Index GFIELD4_IA_GRID = 0;
62
67inline constexpr Index GFIELD4_P_GRID = 1;
68
73inline constexpr Index GFIELD4_F_GRID = 1;
74
79inline constexpr Index GFIELD4_LAT_GRID = 2;
80
85inline constexpr Index GFIELD4_ZA_GRID = 2;
86
91inline constexpr Index GFIELD4_LON_GRID = 3;
92
97inline constexpr Index GFIELD4_AA_GRID = 3;
98} // namespace GriddedFieldGrids
99
102
104
105#define CHECK_ERROR_BOILERPLATE \
106 "size mismatch between grids and data.\n" \
107 "Note that a grid is allowed to be empty, but in the\n" \
108 "data that dimension must have exactly one element.\n"
109
110template <Index N, typename GriddedFieldType>
111String metaErrorData(const GriddedFieldType& gf) {
112 std::ostringstream os;
113 os << "GriddedField" << N << " ";
114 if (gf.get_name().length()) os << "(" << gf.get_name() << ") ";
116 for (Index i = 0; i < N; i++) {
117 os << "Grid";
118 if (gf.get_grid_name(i).nelem()) os << " (" << gf.get_grid_name(i) << ")";
119 os << " = " << gf.get_grid_size(i) << "\n";
120 }
121 os << "Data =";
122 if constexpr (N > 6)
123 os << ' ' <<gf.data.nlibraries();
124 if constexpr (N > 5)
125 os << ' ' <<gf.data.nvitrines();
126 if constexpr (N > 4)
127 os << ' ' <<gf.data.nshelves();
128 if constexpr (N > 3)
129 os << ' ' <<gf.data.nbooks();
130 if constexpr (N > 2)
131 os << ' ' <<gf.data.npages();
132 if constexpr (N > 1)
133 os << ' ' <<gf.data.nrows() << ' ' << gf.data.ncols();
134 else
135 os << ' ' << gf.data.nelem();
136 return os.str();
137}
138
141 private:
142 Index dim;
147 ArrayOfVector mnumericgrids;
148
149 protected:
151
156 : dim(0),
157 mname(),
158 mgridtypes(),
159 mgridnames(),
160 mstringgrids(),
161 mnumericgrids() { /* Nothing to do here */
162 }
163
165
174 GriddedField(const Index d, String s)
175 : dim(d),
176 mname(std::move(s)),
178 mgridnames(d),
180 mnumericgrids(d) { /* Nothing to do here */
181 }
182
183 public:
185 virtual ~GriddedField() = default;
186 GriddedField(const GriddedField&) = default;
190
192
193 [[nodiscard]] Index get_dim() const { return dim; }
194
195 void copy_grids(const GriddedField& gf);
196
198
204 [[nodiscard]] const String& get_grid_name(Index i) const { return mgridnames[i]; }
205
207
213 [[nodiscard]] Index get_grid_size(Index i) const {
214 Index ret = 0;
215 ARTS_ASSERT(i < dim);
216 switch (mgridtypes[i]) {
218 ret = mnumericgrids[i].nelem();
219 break;
220 case GRID_TYPE_STRING:
221 ret = mstringgrids[i].nelem();
222 break;
223 }
224
225 return ret;
226 }
227
229
235 [[nodiscard]] GridType get_grid_type(Index i) const { return mgridtypes[i]; }
236
237 [[nodiscard]] const Vector& get_numeric_grid(Index i) const;
238
239 Vector& get_numeric_grid(Index i);
240
241 [[nodiscard]] const ArrayOfString& get_string_grid(Index i) const;
242
244
246
247 [[nodiscard]] const String& get_name() const { return mname; }
248
249 void set_grid(Index i, const Vector& g);
250
251 void set_grid(Index i, const ArrayOfString& g);
252
254
260 void set_grid_name(Index i, const String& s) {
261 ARTS_ASSERT(i < dim);
262 mgridnames[i] = s;
263 }
264
266
267 void set_name(const String& s) { mname = s; }
268
270
277 [[nodiscard]] virtual bool checksize() const = 0;
278
280
283 virtual void checksize_strict() const = 0;
284
285 friend std::ostream& operator<<(std::ostream& os, const GriddedField& gf);
286};
287
288class GriddedField1 final : public GriddedField {
289 public:
293
294 GriddedField1(const String& s) : GriddedField(1, s) {}
295
296 [[nodiscard]] bool checksize() const final {
297 return (!get_grid_size(0) && data.nelem() == 1) ||
298 data.nelem() == get_grid_size(0);
299 }
300
301 void checksize_strict() const final {
302 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<1, GriddedField1>(*this))
303 }
304
306
307 void resize(const GriddedField1& gf) { data.resize(gf.get_grid_size(0)); }
308
310
311 void resize(Index n) { data.resize(n); }
312
313 friend std::ostream& operator<<(std::ostream& os, const GriddedField1& gf);
314
315 friend String metaErrorData<1, GriddedField1>(const GriddedField1& gf);
316
317 Vector data;
318};
319
320class GriddedField2 final : public GriddedField {
321 public:
325
326 GriddedField2(const String& s) : GriddedField(2, s) {}
327
328 [[nodiscard]] bool checksize() const final {
329 return ((!get_grid_size(1) && data.ncols() == 1) ||
330 data.ncols() == get_grid_size(1)) &&
331 ((!get_grid_size(0) && data.nrows() == 1) ||
332 data.nrows() == get_grid_size(0));
333 }
334
335 void checksize_strict() const final {
336 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<2, GriddedField2>(*this))
337 }
338
340
341 void resize(const GriddedField2& gf) {
342 data.resize(gf.get_grid_size(0), gf.get_grid_size(1));
343 }
344
346
347 void resize(Index r, Index c) { data.resize(r, c); }
348
349 friend std::ostream& operator<<(std::ostream& os, const GriddedField2& gf);
350
351 friend String metaErrorData<2, GriddedField2>(const GriddedField2& gf);
352
353 Matrix data;
354};
355
356class GriddedField3 final : public GriddedField {
357 public:
361
362 GriddedField3(const String& s) : GriddedField(3, s) {}
363
365 data = n;
366
367 return *this;
368 }
369
370 [[nodiscard]] bool checksize() const final {
371 return ((!get_grid_size(2) && data.ncols() == 1) ||
372 data.ncols() == get_grid_size(2)) &&
373 ((!get_grid_size(1) && data.nrows() == 1) ||
374 data.nrows() == get_grid_size(1)) &&
375 ((!get_grid_size(0) && data.npages() == 1) ||
376 data.npages() == get_grid_size(0));
377 }
378
379 void checksize_strict() const final {
380 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<3, GriddedField3>(*this))
381 }
382
384
385 void resize(const GriddedField3& gf) {
386 data.resize(gf.get_grid_size(0), gf.get_grid_size(1), gf.get_grid_size(2));
387 }
388
390
391 void resize(Index p, Index r, Index c) { data.resize(p, r, c); }
392
393 friend std::ostream& operator<<(std::ostream& os, const GriddedField3& gf);
394
395 friend String metaErrorData<3, GriddedField3>(const GriddedField3& gf);
396
397 Tensor3 data;
398};
399
400class GriddedField4 final : public GriddedField {
401 public:
405
406 GriddedField4(const String& s) : GriddedField(4, s) {}
407
408 [[nodiscard]] bool checksize() const final {
409 return ((!get_grid_size(3) && data.ncols() == 1) ||
410 data.ncols() == get_grid_size(3)) &&
411 ((!get_grid_size(2) && data.nrows() == 1) ||
412 data.nrows() == get_grid_size(2)) &&
413 ((!get_grid_size(1) && data.npages() == 1) ||
414 data.npages() == get_grid_size(1)) &&
415 ((!get_grid_size(0) && data.nbooks() == 1) ||
416 data.nbooks() == get_grid_size(0));
417 }
418
419 void checksize_strict() const final {
420 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<4, GriddedField4>(*this))
421 }
422
424
425 void resize(const GriddedField4& gf) {
426 data.resize(gf.get_grid_size(0),
427 gf.get_grid_size(1),
428 gf.get_grid_size(2),
429 gf.get_grid_size(3));
430 }
431
433
434 void resize(Index b, Index p, Index r, Index c) { data.resize(b, p, r, c); }
435
436 friend std::ostream& operator<<(std::ostream& os, const GriddedField4& gf);
437
438 friend String metaErrorData<4, GriddedField4>(const GriddedField4& gf);
439
440 Tensor4 data;
441};
442
443class GriddedField5 final : public GriddedField {
444 public:
448
449 GriddedField5(const String& s) : GriddedField(5, s) {}
450
451 [[nodiscard]] bool checksize() const final {
452 return ((!get_grid_size(4) && data.ncols() == 1) ||
453 data.ncols() == get_grid_size(4)) &&
454 ((!get_grid_size(3) && data.nrows() == 1) ||
455 data.nrows() == get_grid_size(3)) &&
456 ((!get_grid_size(2) && data.npages() == 1) ||
457 data.npages() == get_grid_size(2)) &&
458 ((!get_grid_size(1) && data.nbooks() == 1) ||
459 data.nbooks() == get_grid_size(1)) &&
460 ((!get_grid_size(0) && data.nshelves() == 1) ||
461 data.nshelves() == get_grid_size(0));
462 }
463
464 void checksize_strict() const final {
465 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<5, GriddedField5>(*this))
466 }
467
469
470 void resize(const GriddedField5& gf) {
471 data.resize(gf.get_grid_size(0),
472 gf.get_grid_size(1),
473 gf.get_grid_size(2),
474 gf.get_grid_size(3),
475 gf.get_grid_size(4));
476 }
477
479
480 void resize(Index s, Index b, Index p, Index r, Index c) {
481 data.resize(s, b, p, r, c);
482 }
483
484 friend std::ostream& operator<<(std::ostream& os, const GriddedField5& gf);
485
486 friend String metaErrorData<5, GriddedField5>(const GriddedField5& gf);
487
488 Tensor5 data;
489};
490
491class GriddedField6 final : public GriddedField {
492 public:
496
497 GriddedField6(const String& s) : GriddedField(6, s) {}
498
499 [[nodiscard]] bool checksize() const final {
500 return ((!get_grid_size(5) && data.ncols() == 1) ||
501 data.ncols() == get_grid_size(5)) &&
502 ((!get_grid_size(4) && data.nrows() == 1) ||
503 data.nrows() == get_grid_size(4)) &&
504 ((!get_grid_size(3) && data.npages() == 1) ||
505 data.npages() == get_grid_size(3)) &&
506 ((!get_grid_size(2) && data.nbooks() == 1) ||
507 data.nbooks() == get_grid_size(2)) &&
508 ((!get_grid_size(1) && data.nshelves() == 1) ||
509 data.nshelves() == get_grid_size(1)) &&
510 ((!get_grid_size(0) && data.nvitrines() == 1) ||
511 data.nvitrines() == get_grid_size(0));
512 }
513
514 void checksize_strict() const final {
515 ARTS_USER_ERROR_IF (!checksize(), metaErrorData<6, GriddedField6>(*this))
516 }
517
519
520 void resize(const GriddedField6& gf) {
521 data.resize(gf.get_grid_size(0),
522 gf.get_grid_size(1),
523 gf.get_grid_size(2),
524 gf.get_grid_size(3),
525 gf.get_grid_size(4),
526 gf.get_grid_size(5));
527 }
528
530
531 void resize(Index v, Index s, Index b, Index p, Index r, Index c) {
532 data.resize(v, s, b, p, r, c);
533 }
534
535 friend std::ostream& operator<<(std::ostream& os, const GriddedField6& gf);
536
537 friend String metaErrorData<6, GriddedField6>(const GriddedField6& gf);
538
539 Tensor6 data;
540};
541
542/************ Array types *************/
543
552
553#undef CHECK_ERROR_BOILERPLATE
554
555#endif
This file contains the definition of Array.
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.
#define ARTS_ASSERT(condition,...)
Definition debug.h:86
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
GridType
@ GRID_TYPE_NUMERIC
@ GRID_TYPE_STRING
#define CHECK_ERROR_BOILERPLATE
String metaErrorData(const GriddedFieldType &gf)
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.
#define d
#define v
#define c
#define b