ARTS  2.0.49
gridded_fields.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008
2  Claudia Emde <claudia.emde@dlr.de>
3  Oliver Lemke <olemke@core-dump.info>
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation; either version 2, or (at your option) any
8  later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18  USA.
19 */
20 
36 /*===========================================================================
37  === External declarations
38  ===========================================================================*/
39 
40 
41 #include <stdexcept>
42 #include <iostream>
43 #include "exceptions.h"
44 #include "mystring.h"
45 #include "gridded_fields.h"
46 
47 
48 
49 /*===========================================================================
50  === The functions (in alphabetical order)
51  ===========================================================================*/
52 
54 
60 {
61  assert(gf.get_dim() == dim);
62 
63  for (Index i = 0; i < dim; i++)
64  {
65  switch (gf.get_grid_type(i))
66  {
67  case GRID_TYPE_NUMERIC:
70  mstringgrids[i].resize(0);
71  break;
72  case GRID_TYPE_STRING:
74  mstringgrids[i] = gf.get_string_grid(i);
75  mnumericgrids[i].resize(0);
76  break;
77  }
78  }
79 }
80 
81 
83 
92 {
93  assert (i < dim);
94  if (mgridtypes[i] != GRID_TYPE_NUMERIC)
95  {
96  ostringstream os;
97 
98  if (mname.length())
99  os << mname << " ";
100 
101  os << "Grid ";
102  if (mgridnames[i].length())
103  os << mgridnames[i];
104  else
105  os << i;
106  os << " is not a numeric grid.";
107 
108  throw runtime_error(os.str());
109  }
110 
111  return (mnumericgrids[i]);
112 }
113 
114 
116 
125 {
126  assert (i < dim);
127  if (mgridtypes[i] != GRID_TYPE_NUMERIC)
128  {
129  ostringstream os;
130 
131  if (mname.length())
132  os << mname << " ";
133 
134  os << "Grid ";
135  if (mgridnames[i].length())
136  os << mgridnames[i];
137  else
138  os << i;
139  os << " is not a numeric grid.";
140 
141  throw runtime_error(os.str());
142  }
143 
144  return (mnumericgrids[i]);
145 }
146 
147 
149 
158 {
159  assert (i < dim);
160  if (mgridtypes[i] != GRID_TYPE_STRING)
161  {
162  ostringstream os;
163 
164  if (mname.length())
165  os << mname << " ";
166 
167  os << "Grid ";
168  if (mgridnames[i].length())
169  os << mgridnames[i];
170  else
171  os << i;
172  os << " is not a string grid.";
173 
174  throw runtime_error(os.str());
175  }
176 
177 
178  return (mstringgrids[i]);
179 }
180 
181 
183 
192 {
193  assert (i < dim);
194  if (mgridtypes[i] != GRID_TYPE_STRING)
195  {
196  ostringstream os;
197 
198  if (mname.length())
199  os << mname << " ";
200 
201  os << "Grid ";
202  if (mgridnames[i].length())
203  os << mgridnames[i];
204  else
205  os << i;
206  os << " is not a string grid.";
207 
208  throw runtime_error(os.str());
209  }
210 
211 
212  return (mstringgrids[i]);
213 }
214 
215 
217 
224 {
225  assert (i < dim);
227  mstringgrids[i].resize(0);
228  mnumericgrids[i] = g;
229 }
230 
231 
233 
240 {
241  assert (i < dim);
243  mnumericgrids[i].resize(0);
244  mstringgrids[i] = g;
245 }
246 
247 
249 
255 ostream& operator<<(ostream& os, const GriddedField& gf)
256 {
257  if (gf.mname.size()) os << gf.mname << ":" << endl;
258 
259  for( Index i = 0; i < gf.dim; i++)
260  {
261  if (gf.mgridnames[i].size()) os << gf.mgridnames[i];
262  else os << "Grid " << i;
263  os << ": ";
264  switch (gf.mgridtypes[i])
265  {
266  case GRID_TYPE_STRING:
267  os << gf.mstringgrids[i];
268  break;
269  case GRID_TYPE_NUMERIC:
270  os << gf.mnumericgrids[i];
271  break;
272  }
273  os << endl;
274  }
275 
276  return os;
277 }
278 
279 
281 
287 ostream& operator<<(ostream& os, const GriddedField1& gf)
288 {
289  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
290 }
291 
292 
294 
300 ostream& operator<<(ostream& os, const GriddedField2& gf)
301 {
302  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
303 }
304 
305 
307 
313 ostream& operator<<(ostream& os, const GriddedField3& gf)
314 {
315  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
316 }
317 
318 
320 
326 ostream& operator<<(ostream& os, const GriddedField4& gf)
327 {
328  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data;
329 }
330 
331 
332 
333 
334 
335 
GriddedField2
Definition: gridded_fields.h:230
gridded_fields.h
Implementation of gridded fields.
GriddedField::get_string_grid
const ArrayOfString & get_string_grid(Index i) const
Get a string grid.
Definition: gridded_fields.cc:157
GriddedField::mname
String mname
Definition: gridded_fields.h:54
exceptions.h
The declarations of all the exception classes.
GriddedField
Definition: gridded_fields.h:51
GriddedField::mgridtypes
Array< GridType > mgridtypes
Definition: gridded_fields.h:55
GRID_TYPE_NUMERIC
@ GRID_TYPE_NUMERIC
Definition: gridded_fields.h:43
GriddedField::get_dim
Index get_dim() const
Get the dimension of this gridded field.
Definition: gridded_fields.h:96
GriddedField::mnumericgrids
ArrayOfVector mnumericgrids
Definition: gridded_fields.h:58
GriddedField::get_numeric_grid
ConstVectorView get_numeric_grid(Index i) const
Get a numeric grid.
Definition: gridded_fields.cc:91
GriddedField3
Definition: gridded_fields.h:274
GriddedField::dim
Index dim
Definition: gridded_fields.h:53
GriddedField::get_grid_type
GridType get_grid_type(Index i) const
Get grid type.
Definition: gridded_fields.h:136
Array< String >
GriddedField::mstringgrids
Array< ArrayOfString > mstringgrids
Definition: gridded_fields.h:57
GriddedField::mgridnames
ArrayOfString mgridnames
Definition: gridded_fields.h:56
VectorView
The VectorView class.
Definition: matpackI.h:373
GRID_TYPE_STRING
@ GRID_TYPE_STRING
Definition: gridded_fields.h:44
GriddedField4
Definition: gridded_fields.h:328
GriddedField::copy_grids
void copy_grids(const GriddedField &gf)
Copy grids.
Definition: gridded_fields.cc:59
GriddedField::set_grid
void set_grid(Index i, const Vector &g)
Set a numeric grid.
Definition: gridded_fields.cc:223
GriddedField1
Definition: gridded_fields.h:189
operator<<
ostream & operator<<(ostream &os, const GriddedField &gf)
Output operator for GriddedField.
Definition: gridded_fields.cc:255
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Vector
The Vector class.
Definition: matpackI.h:555
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
mystring.h
This file contains the definition of String, the ARTS string class.