00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028 #ifndef m_select_h
00029 #define m_select_h
00030
00031 #include "messages.h"
00032 #include "mystring.h"
00033 #include "workspace_ng.h"
00034 #include "agenda_class.h"
00035
00036
00037
00038 template< class T >
00039 void Select(
00040 Array<T>& needles,
00041
00042 const Array<T>& haystack,
00043 const ArrayOfIndex& needleind)
00044 {
00045
00046
00047
00048 Array<T> dummy( needleind.nelem() );
00049
00050 for( Index i = 0; i < needleind.nelem(); i++)
00051 {
00052 if (haystack.nelem() <= needleind[i])
00053 {
00054 ostringstream os;
00055 os << "The input vector only has " << haystack.nelem()
00056 << " elements. But one of the needle indexes is "
00057 << needleind[i] << "." << endl;
00058 os << "The indexes must be between 0 and " << haystack.nelem() - 1;
00059 throw runtime_error (os.str());
00060 }
00061 else
00062 dummy[i] = haystack[needleind[i]];
00063 }
00064
00065 needles = dummy;
00066 }
00067
00068
00069
00070 void Select(
00071 Vector& needles,
00072
00073 const Vector& haystack,
00074 const ArrayOfIndex& needleind)
00075 {
00076
00077
00078
00079 Vector dummy( needleind.nelem() );
00080
00081 for( Index i = 0; i < needleind.nelem(); i++)
00082 {
00083 if (haystack.nelem() <= needleind[i])
00084 {
00085 ostringstream os;
00086 os << "The input vector only has " << haystack.nelem()
00087 << " elements. But one of the needle indexes is "
00088 << needleind[i] << "." << endl;
00089 os << "The indexes must be between 0 and " << haystack.nelem() - 1;
00090 throw runtime_error (os.str());
00091 }
00092 else
00093 dummy[i] = haystack[needleind[i]];
00094 }
00095
00096 needles = dummy;
00097 }
00098
00099
00100
00101 void Select(
00102 Matrix& needles,
00103
00104 const Matrix& haystack,
00105 const ArrayOfIndex& needleind)
00106 {
00107
00108
00109
00110 Matrix dummy( needleind.nelem(), haystack.ncols() );
00111
00112 for( Index i = 0; i < needleind.nelem(); i++)
00113 {
00114 if (haystack.nrows() <= needleind[i])
00115 {
00116 ostringstream os;
00117 os << "The input matrix only has " << haystack.nrows()
00118 << " rows. But one of the needle indexes is "
00119 << needleind[i] << "." << endl;
00120 os << "The indexes must be between 0 and " << haystack.nrows() - 1;
00121 throw runtime_error (os.str());
00122 }
00123 else
00124 dummy(i, joker) = haystack(needleind[i], joker);
00125 }
00126
00127 needles = dummy;
00128 }
00129
00130
00131 #endif // m_select_h