1 | // Adaptateurs pour TMatrix TVector du package Sophya
|
---|
2 | // R. Ansari 1/99
|
---|
3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
4 |
|
---|
5 | #include "sopnamsp.h"
|
---|
6 | #include "pitvmaad.h"
|
---|
7 | #include <math.h>
|
---|
8 |
|
---|
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 |
|
---|
44 | /* --Methode-- */
|
---|
45 | template <class T>
|
---|
46 | POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad, PICmplxDispOption dopt)
|
---|
47 | : P1DArrayAdapter(v->NElts())
|
---|
48 | {
|
---|
49 | dOpt = dopt;
|
---|
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 | {
|
---|
64 | return((double)(*mVec)(i));
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* --Methode-- */
|
---|
68 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
69 | double POTVectorAdapter< complex<float> >::Value(int i)
|
---|
70 | {
|
---|
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;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* --Methode-- */
|
---|
91 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
92 | double POTVectorAdapter< complex<double> >::Value(int i)
|
---|
93 | {
|
---|
94 | switch (dOpt) {
|
---|
95 | case PICDO_Module:
|
---|
96 | return _z_mod_( (*mVec)(i) );
|
---|
97 | break;
|
---|
98 | case PICDO_Real:
|
---|
99 | return (double)(((*mVec)(i)).real());
|
---|
100 | break;
|
---|
101 | case PICDO_Imag:
|
---|
102 | return (double)(((*mVec)(i)).imag());
|
---|
103 | break;
|
---|
104 | case PICDO_Phase:
|
---|
105 | return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) );
|
---|
106 | break;
|
---|
107 | case PICDO_Module2:
|
---|
108 | return _z_mod2_( (*mVec)(i) );
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | /* --Methode-- */
|
---|
114 | template <class T>
|
---|
115 | POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad, PICmplxDispOption dopt)
|
---|
116 | : P2DArrayAdapter(mtx->NCols(), mtx->NRows())
|
---|
117 | {
|
---|
118 | dOpt = dopt;
|
---|
119 | aDel = ad;
|
---|
120 | mMtx = mtx;
|
---|
121 | }
|
---|
122 | /* --Methode-- */
|
---|
123 | template <class T>
|
---|
124 | POTMatrixAdapter<T>::~POTMatrixAdapter()
|
---|
125 | {
|
---|
126 | if (aDel) delete mMtx;
|
---|
127 | }
|
---|
128 | /* --Methode-- */
|
---|
129 | template <class T>
|
---|
130 | double POTMatrixAdapter<T>::Value(int ix, int iy)
|
---|
131 | {
|
---|
132 | return((double)(*mMtx)(iy, ix));
|
---|
133 | }
|
---|
134 |
|
---|
135 | /* --Methode-- */
|
---|
136 | template <class T>
|
---|
137 | double POTMatrixAdapter<T>::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
138 | {
|
---|
139 | int ec;
|
---|
140 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
141 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
142 | double ss = 0.;
|
---|
143 | for(int j=jy1; j<=jy2; j++)
|
---|
144 | for(int i=ix1; i<=ix2; i++) ss += (double)((*mMtx)(j, i));
|
---|
145 | ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
|
---|
146 | return ss;
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | /* --Methode-- */
|
---|
151 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
152 | double POTMatrixAdapter< complex<float> >::Value(int ix, int iy)
|
---|
153 | {
|
---|
154 | switch (dOpt) {
|
---|
155 | case PICDO_Module:
|
---|
156 | return _z_mod_( (*mMtx)(iy, ix) );
|
---|
157 | break;
|
---|
158 | case PICDO_Real:
|
---|
159 | return (double)(((*mMtx)(iy, ix)).real());
|
---|
160 | break;
|
---|
161 | case PICDO_Imag:
|
---|
162 | return (double)(((*mMtx)(iy, ix)).imag());
|
---|
163 | break;
|
---|
164 | case PICDO_Phase:
|
---|
165 | return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() );
|
---|
166 | break;
|
---|
167 | case PICDO_Module2:
|
---|
168 | return _z_mod2_( (*mMtx)(iy, ix) );
|
---|
169 | break;
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* --Methode-- */
|
---|
174 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
175 | double POTMatrixAdapter< complex<double> >::Value(int ix, int iy)
|
---|
176 | {
|
---|
177 | switch (dOpt) {
|
---|
178 | case PICDO_Module:
|
---|
179 | return _z_mod_( (*mMtx)(iy, ix) );
|
---|
180 | break;
|
---|
181 | case PICDO_Real:
|
---|
182 | return (double)(((*mMtx)(iy, ix)).real());
|
---|
183 | break;
|
---|
184 | case PICDO_Imag:
|
---|
185 | return (double)(((*mMtx)(iy, ix)).imag());
|
---|
186 | break;
|
---|
187 | case PICDO_Phase:
|
---|
188 | return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() );
|
---|
189 | break;
|
---|
190 | case PICDO_Module2:
|
---|
191 | return _z_mod2_( (*mMtx)(iy, ix) );
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | /* --Methode-- */
|
---|
197 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
198 | double POTMatrixAdapter< complex<float> >::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
199 | {
|
---|
200 | int ec;
|
---|
201 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
202 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
203 | complex<float> ssz = complex<float>(0.,0.);
|
---|
204 | for(int j=jy1; j<=jy2; j++)
|
---|
205 | for(int i=ix1; i<=ix2; i++) ssz += (*mMtx)(j, i);
|
---|
206 | switch (dOpt) {
|
---|
207 | case PICDO_Module:
|
---|
208 | return _z_mod_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) );
|
---|
209 | break;
|
---|
210 | case PICDO_Real:
|
---|
211 | return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
|
---|
212 | break;
|
---|
213 | case PICDO_Imag:
|
---|
214 | return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
|
---|
215 | break;
|
---|
216 | case PICDO_Phase:
|
---|
217 | return atan2( (double) ssz.real(), (double) ssz.imag() );
|
---|
218 | break;
|
---|
219 | case PICDO_Module2:
|
---|
220 | return _z_mod2_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) );
|
---|
221 | break;
|
---|
222 | }
|
---|
223 | return 0.;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /* --Methode-- */
|
---|
227 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
228 | double POTMatrixAdapter< complex<double> >::MeanVal(int ix1, int ix2, int jy1, int jy2)
|
---|
229 | {
|
---|
230 | int ec;
|
---|
231 | if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
|
---|
232 | if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }
|
---|
233 | complex<double> ssz = complex<double>(0.,0.);
|
---|
234 | for(int j=jy1; j<=jy2; j++)
|
---|
235 | for(int i=ix1; i<=ix2; i++) ssz += (*mMtx)(j, i);
|
---|
236 | switch (dOpt) {
|
---|
237 | case PICDO_Module:
|
---|
238 | return _z_mod_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) );
|
---|
239 | break;
|
---|
240 | case PICDO_Real:
|
---|
241 | return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
|
---|
242 | break;
|
---|
243 | case PICDO_Imag:
|
---|
244 | return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
|
---|
245 | break;
|
---|
246 | case PICDO_Phase:
|
---|
247 | return atan2( (double) ssz.real(), (double) ssz.imag() );
|
---|
248 | break;
|
---|
249 | case PICDO_Module2:
|
---|
250 | return _z_mod2_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) );
|
---|
251 | break;
|
---|
252 | }
|
---|
253 | return 0.;
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 |
|
---|
260 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
261 | #pragma define_template POTVectorAdapter< uint_1 >
|
---|
262 | #pragma define_template POTVectorAdapter< uint_2 >
|
---|
263 | #pragma define_template POTVectorAdapter< uint_4 >
|
---|
264 | #pragma define_template POTVectorAdapter< uint_8 >
|
---|
265 | #pragma define_template POTVectorAdapter< int_1 >
|
---|
266 | #pragma define_template POTVectorAdapter< int_2 >
|
---|
267 | #pragma define_template POTVectorAdapter< int_4 >
|
---|
268 | #pragma define_template POTVectorAdapter< int_8 >
|
---|
269 | #pragma define_template POTVectorAdapter< float >
|
---|
270 | #pragma define_template POTVectorAdapter< double >
|
---|
271 | #pragma define_template POTVectorAdapter< complex<float> >
|
---|
272 | #pragma define_template POTVectorAdapter< complex<double> >
|
---|
273 |
|
---|
274 | #pragma define_template POTMatrixAdapter< uint_1 >
|
---|
275 | #pragma define_template POTMatrixAdapter< uint_2 >
|
---|
276 | #pragma define_template POTMatrixAdapter< uint_4 >
|
---|
277 | #pragma define_template POTMatrixAdapter< uint_8 >
|
---|
278 | #pragma define_template POTMatrixAdapter< int_1 >
|
---|
279 | #pragma define_template POTMatrixAdapter< int_2 >
|
---|
280 | #pragma define_template POTMatrixAdapter< int_4 >
|
---|
281 | #pragma define_template POTMatrixAdapter< int_8 >
|
---|
282 | #pragma define_template POTMatrixAdapter< float >
|
---|
283 | #pragma define_template POTMatrixAdapter< double >
|
---|
284 | #pragma define_template POTMatrixAdapter< complex<float> >
|
---|
285 | #pragma define_template POTMatrixAdapter< complex<double> >
|
---|
286 | #endif
|
---|
287 |
|
---|
288 | #if defined(ANSI_TEMPLATES)
|
---|
289 | template class POTVectorAdapter< uint_1 >;
|
---|
290 | template class POTVectorAdapter< uint_2 >;
|
---|
291 | template class POTVectorAdapter< uint_4 >;
|
---|
292 | template class POTVectorAdapter< uint_8 >;
|
---|
293 | template class POTVectorAdapter< int_1 >;
|
---|
294 | template class POTVectorAdapter< int_2 >;
|
---|
295 | template class POTVectorAdapter< int_4 >;
|
---|
296 | template class POTVectorAdapter< int_8 >;
|
---|
297 | template class POTVectorAdapter< float >;
|
---|
298 | template class POTVectorAdapter< double >;
|
---|
299 | template class POTVectorAdapter< complex<float> >;
|
---|
300 | template class POTVectorAdapter< complex<double> >;
|
---|
301 |
|
---|
302 | template class POTMatrixAdapter< uint_1 >;
|
---|
303 | template class POTMatrixAdapter< uint_2 >;
|
---|
304 | template class POTMatrixAdapter< uint_4 >;
|
---|
305 | template class POTMatrixAdapter< uint_8 >;
|
---|
306 | template class POTMatrixAdapter< int_1 >;
|
---|
307 | template class POTMatrixAdapter< int_2 >;
|
---|
308 | template class POTMatrixAdapter< int_4 >;
|
---|
309 | template class POTMatrixAdapter< int_8 >;
|
---|
310 | template class POTMatrixAdapter< float >;
|
---|
311 | template class POTMatrixAdapter< double >;
|
---|
312 | template class POTMatrixAdapter< complex<float> >;
|
---|
313 | template class POTMatrixAdapter< complex<double> >;
|
---|
314 | #endif
|
---|