ARTS  2.2.66
gridded_fields.cc
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 
34 /*===========================================================================
35  === External declarations
36  ===========================================================================*/
37 
38 
39 #include <stdexcept>
40 #include <iostream>
41 #include "exceptions.h"
42 #include "mystring.h"
43 #include "gridded_fields.h"
44 
45 
46 using std::ostream;
47 using std::ostringstream;
48 using std::endl;
49 using std::runtime_error;
50 
51 /*===========================================================================
52  === The functions (in alphabetical order)
53  ===========================================================================*/
54 
56 
62 {
63  assert(gf.get_dim() == dim);
64 
65  for (Index i = 0; i < dim; i++)
66  {
67  switch (gf.get_grid_type(i))
68  {
69  case GRID_TYPE_NUMERIC:
72  mstringgrids[i].resize(0);
73  break;
74  case GRID_TYPE_STRING:
76  mstringgrids[i] = gf.get_string_grid(i);
77  mnumericgrids[i].resize(0);
78  break;
79  }
80  }
81 }
82 
83 
85 
94 {
95  assert (i < dim);
96  if (mgridtypes[i] != GRID_TYPE_NUMERIC)
97  {
98  ostringstream os;
99 
100  if (mname.length())
101  os << mname << " ";
102 
103  os << "Grid ";
104  if (mgridnames[i].length())
105  os << mgridnames[i];
106  else
107  os << i;
108  os << " is not a numeric grid.";
109 
110  throw runtime_error(os.str());
111  }
112 
113  return (mnumericgrids[i]);
114 }
115 
116 
118 
127 {
128  assert (i < dim);
129  if (mgridtypes[i] != GRID_TYPE_NUMERIC)
130  {
131  ostringstream os;
132 
133  if (mname.length())
134  os << mname << " ";
135 
136  os << "Grid ";
137  if (mgridnames[i].length())
138  os << mgridnames[i];
139  else
140  os << i;
141  os << " is not a numeric grid.";
142 
143  throw runtime_error(os.str());
144  }
145 
146  return (mnumericgrids[i]);
147 }
148 
149 
151 
160 {
161  assert (i < dim);
162  if (mgridtypes[i] != GRID_TYPE_STRING)
163  {
164  ostringstream os;
165 
166  if (mname.length())
167  os << mname << " ";
168 
169  os << "Grid ";
170  if (mgridnames[i].length())
171  os << mgridnames[i];
172  else
173  os << i;
174  os << " is not a string grid.";
175 
176  throw runtime_error(os.str());
177  }
178 
179 
180  return (mstringgrids[i]);
181 }
182 
183 
185 
194 {
195  assert (i < dim);
196  if (mgridtypes[i] != GRID_TYPE_STRING)
197  {
198  ostringstream os;
199 
200  if (mname.length())
201  os << mname << " ";
202 
203  os << "Grid ";
204  if (mgridnames[i].length())
205  os << mgridnames[i];
206  else
207  os << i;
208  os << " is not a string grid.";
209 
210  throw runtime_error(os.str());
211  }
212 
213 
214  return (mstringgrids[i]);
215 }
216 
217 
219 
226 {
227  assert (i < dim);
229  mstringgrids[i].resize(0);
230  mnumericgrids[i] = g;
231 }
232 
233 
235 
242 {
243  assert (i < dim);
245  mnumericgrids[i].resize(0);
246  mstringgrids[i] = g;
247 }
248 
249 
251 
257 ostream& operator<<(ostream& os, const GriddedField& gf)
258 {
259  if (gf.mname.size()) os << gf.mname << ":" << endl;
260 
261  for( Index i = 0; i < gf.dim; i++)
262  {
263  if (gf.mgridnames[i].size()) os << gf.mgridnames[i];
264  else os << "Grid " << i;
265  os << ": ";
266  switch (gf.mgridtypes[i])
267  {
268  case GRID_TYPE_STRING:
269  os << gf.mstringgrids[i];
270  break;
271  case GRID_TYPE_NUMERIC:
272  os << gf.mnumericgrids[i];
273  break;
274  }
275  os << endl;
276  }
277 
278  return os;
279 }
280 
281 
283 ostream& operator<<(ostream& os, const GriddedField1& gf)
284 {
285  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
286 }
287 
288 
290 ostream& operator<<(ostream& os, const GriddedField2& gf)
291 {
292  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
293 }
294 
295 
297 ostream& operator<<(ostream& os, const GriddedField3& gf)
298 {
299  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
300 }
301 
302 
304 ostream& operator<<(ostream& os, const GriddedField4& gf)
305 {
306  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
307 }
308 
309 
311 ostream& operator<<(ostream& os, const GriddedField5& gf)
312 {
313  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
314 }
315 
316 
318 ostream& operator<<(ostream& os, const GriddedField6& gf)
319 {
320  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
321 }
322 
323 
324 
325 
326 
327 
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
The VectorView class.
Definition: matpackI.h:372
ConstVectorView get_numeric_grid(Index i) const
Get a numeric grid.
The Vector class.
Definition: matpackI.h:556
const ArrayOfString & get_string_grid(Index i) const
Get a string grid.
GridType get_grid_type(Index i) const
Get grid type.
ArrayOfString mgridnames
void copy_grids(const GriddedField &gf)
Copy grids.
Index get_dim() const
Get the dimension of this gridded field.
ArrayOfVector mnumericgrids
void set_grid(Index i, const Vector &g)
Set a numeric grid.
The declarations of all the exception classes.
Array< ArrayOfString > mstringgrids
friend std::ostream & operator<<(std::ostream &os, const GriddedField &gf)
A constant view of a Vector.
Definition: matpackI.h:292
Implementation of gridded fields.
Array< GridType > mgridtypes
This file contains the definition of String, the ARTS string class.