ARTS  2.3.1285(git:92a29ea9-dirty)
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 #include "gridded_fields.h"
39 #include <iostream>
40 #include <stdexcept>
41 #include "exceptions.h"
42 #include "mystring.h"
43 
44 using std::endl;
45 using std::ostream;
46 using std::ostringstream;
47 using std::runtime_error;
48 
49 /*===========================================================================
50  === The functions (in alphabetical order)
51  ===========================================================================*/
52 
54 
60  assert(gf.get_dim() == dim);
61 
62  for (Index i = 0; i < dim; i++) {
63  switch (gf.get_grid_type(i)) {
64  case GRID_TYPE_NUMERIC:
67  mstringgrids[i].resize(0);
68  break;
69  case GRID_TYPE_STRING:
72  mnumericgrids[i].resize(0);
73  break;
74  }
75  }
76 }
77 
79 
88  assert(i < dim);
89  if (mgridtypes[i] != GRID_TYPE_NUMERIC) {
90  ostringstream os;
91 
92  if (mname.length()) os << mname << " ";
93 
94  os << "Grid ";
95  if (mgridnames[i].length())
96  os << mgridnames[i];
97  else
98  os << i;
99  os << " is not a numeric grid.";
100 
101  throw runtime_error(os.str());
102  }
103 
104  return mnumericgrids[i];
105 }
106 
108 
117  assert(i < dim);
118  if (mgridtypes[i] != GRID_TYPE_NUMERIC) {
119  ostringstream os;
120 
121  if (mname.length()) os << mname << " ";
122 
123  os << "Grid ";
124  if (mgridnames[i].length())
125  os << mgridnames[i];
126  else
127  os << i;
128  os << " is not a numeric grid.";
129 
130  throw runtime_error(os.str());
131  }
132 
133  return mnumericgrids[i];
134 }
135 
137 
146  assert(i < dim);
147  if (mgridtypes[i] != GRID_TYPE_STRING) {
148  ostringstream os;
149 
150  if (mname.length()) os << mname << " ";
151 
152  os << "Grid ";
153  if (mgridnames[i].length())
154  os << mgridnames[i];
155  else
156  os << i;
157  os << " is not a string grid.";
158 
159  throw runtime_error(os.str());
160  }
161 
162  return (mstringgrids[i]);
163 }
164 
166 
175  assert(i < dim);
176  if (mgridtypes[i] != GRID_TYPE_STRING) {
177  ostringstream os;
178 
179  if (mname.length()) os << mname << " ";
180 
181  os << "Grid ";
182  if (mgridnames[i].length())
183  os << mgridnames[i];
184  else
185  os << i;
186  os << " is not a string grid.";
187 
188  throw runtime_error(os.str());
189  }
190 
191  return (mstringgrids[i]);
192 }
193 
195 
202  assert(i < dim);
204  mstringgrids[i].resize(0);
205  mnumericgrids[i] = g;
206 }
207 
209 
216  assert(i < dim);
218  mnumericgrids[i].resize(0);
219  mstringgrids[i] = g;
220 }
221 
223 
229 ostream& operator<<(ostream& os, const GriddedField& gf) {
230  if (gf.mname.size()) os << gf.mname << ":" << endl;
231 
232  for (Index i = 0; i < gf.dim; i++) {
233  if (gf.mgridnames[i].size())
234  os << gf.mgridnames[i];
235  else
236  os << "Grid " << i;
237  os << ": ";
238  switch (gf.mgridtypes[i]) {
239  case GRID_TYPE_STRING:
240  os << gf.mstringgrids[i];
241  break;
242  case GRID_TYPE_NUMERIC:
243  os << gf.mnumericgrids[i];
244  break;
245  }
246  os << endl;
247  }
248 
249  return os;
250 }
251 
253 ostream& operator<<(ostream& os, const GriddedField1& gf) {
254  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
255 }
256 
258 ostream& operator<<(ostream& os, const GriddedField2& gf) {
259  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
260 }
261 
263 ostream& operator<<(ostream& os, const GriddedField3& gf) {
264  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
265 }
266 
268 ostream& operator<<(ostream& os, const GriddedField4& gf) {
269  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
270 }
271 
273 ostream& operator<<(ostream& os, const GriddedField5& gf) {
274  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
275 }
276 
278 ostream& operator<<(ostream& os, const GriddedField6& gf) {
279  return os << *((GriddedField*)&gf) << "Data:" << endl << gf.data << endl;
280 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
The Vector class.
Definition: matpackI.h:860
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.
_CS_string_type str() const
Definition: sstream.h:491
ArrayOfVector mnumericgrids
void set_grid(Index i, const Vector &g)
Set a numeric grid.
The declarations of all the exception classes.
Array< ArrayOfString > mstringgrids
const Vector & get_numeric_grid(Index i) const
Get a numeric grid.
friend std::ostream & operator<<(std::ostream &os, const GriddedField &gf)
basic_ostringstream< char, string_char_traits< char >, alloc > ostringstream
Definition: sstream.h:204
Implementation of gridded fields.
Array< GridType > mgridtypes
This file contains the definition of String, the ARTS string class.