ARTS 2.5.9 (git: 825fa5f2)
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_numbers.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 */
43template <typename T>
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
61inline void Extract(
62 // WS Generic Output:
63 SpeciesTag& e,
64 // WS Input:
65 // WS Generic Input:
66 const ArrayOfSpeciesTag& arr,
67 const Index& index,
68 const Verbosity&) {
69 if (index >= arr.nelem()) {
70 ostringstream os;
71 os << "The index " << index << " is outside the range of the array.";
72 throw runtime_error(os.str());
73 }
74
75 e = arr[index];
76}
77
78/* Workspace method: Doxygen documentation will be auto-generated */
80 // WS Generic Output:
81 ArrayOfIndex& aoi,
82 // WS Input:
83 // WS Generic Input:
84 const ArrayOfArrayOfIndex& aoaoi,
85 const Index& index,
86 const Verbosity&) {
87 if (index >= aoaoi.nelem()) {
88 ostringstream os;
89 os << "The index " << index << " is outside the range of the Array.";
90 throw runtime_error(os.str());
91 }
92
93 aoi.resize(aoaoi[index].nelem());
94 aoi = aoaoi[index];
95}
96
97/* Workspace method: Doxygen documentation will be auto-generated */
98inline void Extract(
99 // WS Generic Output:
100 Numeric& n,
101 // WS Input:
102 // WS Generic Input:
103 const Vector& v,
104 const Index& index,
105 const Verbosity&) {
106 if (index >= v.nelem()) {
107 ostringstream os;
108 os << "The index " << index << " is outside the range of the Vector.";
109 throw runtime_error(os.str());
110 }
111
112 n = v[index];
113}
114
115/* Workspace method: Doxygen documentation will be auto-generated */
116inline void Extract(
117 // WS Generic Output:
118 Matrix& m,
119 // WS Input:
120 // WS Generic Input:
121 const Tensor3& t3,
122 const Index& index,
123 const Verbosity&) {
124 if (index >= t3.npages()) {
125 ostringstream os;
126 os << "The index " << index << " is outside the page range of the Tensor3.";
127 throw runtime_error(os.str());
128 }
129
130 m = t3(index, joker, joker);
131}
132
133/* Workspace method: Doxygen documentation will be auto-generated */
134inline void Extract(
135 // WS Generic Output:
136 Tensor3& t3,
137 // WS Input:
138 // WS Generic Input:
139 const Tensor4& t4,
140 const Index& index,
141 const Verbosity&) {
142 if (index >= t4.nbooks()) {
143 ostringstream os;
144 os << "The index " << index << " is outside the book range of the Tensor4.";
145 throw runtime_error(os.str());
146 }
147
148 t3.resize(t4.npages(), t4.nrows(), t4.ncols());
149 t3 = t4(index, joker, joker, joker);
150}
151
152/* Workspace method: Doxygen documentation will be auto-generated */
153inline void Extract(
154 // WS Generic Output:
155 Tensor4& t4,
156 // WS Input:
157 // WS Generic Input:
158 const Tensor5& t5,
159 const Index& index,
160 const Verbosity&) {
161 if (index >= t5.nshelves()) {
162 ostringstream os;
163 os << "The index " << index << "is outside the shelf range of the Tensor5.";
164 throw runtime_error(os.str());
165 }
166
167 t4.resize(t5.nbooks(), t5.npages(), t5.nrows(), t5.ncols());
168 t4 = t5(index, joker, joker, joker, joker);
169}
170
171/* Workspace method: Doxygen documentation will be auto-generated
172
173 Implementation largely copied from Patrick's MatrixExtractFromTensor3 method.
174
175 2007-10-26 Oliver Lemke */
176inline void Extract(
177 // WS Generic Output:
179 // WS Input:
180 // WS Generic Input:
181 const ArrayOfArrayOfGriddedField3& aagf,
182 const Index& index,
183 const Verbosity&) {
184 if (index >= aagf.nelem()) {
185 ostringstream os;
186 os << "The index " << index
187 << " is outside the range of the ArrayOfArrayOfGriddedField3.";
188 throw runtime_error(os.str());
189 }
190
191 agf.resize(aagf[index].nelem());
192 agf = aagf[index];
193}
194
195/* Workspace method: Doxygen documentation will be auto-generated
196
197 Implementation largely copied from MatrixExtractFromArrayOfMatrix.
198
199 2007-11-26 Stefan Buehler */
200inline void Extract(
201 // WS Generic Output:
202 GriddedField4& m,
203 // WS Input:
204 // WS Generic Input:
205 const ArrayOfGriddedField4& agf4,
206 const Index& index,
207 const Verbosity&) {
208 if (index >= agf4.nelem()) {
209 ostringstream os;
210 os << "The index " << index
211 << " is outside the range of The ArrayOfGriddedField4.";
212 throw runtime_error(os.str());
213 }
214
215 // I simply use the copy operator here, since I'm too lazy to go
216 // through all members of the structure to resize them. That is not
217 // necessary, since sizes are adjusted automatically.
218 m = agf4[index];
219}
220
221inline void Extract(
222 // WS Generic Output:
224 // WS Input:
225 // WS Generic Input:
226 const ArrayOfQuantumIdentifier& aoqi,
227 const Index& index,
228 const Verbosity&) {
229 if (index > aoqi.nelem() or index < 0) throw std::runtime_error("Bad index");
230 qi = aoqi[index];
231}
232
233#endif /* m_extract_h */
This file contains the definition of Array.
This can be used to make arrays out of anything.
Definition: array.h:48
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:145
Index ncols() const noexcept
Definition: matpackIV.h:146
Index nrows() const noexcept
Definition: matpackIV.h:145
Index nbooks() const noexcept
Definition: matpackIV.h:143
Index npages() const noexcept
Definition: matpackIV.h:144
Index nrows() const noexcept
Definition: matpackV.h:157
Index ncols() const noexcept
Definition: matpackV.h:158
Index npages() const noexcept
Definition: matpackV.h:156
Index nbooks() const noexcept
Definition: matpackV.h:155
Index nshelves() const noexcept
Definition: matpackV.h:154
The Matrix class.
Definition: matpackI.h:1285
The Tensor3 class.
Definition: matpackIII.h:352
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:661
The Tensor4 class.
Definition: matpackIV.h:435
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1054
The Tensor5 class.
Definition: matpackV.h:524
The Vector class.
Definition: matpackI.h:910
The declarations of all the exception classes.
Implementation of gridded fields.
void Extract(T &e, const Array< T > &arr, const Index &index, const Verbosity &)
Definition: m_extract.h:44
void ArrayOfIndexExtractFromArrayOfArrayOfIndex(ArrayOfIndex &aoi, const ArrayOfArrayOfIndex &aoaoi, const Index &index, const Verbosity &)
Definition: m_extract.h:79
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
const Joker joker
Species::Tag SpeciesTag
Definition: species_tags.h:100
A logical struct for global quantum numbers with species identifiers.
#define v