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