[594] | 1 | // Adaptateurs pour TMatrix TVector du package Sophya
|
---|
| 2 | // R. Ansari 1/99
|
---|
| 3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
| 4 |
|
---|
[2615] | 5 | #include "sopnamsp.h"
|
---|
[594] | 6 | #include "pitvmaad.h"
|
---|
| 7 | #include <math.h>
|
---|
| 8 |
|
---|
| 9 | /* --Methode-- */
|
---|
| 10 | template <class T>
|
---|
| 11 | POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad)
|
---|
| 12 | : P1DArrayAdapter(v->NElts())
|
---|
| 13 | {
|
---|
| 14 | aDel = ad;
|
---|
| 15 | mVec = v;
|
---|
| 16 | }
|
---|
| 17 | /* --Methode-- */
|
---|
| 18 | template <class T>
|
---|
| 19 | POTVectorAdapter<T>::~POTVectorAdapter()
|
---|
| 20 | {
|
---|
| 21 | if (aDel) delete mVec;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /* --Methode-- */
|
---|
| 25 | template <class T>
|
---|
| 26 | double POTVectorAdapter<T>::Value(int i)
|
---|
| 27 | {
|
---|
| 28 | return((*mVec)(i));
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /* --Methode-- */
|
---|
[2343] | 32 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[594] | 33 | double POTVectorAdapter< complex<float> >::Value(int i)
|
---|
| 34 | {
|
---|
| 35 | double re,im;
|
---|
| 36 | re = (*mVec)(i).real();
|
---|
| 37 | im = (*mVec)(i).imag();
|
---|
| 38 | return(sqrt(re*re+im*im));
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /* --Methode-- */
|
---|
[2343] | 42 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[594] | 43 | double POTVectorAdapter< complex<double> >::Value(int i)
|
---|
| 44 | {
|
---|
| 45 | double re,im;
|
---|
| 46 | re = (*mVec)(i).real();
|
---|
| 47 | im = (*mVec)(i).imag();
|
---|
| 48 | return(sqrt(re*re+im*im));
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /* --Methode-- */
|
---|
| 52 | template <class T>
|
---|
| 53 | POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad)
|
---|
| 54 | : P2DArrayAdapter(mtx->NCols(), mtx->NRows())
|
---|
| 55 | {
|
---|
| 56 | aDel = ad;
|
---|
| 57 | mMtx = mtx;
|
---|
| 58 | }
|
---|
| 59 | /* --Methode-- */
|
---|
| 60 | template <class T>
|
---|
| 61 | POTMatrixAdapter<T>::~POTMatrixAdapter()
|
---|
| 62 | {
|
---|
| 63 | if (aDel) delete mMtx;
|
---|
| 64 | }
|
---|
| 65 | /* --Methode-- */
|
---|
| 66 | template <class T>
|
---|
| 67 | double POTMatrixAdapter<T>::Value(int ix, int iy)
|
---|
| 68 | {
|
---|
| 69 | return((double)(*mMtx)(iy, ix));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /* --Methode-- */
|
---|
[3520] | 73 | template <class T>
|
---|
| 74 | double POTMatrixAdapter<T>::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
| 75 | {
|
---|
| 76 | int ec;
|
---|
| 77 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
| 78 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
| 79 | double ss = 0.;
|
---|
| 80 | for(int j=jy1; j<=jy2; j++)
|
---|
| 81 | for(int i=ix1; i<=ix2; i++) ss += (double)((*mMtx)(j, i));
|
---|
| 82 | ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
|
---|
| 83 | return ss;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | /* --Methode-- */
|
---|
[2343] | 88 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[594] | 89 | double POTMatrixAdapter< complex<float> >::Value(int ix, int iy)
|
---|
| 90 | {
|
---|
| 91 | double re,im;
|
---|
| 92 | re = (*mMtx)(iy, ix).real();
|
---|
| 93 | im = (*mMtx)(iy, ix).imag();
|
---|
| 94 | return(sqrt(re*re+im*im));
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /* --Methode-- */
|
---|
[2343] | 98 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[594] | 99 | double POTMatrixAdapter< complex<double> >::Value(int ix, int iy)
|
---|
| 100 | {
|
---|
| 101 | double re,im;
|
---|
| 102 | re = (*mMtx)(iy, ix).real();
|
---|
| 103 | im = (*mMtx)(iy, ix).imag();
|
---|
| 104 | return(sqrt(re*re+im*im));
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[3520] | 107 | /* --Methode-- */
|
---|
| 108 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 109 | double POTMatrixAdapter< complex<float> >::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
| 110 | {
|
---|
| 111 | int ec;
|
---|
| 112 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
| 113 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
| 114 | complex<float> ss = 0.;
|
---|
| 115 | for(int j=jy1; j<=jy2; j++)
|
---|
| 116 | for(int i=ix1; i<=ix2; i++) ss += (*mMtx)(j, i);
|
---|
| 117 | ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
|
---|
| 118 | return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag());
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /* --Methode-- */
|
---|
| 122 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 123 | double POTMatrixAdapter< complex<double> >::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
| 124 | {
|
---|
| 125 | int ec;
|
---|
| 126 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
| 127 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
| 128 | complex<double> ss = 0.;
|
---|
| 129 | for(int j=jy1; j<=jy2; j++)
|
---|
| 130 | for(int i=ix1; i<=ix2; i++) ss += (*mMtx)(j, i);
|
---|
| 131 | ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
|
---|
| 132 | return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag());
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[594] | 135 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[3661] | 136 | #pragma define_template POTVectorAdapter< uint_1 >
|
---|
[2930] | 137 | #pragma define_template POTVectorAdapter< uint_2 >
|
---|
[3528] | 138 | #pragma define_template POTVectorAdapter< uint_4 >
|
---|
| 139 | #pragma define_template POTVectorAdapter< uint_8 >
|
---|
[3661] | 140 | #pragma define_template POTVectorAdapter< int_1 >
|
---|
[2930] | 141 | #pragma define_template POTVectorAdapter< int_2 >
|
---|
[594] | 142 | #pragma define_template POTVectorAdapter< int_4 >
|
---|
| 143 | #pragma define_template POTVectorAdapter< int_8 >
|
---|
| 144 | #pragma define_template POTVectorAdapter< float >
|
---|
| 145 | #pragma define_template POTVectorAdapter< double >
|
---|
| 146 | #pragma define_template POTVectorAdapter< complex<float> >
|
---|
| 147 | #pragma define_template POTVectorAdapter< complex<double> >
|
---|
| 148 |
|
---|
[3661] | 149 | #pragma define_template POTMatrixAdapter< uint_1 >
|
---|
[2930] | 150 | #pragma define_template POTMatrixAdapter< uint_2 >
|
---|
[3528] | 151 | #pragma define_template POTMatrixAdapter< uint_4 >
|
---|
| 152 | #pragma define_template POTMatrixAdapter< uint_8 >
|
---|
[3661] | 153 | #pragma define_template POTMatrixAdapter< int_1 >
|
---|
[2930] | 154 | #pragma define_template POTMatrixAdapter< int_2 >
|
---|
[594] | 155 | #pragma define_template POTMatrixAdapter< int_4 >
|
---|
| 156 | #pragma define_template POTMatrixAdapter< int_8 >
|
---|
| 157 | #pragma define_template POTMatrixAdapter< float >
|
---|
| 158 | #pragma define_template POTMatrixAdapter< double >
|
---|
| 159 | #pragma define_template POTMatrixAdapter< complex<float> >
|
---|
| 160 | #pragma define_template POTMatrixAdapter< complex<double> >
|
---|
| 161 | #endif
|
---|
| 162 |
|
---|
| 163 | #if defined(ANSI_TEMPLATES)
|
---|
[3661] | 164 | template class POTVectorAdapter< uint_1 >;
|
---|
[2930] | 165 | template class POTVectorAdapter< uint_2 >;
|
---|
[3528] | 166 | template class POTVectorAdapter< uint_4 >;
|
---|
| 167 | template class POTVectorAdapter< uint_8 >;
|
---|
[3661] | 168 | template class POTVectorAdapter< int_1 >;
|
---|
[2930] | 169 | template class POTVectorAdapter< int_2 >;
|
---|
[594] | 170 | template class POTVectorAdapter< int_4 >;
|
---|
| 171 | template class POTVectorAdapter< int_8 >;
|
---|
| 172 | template class POTVectorAdapter< float >;
|
---|
| 173 | template class POTVectorAdapter< double >;
|
---|
| 174 | template class POTVectorAdapter< complex<float> >;
|
---|
| 175 | template class POTVectorAdapter< complex<double> >;
|
---|
| 176 |
|
---|
[3661] | 177 | template class POTMatrixAdapter< uint_1 >;
|
---|
[2930] | 178 | template class POTMatrixAdapter< uint_2 >;
|
---|
[3528] | 179 | template class POTMatrixAdapter< uint_4 >;
|
---|
| 180 | template class POTMatrixAdapter< uint_8 >;
|
---|
[3661] | 181 | template class POTMatrixAdapter< int_1 >;
|
---|
[2930] | 182 | template class POTMatrixAdapter< int_2 >;
|
---|
[594] | 183 | template class POTMatrixAdapter< int_4 >;
|
---|
| 184 | template class POTMatrixAdapter< int_8 >;
|
---|
| 185 | template class POTMatrixAdapter< float >;
|
---|
| 186 | template class POTMatrixAdapter< double >;
|
---|
| 187 | template class POTMatrixAdapter< complex<float> >;
|
---|
| 188 | template class POTMatrixAdapter< complex<double> >;
|
---|
| 189 | #endif
|
---|