| [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__ | 
|---|
| [2930] | 136 | #pragma define_template POTVectorAdapter< uint_2 > | 
|---|
| [3528] | 137 | #pragma define_template POTVectorAdapter< uint_4 > | 
|---|
|  | 138 | #pragma define_template POTVectorAdapter< uint_8 > | 
|---|
| [2930] | 139 | #pragma define_template POTVectorAdapter< int_2 > | 
|---|
| [594] | 140 | #pragma define_template POTVectorAdapter< int_4 > | 
|---|
|  | 141 | #pragma define_template POTVectorAdapter< int_8 > | 
|---|
|  | 142 | #pragma define_template POTVectorAdapter< float > | 
|---|
|  | 143 | #pragma define_template POTVectorAdapter< double > | 
|---|
|  | 144 | #pragma define_template POTVectorAdapter< complex<float> > | 
|---|
|  | 145 | #pragma define_template POTVectorAdapter< complex<double> > | 
|---|
|  | 146 |  | 
|---|
| [2930] | 147 | #pragma define_template POTMatrixAdapter< uint_2 > | 
|---|
| [3528] | 148 | #pragma define_template POTMatrixAdapter< uint_4 > | 
|---|
|  | 149 | #pragma define_template POTMatrixAdapter< uint_8 > | 
|---|
| [2930] | 150 | #pragma define_template POTMatrixAdapter< int_2 > | 
|---|
| [594] | 151 | #pragma define_template POTMatrixAdapter< int_4 > | 
|---|
|  | 152 | #pragma define_template POTMatrixAdapter< int_8 > | 
|---|
|  | 153 | #pragma define_template POTMatrixAdapter< float > | 
|---|
|  | 154 | #pragma define_template POTMatrixAdapter< double > | 
|---|
|  | 155 | #pragma define_template POTMatrixAdapter< complex<float> > | 
|---|
|  | 156 | #pragma define_template POTMatrixAdapter< complex<double> > | 
|---|
|  | 157 | #endif | 
|---|
|  | 158 |  | 
|---|
|  | 159 | #if defined(ANSI_TEMPLATES) | 
|---|
| [2930] | 160 | template class POTVectorAdapter< uint_2 >; | 
|---|
| [3528] | 161 | template class POTVectorAdapter< uint_4 >; | 
|---|
|  | 162 | template class POTVectorAdapter< uint_8 >; | 
|---|
| [2930] | 163 | template class POTVectorAdapter< int_2 >; | 
|---|
| [594] | 164 | template class POTVectorAdapter< int_4 >; | 
|---|
|  | 165 | template class POTVectorAdapter< int_8 >; | 
|---|
|  | 166 | template class POTVectorAdapter< float >; | 
|---|
|  | 167 | template class POTVectorAdapter< double >; | 
|---|
|  | 168 | template class POTVectorAdapter< complex<float> >; | 
|---|
|  | 169 | template class POTVectorAdapter< complex<double> >; | 
|---|
|  | 170 |  | 
|---|
| [2930] | 171 | template class POTMatrixAdapter< uint_2 >; | 
|---|
| [3528] | 172 | template class POTMatrixAdapter< uint_4 >; | 
|---|
|  | 173 | template class POTMatrixAdapter< uint_8 >; | 
|---|
| [2930] | 174 | template class POTMatrixAdapter< int_2 >; | 
|---|
| [594] | 175 | template class POTMatrixAdapter< int_4 >; | 
|---|
|  | 176 | template class POTMatrixAdapter< int_8 >; | 
|---|
|  | 177 | template class POTMatrixAdapter< float >; | 
|---|
|  | 178 | template class POTMatrixAdapter< double >; | 
|---|
|  | 179 | template class POTMatrixAdapter< complex<float> >; | 
|---|
|  | 180 | template class POTMatrixAdapter< complex<double> >; | 
|---|
|  | 181 | #endif | 
|---|