| [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 |  | 
|---|
| [3713] | 9 | // ------------------------------------------------------- | 
|---|
|  | 10 | // Decodage de la presence dans la chaine opt des options d'affichage pour tableaux complexes | 
|---|
|  | 11 | //   cdreal , cdimag , cdphase , cdmod , cdmod2 | 
|---|
|  | 12 | PICmplxDispOption StringToCmplxDispOption( string & opt ) | 
|---|
|  | 13 | { | 
|---|
|  | 14 | PICmplxDispOption dopt=PICDO_Module; | 
|---|
|  | 15 | size_t olen = opt.length(); | 
|---|
|  | 16 | if (opt.find("cdmod2")<olen) dopt=PICDO_Module2; | 
|---|
|  | 17 | else if (opt.find("cdmod")<olen) dopt=PICDO_Module; | 
|---|
|  | 18 | else if (opt.find("cdphas")<olen) dopt=PICDO_Phase; | 
|---|
|  | 19 | else if (opt.find("cdimag")<olen) dopt=PICDO_Imag; | 
|---|
|  | 20 | else if (opt.find("cdreal")<olen) dopt=PICDO_Real; | 
|---|
|  | 21 | else dopt=PICDO_Module; | 
|---|
|  | 22 | return dopt; | 
|---|
|  | 23 | } | 
|---|
|  | 24 |  | 
|---|
|  | 25 | /* --- Methodes de calcul inline pour valeurs de retour complexes ---- */ | 
|---|
|  | 26 | static inline double  _z_mod_( complex< r_4 > z) | 
|---|
|  | 27 | { | 
|---|
|  | 28 | return ( sqrt((double)(z.real()*z.real()+z.imag()*z.imag() ) ) ); | 
|---|
|  | 29 | } | 
|---|
|  | 30 | static inline double  _z_mod_( complex< r_8 > z) | 
|---|
|  | 31 | { | 
|---|
|  | 32 | return ( sqrt(z.real()*z.real()+z.imag()*z.imag() )  ); | 
|---|
|  | 33 | } | 
|---|
|  | 34 | static inline double  _z_mod2_( complex< r_4 > z) | 
|---|
|  | 35 | { | 
|---|
|  | 36 | return ( (double)(z.real()*z.real()+z.imag()*z.imag() ) ); | 
|---|
|  | 37 | } | 
|---|
|  | 38 | static inline double  _z_mod2_( complex< r_8 > z) | 
|---|
|  | 39 | { | 
|---|
|  | 40 | return ( z.real()*z.real()+z.imag()*z.imag() ); | 
|---|
|  | 41 | } | 
|---|
|  | 42 | /* ----------------------------  */ | 
|---|
|  | 43 |  | 
|---|
| [594] | 44 | /* --Methode-- */ | 
|---|
|  | 45 | template <class T> | 
|---|
| [3713] | 46 | POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad, PICmplxDispOption dopt) | 
|---|
| [594] | 47 | : P1DArrayAdapter(v->NElts()) | 
|---|
|  | 48 | { | 
|---|
| [3713] | 49 | dOpt = dopt; | 
|---|
| [594] | 50 | aDel = ad; | 
|---|
|  | 51 | mVec = v; | 
|---|
|  | 52 | } | 
|---|
|  | 53 | /* --Methode-- */ | 
|---|
|  | 54 | template <class T> | 
|---|
|  | 55 | POTVectorAdapter<T>::~POTVectorAdapter() | 
|---|
|  | 56 | { | 
|---|
|  | 57 | if (aDel) delete mVec; | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
|  | 60 | /* --Methode-- */ | 
|---|
|  | 61 | template <class T> | 
|---|
|  | 62 | double POTVectorAdapter<T>::Value(int i) | 
|---|
|  | 63 | { | 
|---|
| [3713] | 64 | return((double)(*mVec)(i)); | 
|---|
| [594] | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | /* --Methode-- */ | 
|---|
| [2343] | 68 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| [594] | 69 | double POTVectorAdapter< complex<float> >::Value(int i) | 
|---|
|  | 70 | { | 
|---|
| [3713] | 71 | switch (dOpt) { | 
|---|
|  | 72 | case PICDO_Module: | 
|---|
|  | 73 | return _z_mod_( (*mVec)(i) ); | 
|---|
|  | 74 | break; | 
|---|
|  | 75 | case PICDO_Real: | 
|---|
|  | 76 | return (double)(((*mVec)(i)).real()); | 
|---|
|  | 77 | break; | 
|---|
|  | 78 | case PICDO_Imag: | 
|---|
|  | 79 | return (double)(((*mVec)(i)).imag()); | 
|---|
|  | 80 | break; | 
|---|
|  | 81 | case PICDO_Phase: | 
|---|
|  | 82 | return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) ); | 
|---|
|  | 83 | break; | 
|---|
|  | 84 | case PICDO_Module2: | 
|---|
|  | 85 | return _z_mod2_( (*mVec)(i) ); | 
|---|
|  | 86 | break; | 
|---|
| [3833] | 87 | default: | 
|---|
|  | 88 | return 0.; | 
|---|
|  | 89 | break; | 
|---|
| [3713] | 90 | } | 
|---|
| [594] | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | /* --Methode-- */ | 
|---|
| [2343] | 94 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| [594] | 95 | double POTVectorAdapter< complex<double> >::Value(int i) | 
|---|
|  | 96 | { | 
|---|
| [3713] | 97 | switch (dOpt) { | 
|---|
|  | 98 | case PICDO_Module: | 
|---|
|  | 99 | return _z_mod_( (*mVec)(i) ); | 
|---|
|  | 100 | break; | 
|---|
|  | 101 | case PICDO_Real: | 
|---|
|  | 102 | return (double)(((*mVec)(i)).real()); | 
|---|
|  | 103 | break; | 
|---|
|  | 104 | case PICDO_Imag: | 
|---|
|  | 105 | return (double)(((*mVec)(i)).imag()); | 
|---|
|  | 106 | break; | 
|---|
|  | 107 | case PICDO_Phase: | 
|---|
|  | 108 | return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) ); | 
|---|
|  | 109 | break; | 
|---|
|  | 110 | case PICDO_Module2: | 
|---|
|  | 111 | return _z_mod2_( (*mVec)(i) ); | 
|---|
|  | 112 | break; | 
|---|
| [3833] | 113 | default: | 
|---|
|  | 114 | return 0.; | 
|---|
|  | 115 | break; | 
|---|
| [3713] | 116 | } | 
|---|
| [594] | 117 | } | 
|---|
|  | 118 |  | 
|---|
|  | 119 | /* --Methode-- */ | 
|---|
|  | 120 | template <class T> | 
|---|
| [3713] | 121 | POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad, PICmplxDispOption dopt) | 
|---|
| [594] | 122 | : P2DArrayAdapter(mtx->NCols(), mtx->NRows()) | 
|---|
|  | 123 | { | 
|---|
| [3713] | 124 | dOpt = dopt; | 
|---|
| [594] | 125 | aDel = ad; | 
|---|
|  | 126 | mMtx = mtx; | 
|---|
|  | 127 | } | 
|---|
|  | 128 | /* --Methode-- */ | 
|---|
|  | 129 | template <class T> | 
|---|
|  | 130 | POTMatrixAdapter<T>::~POTMatrixAdapter() | 
|---|
|  | 131 | { | 
|---|
|  | 132 | if (aDel)  delete mMtx; | 
|---|
|  | 133 | } | 
|---|
|  | 134 | /* --Methode-- */ | 
|---|
|  | 135 | template <class T> | 
|---|
|  | 136 | double POTMatrixAdapter<T>::Value(int ix, int iy) | 
|---|
|  | 137 | { | 
|---|
|  | 138 | return((double)(*mMtx)(iy, ix)); | 
|---|
|  | 139 | } | 
|---|
|  | 140 |  | 
|---|
|  | 141 | /* --Methode-- */ | 
|---|
| [3520] | 142 | template <class T> | 
|---|
|  | 143 | double POTMatrixAdapter<T>::MeanVal(int ix1, int ix2, int jy1, int jy2) | 
|---|
|  | 144 | { | 
|---|
|  | 145 | int ec; | 
|---|
|  | 146 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } | 
|---|
|  | 147 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } | 
|---|
|  | 148 | double ss = 0.; | 
|---|
|  | 149 | for(int j=jy1; j<=jy2; j++) | 
|---|
|  | 150 | for(int i=ix1; i<=ix2; i++)  ss += (double)((*mMtx)(j, i)); | 
|---|
|  | 151 | ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); | 
|---|
|  | 152 | return ss; | 
|---|
|  | 153 | } | 
|---|
|  | 154 |  | 
|---|
|  | 155 |  | 
|---|
|  | 156 | /* --Methode-- */ | 
|---|
| [2343] | 157 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| [594] | 158 | double POTMatrixAdapter< complex<float> >::Value(int ix, int iy) | 
|---|
|  | 159 | { | 
|---|
| [3713] | 160 | switch (dOpt) { | 
|---|
|  | 161 | case PICDO_Module: | 
|---|
|  | 162 | return _z_mod_( (*mMtx)(iy, ix) ); | 
|---|
|  | 163 | break; | 
|---|
|  | 164 | case PICDO_Real: | 
|---|
|  | 165 | return (double)(((*mMtx)(iy, ix)).real()); | 
|---|
|  | 166 | break; | 
|---|
|  | 167 | case PICDO_Imag: | 
|---|
|  | 168 | return (double)(((*mMtx)(iy, ix)).imag()); | 
|---|
|  | 169 | break; | 
|---|
|  | 170 | case PICDO_Phase: | 
|---|
|  | 171 | return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() ); | 
|---|
|  | 172 | break; | 
|---|
|  | 173 | case PICDO_Module2: | 
|---|
|  | 174 | return _z_mod2_( (*mMtx)(iy, ix) ); | 
|---|
|  | 175 | break; | 
|---|
| [3833] | 176 | default: | 
|---|
|  | 177 | return 0.; | 
|---|
|  | 178 | break; | 
|---|
| [3713] | 179 | } | 
|---|
| [594] | 180 | } | 
|---|
|  | 181 |  | 
|---|
|  | 182 | /* --Methode-- */ | 
|---|
| [2343] | 183 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| [594] | 184 | double POTMatrixAdapter< complex<double> >::Value(int ix, int iy) | 
|---|
|  | 185 | { | 
|---|
| [3713] | 186 | switch (dOpt) { | 
|---|
|  | 187 | case PICDO_Module: | 
|---|
|  | 188 | return _z_mod_( (*mMtx)(iy, ix) ); | 
|---|
|  | 189 | break; | 
|---|
|  | 190 | case PICDO_Real: | 
|---|
|  | 191 | return (double)(((*mMtx)(iy, ix)).real()); | 
|---|
|  | 192 | break; | 
|---|
|  | 193 | case PICDO_Imag: | 
|---|
|  | 194 | return (double)(((*mMtx)(iy, ix)).imag()); | 
|---|
|  | 195 | break; | 
|---|
|  | 196 | case PICDO_Phase: | 
|---|
|  | 197 | return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() ); | 
|---|
|  | 198 | break; | 
|---|
|  | 199 | case PICDO_Module2: | 
|---|
|  | 200 | return _z_mod2_( (*mMtx)(iy, ix) ); | 
|---|
|  | 201 | break; | 
|---|
| [3833] | 202 | default: | 
|---|
|  | 203 | return 0.; | 
|---|
|  | 204 | break; | 
|---|
| [3713] | 205 | } | 
|---|
| [594] | 206 | } | 
|---|
|  | 207 |  | 
|---|
| [3520] | 208 | /* --Methode-- */ | 
|---|
|  | 209 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 210 | double POTMatrixAdapter< complex<float> >::MeanVal(int ix1, int ix2, int jy1, int jy2) | 
|---|
|  | 211 | { | 
|---|
|  | 212 | int ec; | 
|---|
|  | 213 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } | 
|---|
|  | 214 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } | 
|---|
| [3713] | 215 | complex<float> ssz = complex<float>(0.,0.); | 
|---|
| [3520] | 216 | for(int j=jy1; j<=jy2; j++) | 
|---|
| [3713] | 217 | for(int i=ix1; i<=ix2; i++)  ssz += (*mMtx)(j, i); | 
|---|
|  | 218 | switch (dOpt) { | 
|---|
|  | 219 | case PICDO_Module: | 
|---|
|  | 220 | return _z_mod_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) ); | 
|---|
|  | 221 | break; | 
|---|
|  | 222 | case PICDO_Real: | 
|---|
|  | 223 | return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; | 
|---|
|  | 224 | break; | 
|---|
|  | 225 | case PICDO_Imag: | 
|---|
|  | 226 | return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; | 
|---|
|  | 227 | break; | 
|---|
|  | 228 | case PICDO_Phase: | 
|---|
|  | 229 | return atan2( (double) ssz.real(), (double) ssz.imag() ); | 
|---|
|  | 230 | break; | 
|---|
|  | 231 | case PICDO_Module2: | 
|---|
|  | 232 | return _z_mod2_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) ); | 
|---|
|  | 233 | break; | 
|---|
|  | 234 | } | 
|---|
|  | 235 | return 0.; | 
|---|
| [3520] | 236 | } | 
|---|
|  | 237 |  | 
|---|
|  | 238 | /* --Methode-- */ | 
|---|
|  | 239 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 240 | double POTMatrixAdapter< complex<double> >::MeanVal(int ix1, int ix2, int jy1, int jy2) | 
|---|
|  | 241 | { | 
|---|
|  | 242 | int ec; | 
|---|
|  | 243 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } | 
|---|
|  | 244 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } | 
|---|
| [3713] | 245 | complex<double> ssz = complex<double>(0.,0.); | 
|---|
| [3520] | 246 | for(int j=jy1; j<=jy2; j++) | 
|---|
| [3713] | 247 | for(int i=ix1; i<=ix2; i++)  ssz += (*mMtx)(j, i); | 
|---|
|  | 248 | switch (dOpt) { | 
|---|
|  | 249 | case PICDO_Module: | 
|---|
|  | 250 | return _z_mod_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) ); | 
|---|
|  | 251 | break; | 
|---|
|  | 252 | case PICDO_Real: | 
|---|
|  | 253 | return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; | 
|---|
|  | 254 | break; | 
|---|
|  | 255 | case PICDO_Imag: | 
|---|
|  | 256 | return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; | 
|---|
|  | 257 | break; | 
|---|
|  | 258 | case PICDO_Phase: | 
|---|
|  | 259 | return atan2( (double) ssz.real(), (double) ssz.imag() ); | 
|---|
|  | 260 | break; | 
|---|
|  | 261 | case PICDO_Module2: | 
|---|
|  | 262 | return _z_mod2_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) ); | 
|---|
|  | 263 | break; | 
|---|
|  | 264 | } | 
|---|
|  | 265 | return 0.; | 
|---|
| [3520] | 266 | } | 
|---|
|  | 267 |  | 
|---|
| [3713] | 268 |  | 
|---|
|  | 269 |  | 
|---|
|  | 270 |  | 
|---|
|  | 271 |  | 
|---|
| [594] | 272 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| [3661] | 273 | #pragma define_template POTVectorAdapter< uint_1 > | 
|---|
| [2930] | 274 | #pragma define_template POTVectorAdapter< uint_2 > | 
|---|
| [3528] | 275 | #pragma define_template POTVectorAdapter< uint_4 > | 
|---|
|  | 276 | #pragma define_template POTVectorAdapter< uint_8 > | 
|---|
| [3661] | 277 | #pragma define_template POTVectorAdapter< int_1 > | 
|---|
| [2930] | 278 | #pragma define_template POTVectorAdapter< int_2 > | 
|---|
| [594] | 279 | #pragma define_template POTVectorAdapter< int_4 > | 
|---|
|  | 280 | #pragma define_template POTVectorAdapter< int_8 > | 
|---|
|  | 281 | #pragma define_template POTVectorAdapter< float > | 
|---|
|  | 282 | #pragma define_template POTVectorAdapter< double > | 
|---|
|  | 283 | #pragma define_template POTVectorAdapter< complex<float> > | 
|---|
|  | 284 | #pragma define_template POTVectorAdapter< complex<double> > | 
|---|
|  | 285 |  | 
|---|
| [3661] | 286 | #pragma define_template POTMatrixAdapter< uint_1 > | 
|---|
| [2930] | 287 | #pragma define_template POTMatrixAdapter< uint_2 > | 
|---|
| [3528] | 288 | #pragma define_template POTMatrixAdapter< uint_4 > | 
|---|
|  | 289 | #pragma define_template POTMatrixAdapter< uint_8 > | 
|---|
| [3661] | 290 | #pragma define_template POTMatrixAdapter< int_1 > | 
|---|
| [2930] | 291 | #pragma define_template POTMatrixAdapter< int_2 > | 
|---|
| [594] | 292 | #pragma define_template POTMatrixAdapter< int_4 > | 
|---|
|  | 293 | #pragma define_template POTMatrixAdapter< int_8 > | 
|---|
|  | 294 | #pragma define_template POTMatrixAdapter< float > | 
|---|
|  | 295 | #pragma define_template POTMatrixAdapter< double > | 
|---|
|  | 296 | #pragma define_template POTMatrixAdapter< complex<float> > | 
|---|
|  | 297 | #pragma define_template POTMatrixAdapter< complex<double> > | 
|---|
|  | 298 | #endif | 
|---|
|  | 299 |  | 
|---|
|  | 300 | #if defined(ANSI_TEMPLATES) | 
|---|
| [3661] | 301 | template class POTVectorAdapter< uint_1 >; | 
|---|
| [2930] | 302 | template class POTVectorAdapter< uint_2 >; | 
|---|
| [3528] | 303 | template class POTVectorAdapter< uint_4 >; | 
|---|
|  | 304 | template class POTVectorAdapter< uint_8 >; | 
|---|
| [3661] | 305 | template class POTVectorAdapter< int_1 >; | 
|---|
| [2930] | 306 | template class POTVectorAdapter< int_2 >; | 
|---|
| [594] | 307 | template class POTVectorAdapter< int_4 >; | 
|---|
|  | 308 | template class POTVectorAdapter< int_8 >; | 
|---|
|  | 309 | template class POTVectorAdapter< float >; | 
|---|
|  | 310 | template class POTVectorAdapter< double >; | 
|---|
|  | 311 | template class POTVectorAdapter< complex<float> >; | 
|---|
|  | 312 | template class POTVectorAdapter< complex<double> >; | 
|---|
|  | 313 |  | 
|---|
| [3661] | 314 | template class POTMatrixAdapter< uint_1 >; | 
|---|
| [2930] | 315 | template class POTMatrixAdapter< uint_2 >; | 
|---|
| [3528] | 316 | template class POTMatrixAdapter< uint_4 >; | 
|---|
|  | 317 | template class POTMatrixAdapter< uint_8 >; | 
|---|
| [3661] | 318 | template class POTMatrixAdapter< int_1 >; | 
|---|
| [2930] | 319 | template class POTMatrixAdapter< int_2 >; | 
|---|
| [594] | 320 | template class POTMatrixAdapter< int_4 >; | 
|---|
|  | 321 | template class POTMatrixAdapter< int_8 >; | 
|---|
|  | 322 | template class POTMatrixAdapter< float >; | 
|---|
|  | 323 | template class POTMatrixAdapter< double >; | 
|---|
|  | 324 | template class POTMatrixAdapter< complex<float> >; | 
|---|
|  | 325 | template class POTMatrixAdapter< complex<double> >; | 
|---|
|  | 326 | #endif | 
|---|