ARTS  2.4.0(git:4fb77825)
test_gridded_fields.cc
Go to the documentation of this file.
1 #include "gridded_fields.h"
2 #include "matpack.h"
3 
4 using std::cout;
5 using std::endl;
6 
7 int main(void) {
8  // Creating two gridded fields
10  GriddedField1 gfone("I'm a GriddedField1");
11  GriddedField2 gftwo;
12 
13  gftwo.set_name("I'm a GriddedField2");
14 
15  // Initializing the grids
17  Vector gfonegrid(1, 5, 1); // gfonegrid = [1,2,3,4,5]
18  gfone.set_grid(0, gfonegrid); // Set grid for the vector elements.
19 
20  Vector gftwogrid0(1, 5, 1); // gftwogrid0 = [1,2,3,4,5]
21  ArrayOfString gftwogrid1{"Chan1", "Chan2", "Chan3"};
22 
23  gftwo.set_grid(0, gftwogrid0); // Set grid for the matrix rows.
24  gftwo.set_grid(1, gftwogrid1); // Set grid for the matrix columns.
25 
26  gfone.set_grid_name(0, "Pressure");
27 
28  gftwo.set_grid_name(0, "Pressure");
29  gftwo.set_grid_name(1, "Channel");
30 
31  // Initializing the data
33  Vector avector(1, 4, 0.5); // avector = [1,1.5,2,2.5]
34 
35  gfone.data = avector;
36 
37  cout << gfone;
38 
39  Matrix amatrix(5, 3, 4.); // amatrix = [[4,4,4],[4,4,4],...]
40 
41  gftwo.data = amatrix;
42 
43  // Consistency check
45 
46  if (!gfone.checksize())
47  cout << gfone.get_name() << ": Sizes of grid and data don't match" << endl;
48 
49  // This should fail!
50  if (!gftwo.checksize())
51  cout << gftwo.get_name() << ": Sizes of grids and data don't match" << endl;
52 
53  // Output
55 
56  cout << "GriddedField1: " << gfone << endl;
57  cout << "GriddedField2: " << gftwo << endl;
58 
59  return 0;
60 }
GriddedField2
Definition: gridded_fields.h:237
Matrix
The Matrix class.
Definition: matpackI.h:1193
gridded_fields.h
Implementation of gridded fields.
GriddedField::set_grid_name
void set_grid_name(Index i, const String &s)
Set grid name.
Definition: gridded_fields.h:165
matpack.h
main
int main(void)
Definition: test_gridded_fields.cc:7
GriddedField1::data
Vector data
Definition: gridded_fields.h:234
GriddedField2::data
Matrix data
Definition: gridded_fields.h:281
Array< String >
GriddedField::set_name
void set_name(const String &s)
Set name of this gridded field.
Definition: gridded_fields.h:172
GriddedField::get_name
const String & get_name() const
Get the name of this gridded field.
Definition: gridded_fields.h:152
GriddedField2::checksize
bool checksize() const final
Consistency check.
Definition: gridded_fields.h:245
GriddedField::set_grid
void set_grid(Index i, const Vector &g)
Set a numeric grid.
Definition: gridded_fields.cc:201
GriddedField1
Definition: gridded_fields.h:196
Vector
The Vector class.
Definition: matpackI.h:860