00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00030 #ifndef m_extract_h
00031 #define m_extract_h
00032
00033 #include "array.h"
00034 #include "exceptions.h"
00035 #include "matpackV.h"
00036 #include "gridded_fields.h"
00037
00038
00039 template <typename T>
00040 void Extract(
00041
00042 T& e,
00043
00044
00045 const Array<T>& arr,
00046 const Index& index)
00047 {
00048 if( index >= arr.nelem() )
00049 {
00050 ostringstream os;
00051 os << "The index " << index
00052 << " is outside the range of the array.";
00053 throw runtime_error( os.str() );
00054
00055 }
00056
00057 e = arr[index];
00058 }
00059
00060
00061
00062 void ArrayOfIndexExtractFromArrayOfArrayOfIndex(
00063
00064 ArrayOfIndex& aoi,
00065
00066
00067 const ArrayOfArrayOfIndex& aoaoi,
00068 const Index& index)
00069 {
00070 if( index >= aoaoi.nelem() )
00071 {
00072 ostringstream os;
00073 os << "The index " << index
00074 << " is outside the range of the Array.";
00075 throw runtime_error( os.str() );
00076
00077 }
00078
00079 aoi.resize( aoaoi[index].nelem() );
00080 aoi = aoaoi[index];
00081 }
00082
00083
00084
00085 void Extract(
00086
00087 Numeric& n,
00088
00089
00090 const Vector& v,
00091 const Index& index)
00092 {
00093 if( index >= v.nelem() )
00094 {
00095 ostringstream os;
00096 os << "The index " << index
00097 << " is outside the range of the Vector.";
00098 throw runtime_error( os.str() );
00099
00100 }
00101
00102 n = v[ index ];
00103 }
00104
00105
00106
00107 void Extract(
00108
00109 Matrix& m,
00110
00111
00112 const Tensor3& t3,
00113 const Index& index)
00114 {
00115 if( index >= t3.npages() )
00116 {
00117 ostringstream os;
00118 os << "The index " << index
00119 << " is outside the page range of the Tensor3.";
00120 throw runtime_error( os.str() );
00121
00122 }
00123
00124 m = t3( index, joker, joker );
00125 }
00126
00127
00128
00129 void Extract(
00130
00131 Tensor3& t3,
00132
00133
00134 const Tensor4& t4,
00135 const Index& index)
00136 {
00137 if( index >= t4.nbooks() )
00138 {
00139 ostringstream os;
00140 os << "The index " << index
00141 << " is outside the book range of the Tensor4.";
00142 throw runtime_error( os.str() );
00143
00144 }
00145
00146 t3.resize( t4.npages(), t4.nrows(), t4.ncols() );
00147 t3 = t4( index, joker, joker, joker );
00148 }
00149
00150
00151
00152 void Extract(
00153
00154 Tensor4& t4,
00155
00156
00157 const Tensor5& t5,
00158 const Index& index)
00159 {
00160 if( index >= t5.nshelves() )
00161 {
00162 ostringstream os;
00163 os << "The index " << index
00164 << "is outside the shelf range of the Tensor5.";
00165 throw runtime_error( os.str() );
00166
00167 }
00168
00169 t4.resize( t5.nbooks(), t5.npages(), t5.nrows(), t5.ncols() );
00170 t4 = t5( index, joker, joker, joker, joker );
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 void Extract(
00180
00181 ArrayOfGField3& agf,
00182
00183
00184 const ArrayOfArrayOfGField3& aagf,
00185 const Index& index)
00186 {
00187 if( index >= aagf.nelem() )
00188 {
00189 ostringstream os;
00190 os << "The index " << index
00191 << " is outside the range of the ArrayOfArrayOfGField3.";
00192 throw runtime_error( os.str() );
00193
00194 }
00195
00196 agf.resize( aagf[index].nelem() );
00197 agf = aagf[index];
00198 }
00199
00200
00201
00202
00203
00204
00205
00206 void Extract(
00207
00208 GField4& m,
00209
00210
00211 const ArrayOfGField4& agf4,
00212 const Index& index)
00213 {
00214 if( index >= agf4.nelem() )
00215 {
00216 ostringstream os;
00217 os << "The index " << index
00218 << " is outside the range of The ArrayOfGField4.";
00219 throw runtime_error( os.str() );
00220
00221 }
00222
00223
00224
00225
00226 m = agf4[index];
00227 }
00228
00229
00230
00231
00232 #endif
00233