ARTS  2.2.66
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 "matpackV.h"
36 #include "gridded_fields.h"
37 
38 /* Workspace method: Doxygen documentation will be auto-generated */
39 /* This template function covers all implementations of extracting
40  an element X from an ArrayOfX
41  */
42 template <typename T>
43 void Extract(
44  // WS Generic Output:
45  T& e,
46  // WS Input:
47  // WS Generic Input:
48  const Array<T>& arr,
49  const Index& index,
50  const Verbosity&)
51 {
52  if( index >= arr.nelem() )
53  {
54  ostringstream os;
55  os << "The index " << index
56  << " is outside the range of the array.";
57  throw runtime_error( os.str() );
58 
59  }
60 
61  e = arr[index];
62 }
63 
64 
65 /* Workspace method: Doxygen documentation will be auto-generated */
67  // WS Generic Output:
68  ArrayOfIndex& aoi,
69  // WS Input:
70  // WS Generic Input:
71  const ArrayOfArrayOfIndex& aoaoi,
72  const Index& index,
73  const Verbosity&)
74 {
75  if( index >= aoaoi.nelem() )
76  {
77  ostringstream os;
78  os << "The index " << index
79  << " is outside the range of the Array.";
80  throw runtime_error( os.str() );
81 
82  }
83 
84  aoi.resize( aoaoi[index].nelem() );
85  aoi = aoaoi[index];
86 }
87 
88 
89 /* Workspace method: Doxygen documentation will be auto-generated */
90 void Extract(
91  // WS Generic Output:
92  Numeric& n,
93  // WS Input:
94  // WS Generic Input:
95  const Vector& v,
96  const Index& index,
97  const Verbosity&)
98 {
99  if( index >= v.nelem() )
100  {
101  ostringstream os;
102  os << "The index " << index
103  << " is outside the range of the Vector.";
104  throw runtime_error( os.str() );
105 
106  }
107 
108  n = v[ index ];
109 }
110 
111 
112 /* Workspace method: Doxygen documentation will be auto-generated */
113 void Extract(
114  // WS Generic Output:
115  Matrix& m,
116  // WS Input:
117  // WS Generic Input:
118  const Tensor3& t3,
119  const Index& index,
120  const Verbosity&)
121 {
122  if( index >= t3.npages() )
123  {
124  ostringstream os;
125  os << "The index " << index
126  << " is outside the page range of the Tensor3.";
127  throw runtime_error( os.str() );
128 
129  }
130 
131  m = t3( index, joker, joker );
132 }
133 
134 
135 /* Workspace method: Doxygen documentation will be auto-generated */
136 void Extract(
137  // WS Generic Output:
138  Tensor3& t3,
139  // WS Input:
140  // WS Generic Input:
141  const Tensor4& t4,
142  const Index& index,
143  const Verbosity&)
144 {
145  if( index >= t4.nbooks() )
146  {
147  ostringstream os;
148  os << "The index " << index
149  << " is outside the book range of the Tensor4.";
150  throw runtime_error( os.str() );
151 
152  }
153 
154  t3.resize( t4.npages(), t4.nrows(), t4.ncols() );
155  t3 = t4( index, joker, joker, joker );
156 }
157 
158 
159 /* Workspace method: Doxygen documentation will be auto-generated */
160 void Extract(
161  // WS Generic Output:
162  Tensor4& t4,
163  // WS Input:
164  // WS Generic Input:
165  const Tensor5& t5,
166  const Index& index,
167  const Verbosity&)
168 {
169  if( index >= t5.nshelves() )
170  {
171  ostringstream os;
172  os << "The index " << index
173  << "is outside the shelf range of the Tensor5.";
174  throw runtime_error( os.str() );
175 
176  }
177 
178  t4.resize( t5.nbooks(), t5.npages(), t5.nrows(), t5.ncols() );
179  t4 = t5( index, joker, joker, joker, joker );
180 }
181 
182 
183 /* Workspace method: Doxygen documentation will be auto-generated
184 
185  Implementation largely copied from Patrick's MatrixExtractFromTensor3 method.
186 
187  2007-10-26 Oliver Lemke */
188 void Extract(
189  // WS Generic Output:
191  // WS Input:
192  // WS Generic Input:
193  const ArrayOfArrayOfGriddedField3& aagf,
194  const Index& index,
195  const Verbosity&)
196 {
197  if( index >= aagf.nelem() )
198  {
199  ostringstream os;
200  os << "The index " << index
201  << " is outside the range of the ArrayOfArrayOfGriddedField3.";
202  throw runtime_error( os.str() );
203 
204  }
205 
206  agf.resize( aagf[index].nelem() );
207  agf = aagf[index];
208 }
209 
210 
211 /* Workspace method: Doxygen documentation will be auto-generated
212 
213  Implementation largely copied from MatrixExtractFromArrayOfMatrix.
214 
215  2007-11-26 Stefan Buehler */
216 void Extract(
217  // WS Generic Output:
218  GriddedField4& m,
219  // WS Input:
220  // WS Generic Input:
221  const ArrayOfGriddedField4& agf4,
222  const Index& index,
223  const Verbosity&)
224 {
225  if( index >= agf4.nelem() )
226  {
227  ostringstream os;
228  os << "The index " << index
229  << " is outside the range of The ArrayOfGriddedField4.";
230  throw runtime_error( os.str() );
231 
232  }
233 
234  // I simply use the copy operator here, since I'm too lazy to go
235  // through all members of the structure to resize them. That is not
236  // necessary, since sizes are adjusted automatically.
237  m = agf4[index];
238 }
239 
240 
241 
242 
243 #endif /* m_extract_h */
244 
Matrix
The Matrix class.
Definition: matpackI.h:788
gridded_fields.h
Implementation of gridded fields.
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1403
ConstTensor5View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:41
exceptions.h
The declarations of all the exception classes.
Tensor3
The Tensor3 class.
Definition: matpackIII.h:348
ConstTensor5View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:59
joker
const Joker joker
ArrayOfIndexExtractFromArrayOfArrayOfIndex
void ArrayOfIndexExtractFromArrayOfArrayOfIndex(ArrayOfIndex &aoi, const ArrayOfArrayOfIndex &aoaoi, const Index &index, const Verbosity &)
Definition: m_extract.h:66
Tensor4
The Tensor4 class.
Definition: matpackIV.h:383
array.h
This file contains the definition of Array.
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:862
ConstTensor5View::npages
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:47
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:143
Array
This can be used to make arrays out of anything.
Definition: array.h:107
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:180
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:81
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Verbosity
Definition: messages.h:50
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:69
GriddedField4
Definition: gridded_fields.h:374
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:63
Extract
void Extract(T &e, const Array< T > &arr, const Index &index, const Verbosity &)
Definition: m_extract.h:43
Tensor5
The Tensor5 class.
Definition: matpackV.h:451
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:75
ConstTensor5View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
matpackV.h
ConstTensor5View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:35
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Vector
The Vector class.
Definition: matpackI.h:556
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:176