ARTS  2.3.1285(git:92a29ea9-dirty)
m_extract.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Stefan Buehler <sbuehler@ltu.se>
2  Oliver Lemke <olemke@core-dump.info>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the
6  Free Software Foundation; either version 2, or (at your option) any
7  later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17  USA. */
18 
30 #ifndef m_extract_h
31 #define m_extract_h
32 
33 #include "array.h"
34 #include "exceptions.h"
35 #include "gridded_fields.h"
36 #include "matpackV.h"
37 #include "quantum.h"
38 
39 /* Workspace method: Doxygen documentation will be auto-generated */
40 /* This template function covers all implementations of extracting
41  an element X from an ArrayOfX
42  */
43 template <typename T>
44 void Extract(
45  // WS Generic Output:
46  T& e,
47  // WS Input:
48  // WS Generic Input:
49  const Array<T>& arr,
50  const Index& index,
51  const Verbosity&) {
52  if (index >= arr.nelem()) {
53  ostringstream os;
54  os << "The index " << index << " is outside the range of the array.";
55  throw runtime_error(os.str());
56  }
57 
58  e = arr[index];
59 }
60 
61 /* Workspace method: Doxygen documentation will be auto-generated */
63  // WS Generic Output:
64  ArrayOfIndex& aoi,
65  // WS Input:
66  // WS Generic Input:
67  const ArrayOfArrayOfIndex& aoaoi,
68  const Index& index,
69  const Verbosity&) {
70  if (index >= aoaoi.nelem()) {
71  ostringstream os;
72  os << "The index " << index << " is outside the range of the Array.";
73  throw runtime_error(os.str());
74  }
75 
76  aoi.resize(aoaoi[index].nelem());
77  aoi = aoaoi[index];
78 }
79 
80 /* Workspace method: Doxygen documentation will be auto-generated */
81 inline void Extract(
82  // WS Generic Output:
83  Numeric& n,
84  // WS Input:
85  // WS Generic Input:
86  const Vector& v,
87  const Index& index,
88  const Verbosity&) {
89  if (index >= v.nelem()) {
90  ostringstream os;
91  os << "The index " << index << " is outside the range of the Vector.";
92  throw runtime_error(os.str());
93  }
94 
95  n = v[index];
96 }
97 
98 /* Workspace method: Doxygen documentation will be auto-generated */
99 inline void Extract(
100  // WS Generic Output:
101  Matrix& m,
102  // WS Input:
103  // WS Generic Input:
104  const Tensor3& t3,
105  const Index& index,
106  const Verbosity&) {
107  if (index >= t3.npages()) {
108  ostringstream os;
109  os << "The index " << index << " is outside the page range of the Tensor3.";
110  throw runtime_error(os.str());
111  }
112 
113  m = t3(index, joker, joker);
114 }
115 
116 /* Workspace method: Doxygen documentation will be auto-generated */
117 inline void Extract(
118  // WS Generic Output:
119  Tensor3& t3,
120  // WS Input:
121  // WS Generic Input:
122  const Tensor4& t4,
123  const Index& index,
124  const Verbosity&) {
125  if (index >= t4.nbooks()) {
126  ostringstream os;
127  os << "The index " << index << " is outside the book range of the Tensor4.";
128  throw runtime_error(os.str());
129  }
130 
131  t3.resize(t4.npages(), t4.nrows(), t4.ncols());
132  t3 = t4(index, joker, joker, joker);
133 }
134 
135 /* Workspace method: Doxygen documentation will be auto-generated */
136 inline void Extract(
137  // WS Generic Output:
138  Tensor4& t4,
139  // WS Input:
140  // WS Generic Input:
141  const Tensor5& t5,
142  const Index& index,
143  const Verbosity&) {
144  if (index >= t5.nshelves()) {
145  ostringstream os;
146  os << "The index " << index << "is outside the shelf range of the Tensor5.";
147  throw runtime_error(os.str());
148  }
149 
150  t4.resize(t5.nbooks(), t5.npages(), t5.nrows(), t5.ncols());
151  t4 = t5(index, joker, joker, joker, joker);
152 }
153 
154 /* Workspace method: Doxygen documentation will be auto-generated
155 
156  Implementation largely copied from Patrick's MatrixExtractFromTensor3 method.
157 
158  2007-10-26 Oliver Lemke */
159 inline void Extract(
160  // WS Generic Output:
162  // WS Input:
163  // WS Generic Input:
164  const ArrayOfArrayOfGriddedField3& aagf,
165  const Index& index,
166  const Verbosity&) {
167  if (index >= aagf.nelem()) {
168  ostringstream os;
169  os << "The index " << index
170  << " is outside the range of the ArrayOfArrayOfGriddedField3.";
171  throw runtime_error(os.str());
172  }
173 
174  agf.resize(aagf[index].nelem());
175  agf = aagf[index];
176 }
177 
178 /* Workspace method: Doxygen documentation will be auto-generated
179 
180  Implementation largely copied from MatrixExtractFromArrayOfMatrix.
181 
182  2007-11-26 Stefan Buehler */
183 inline void Extract(
184  // WS Generic Output:
185  GriddedField4& m,
186  // WS Input:
187  // WS Generic Input:
188  const ArrayOfGriddedField4& agf4,
189  const Index& index,
190  const Verbosity&) {
191  if (index >= agf4.nelem()) {
192  ostringstream os;
193  os << "The index " << index
194  << " is outside the range of The ArrayOfGriddedField4.";
195  throw runtime_error(os.str());
196  }
197 
198  // I simply use the copy operator here, since I'm too lazy to go
199  // through all members of the structure to resize them. That is not
200  // necessary, since sizes are adjusted automatically.
201  m = agf4[index];
202 }
203 
204 inline void Extract(
205  // WS Generic Output:
206  QuantumIdentifier& qi,
207  // WS Input:
208  // WS Generic Input:
209  const ArrayOfQuantumIdentifier& aoqi,
210  const Index& index,
211  const Verbosity&) {
212  if (index > aoqi.nelem() or index < 0) throw std::runtime_error("Bad index");
213  qi = aoqi[index];
214 }
215 
216 #endif /* m_extract_h */
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:50
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
Index nelem() const
Number of elements.
Definition: array.h:195
The Vector class.
Definition: matpackI.h:860
The Tensor4 class.
Definition: matpackIV.h:421
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:60
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:47
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:63
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
void Extract(T &e, const Array< T > &arr, const Index &index, const Verbosity &)
Definition: m_extract.h:44
This file contains the definition of Array.
The Tensor3 class.
Definition: matpackIII.h:339
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:44
_CS_string_type str() const
Definition: sstream.h:491
The declarations of all the exception classes.
Class to identify and match lines by their quantum numbers.
Definition: quantum.h:390
const Joker joker
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
The Matrix class.
Definition: matpackI.h:1193
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:664
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:144
This can be used to make arrays out of anything.
Definition: array.h:40
Index nelem(const Lines &l)
Number of lines.
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:57
Implementation of gridded fields.
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
void ArrayOfIndexExtractFromArrayOfArrayOfIndex(ArrayOfIndex &aoi, const ArrayOfArrayOfIndex &aoaoi, const Index &index, const Verbosity &)
Definition: m_extract.h:62
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1064
The Tensor5 class.
Definition: matpackV.h:506