1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <typeinfo>
|
---|
4 | #include <iostream>
|
---|
5 | #include <string>
|
---|
6 | #include <complex>
|
---|
7 |
|
---|
8 | #include "datatype.h"
|
---|
9 |
|
---|
10 | #include "tvector.h"
|
---|
11 | #include "objfitter.h"
|
---|
12 | #include "nomtmatvecadapter.h"
|
---|
13 | #include "piyfxdrw.h"
|
---|
14 | #include "pitvmaad.h"
|
---|
15 |
|
---|
16 | #include "fioarr.h"
|
---|
17 | #include "fitstarray.h"
|
---|
18 |
|
---|
19 |
|
---|
20 | //----------------------------------------------------------------
|
---|
21 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet TMatrix<T>
|
---|
22 | //----------------------------------------------------------------
|
---|
23 |
|
---|
24 |
|
---|
25 | /* --Methode-- */
|
---|
26 | template <class T>
|
---|
27 | NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
|
---|
28 | : NObjMgrAdapter(o)
|
---|
29 | {
|
---|
30 | mMtx = o;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /* --Methode-- */
|
---|
34 | template <class T>
|
---|
35 | NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | /* --Methode-- */
|
---|
40 | template <class T>
|
---|
41 | NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
|
---|
42 | {
|
---|
43 | TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
|
---|
44 | if (m) return ( new NOMAdapter_TMatrix<T>(m) );
|
---|
45 | return ( new NObjMgrAdapter(o) );
|
---|
46 | }
|
---|
47 |
|
---|
48 | /* --Methode-- */
|
---|
49 | template <class T>
|
---|
50 | string NOMAdapter_TMatrix<T>::GetDataObjType()
|
---|
51 | {
|
---|
52 | string type = "TMatrix< ";
|
---|
53 |
|
---|
54 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
55 | if (v != NULL) type = "TVector< ";
|
---|
56 |
|
---|
57 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
58 | type += DataTypeInfo<T>::getTypeName();
|
---|
59 | type += " > ";
|
---|
60 | return(type);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /* --Methode-- */
|
---|
64 | template <class T>
|
---|
65 | AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj(bool share)
|
---|
66 | {
|
---|
67 | if (mMtx == NULL) return(NULL);
|
---|
68 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
69 | if (v != NULL) return( new TVector<T>(*v, share) );
|
---|
70 | else return ( new TMatrix<T>(*mMtx, share) );
|
---|
71 | }
|
---|
72 |
|
---|
73 | /* --Methode-- */
|
---|
74 | template <class T>
|
---|
75 | void NOMAdapter_TMatrix<T>::ReadFits(string const & flnm)
|
---|
76 | {
|
---|
77 | FitsInFile fis(flnm);
|
---|
78 | fis >> (*mMtx);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* --Methode-- */
|
---|
82 | template <class T>
|
---|
83 | void NOMAdapter_TMatrix<T>::SaveFits(string const & flnm)
|
---|
84 | {
|
---|
85 | FitsOutFile fos(flnm);
|
---|
86 | fos << (*mMtx);
|
---|
87 | }
|
---|
88 | // ---- Specialisation pour complexes -----
|
---|
89 | #if defined(__SGICC__)
|
---|
90 | template <>
|
---|
91 | #endif
|
---|
92 | void NOMAdapter_TMatrix< complex<r_4> >::ReadFits(string const & flnm)
|
---|
93 | {
|
---|
94 | cout << " NOMAdapter_TMatrix< complex<r_4> >::ReadFits() - Error "
|
---|
95 | << " Not supported (complex data type)" << endl;
|
---|
96 | }
|
---|
97 | #if defined(__SGICC__)
|
---|
98 | template <>
|
---|
99 | #endif
|
---|
100 | void NOMAdapter_TMatrix< complex<r_4> >::SaveFits(string const & flnm)
|
---|
101 | {
|
---|
102 | cout << " NOMAdapter_TMatrix< complex<r_4> >::SaveFits() - Error "
|
---|
103 | << " Not supported (complex data type)" << endl;
|
---|
104 | }
|
---|
105 |
|
---|
106 | #if defined(__SGICC__)
|
---|
107 | template <>
|
---|
108 | #endif
|
---|
109 | void NOMAdapter_TMatrix< complex<r_8> >::ReadFits(string const & flnm)
|
---|
110 | {
|
---|
111 | cout << " NOMAdapter_TMatrix< complex<r_8> >::ReadFits() - Error "
|
---|
112 | << " Not supported (complex data type)" << endl;
|
---|
113 | }
|
---|
114 | #if defined(__SGICC__)
|
---|
115 | template <>
|
---|
116 | #endif
|
---|
117 | void NOMAdapter_TMatrix< complex<r_8> >::SaveFits(string const & flnm)
|
---|
118 | {
|
---|
119 | cout << " NOMAdapter_TMatrix< complex<r_8> >::SaveFits() - Error "
|
---|
120 | << " Not supported (complex data type)" << endl;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /* --Methode-- */
|
---|
124 | template <class T>
|
---|
125 | void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
126 | {
|
---|
127 | if (mMtx == NULL) return;
|
---|
128 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
129 | if (v != NULL) {
|
---|
130 | FIO_TArray<T> fio(v);
|
---|
131 | fio.Write(pos, nom);
|
---|
132 | }
|
---|
133 | else {
|
---|
134 | FIO_TArray<T> fio(mMtx);
|
---|
135 | fio.Write(pos, nom);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* --Methode-- */
|
---|
140 | template <class T>
|
---|
141 | void NOMAdapter_TMatrix<T>::Print(ostream& os)
|
---|
142 | {
|
---|
143 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
144 | if (v != NULL) os << (*v);
|
---|
145 | else os << (*mMtx);
|
---|
146 | }
|
---|
147 |
|
---|
148 | /* --Methode-- */
|
---|
149 | template <class T>
|
---|
150 | PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
|
---|
151 | {
|
---|
152 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
153 | if (v == NULL) return(NULL);
|
---|
154 | else {
|
---|
155 | dopt = "thinline " + dopt;
|
---|
156 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | /* --Methode-- */
|
---|
161 | template <class T>
|
---|
162 | P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
|
---|
163 | {
|
---|
164 | return ( new POTMatrixAdapter<T>(mMtx, false) );
|
---|
165 | }
|
---|
166 |
|
---|
167 | /* --Methode-- */
|
---|
168 | template <class T>
|
---|
169 | NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
|
---|
170 | {
|
---|
171 | adel = true;
|
---|
172 | return( new NTupInt_TMatrix<T>(mMtx) );
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | /* --Methode-- */
|
---|
177 | template <class T>
|
---|
178 | GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
|
---|
179 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
180 | ,int i1,int i2,int j1,int j2)
|
---|
181 | {
|
---|
182 | adel = false;
|
---|
183 | if(!mMtx) return(NULL);
|
---|
184 |
|
---|
185 | int nx,ny;
|
---|
186 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
187 |
|
---|
188 | if(vec) { // C'est un TVector
|
---|
189 | nx = vec->NElts();
|
---|
190 | ny = 1;
|
---|
191 | } else {
|
---|
192 | nx = mMtx->NRows();
|
---|
193 | ny = mMtx->NCol();
|
---|
194 | if(nx<=0 || ny<=0) return(NULL);
|
---|
195 | }
|
---|
196 |
|
---|
197 | i1 = (i1<0||i1>=nx)? 0: i1;
|
---|
198 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
|
---|
199 | j1 = (j1<0||j1>=ny)? 0: j1;
|
---|
200 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
|
---|
201 |
|
---|
202 | GeneralFitData* mGData = NULL;
|
---|
203 |
|
---|
204 | if(vec) { // C'est un TVector
|
---|
205 | mGData = new GeneralFitData(1,(i2-i1+1),0);
|
---|
206 | adel = true;
|
---|
207 | for(int i=i1;i<=i2;i++) {
|
---|
208 | double x = (double) i;
|
---|
209 | double f = (*vec)(i);
|
---|
210 | double e = 1.;
|
---|
211 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
212 | mGData->AddData1(x,f,e);
|
---|
213 | }
|
---|
214 | } else {
|
---|
215 | mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
|
---|
216 | adel = true;
|
---|
217 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
|
---|
218 | double x = (double) i;
|
---|
219 | double y = (double) j;
|
---|
220 | double f = (*mMtx)(i,j);
|
---|
221 | double e = 1.;
|
---|
222 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
223 | mGData->AddData2(x,y,f,e);
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | return mGData;
|
---|
228 | }
|
---|
229 |
|
---|
230 | template <class T>
|
---|
231 | AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
|
---|
232 | {
|
---|
233 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
234 | if(vec) {
|
---|
235 | TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true);
|
---|
236 | return v;
|
---|
237 | } else {
|
---|
238 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true);
|
---|
239 | return m;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | template <class T>
|
---|
244 | AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
|
---|
245 | {
|
---|
246 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
247 | if(vec) {
|
---|
248 | TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true);
|
---|
249 | return v;
|
---|
250 | } else {
|
---|
251 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true);
|
---|
252 | return m;
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | // ---- Specialisation pour complexes -----
|
---|
257 | #if defined(__SGICC__)
|
---|
258 | template <>
|
---|
259 | #endif
|
---|
260 | GeneralFitData* NOMAdapter_TMatrix< complex<r_4> >::GetGeneralFitData(bool& adel
|
---|
261 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
262 | ,int i1,int i2,int j1,int j2)
|
---|
263 | {
|
---|
264 | return(NULL);
|
---|
265 | }
|
---|
266 |
|
---|
267 | #if defined(__SGICC__)
|
---|
268 | template <>
|
---|
269 | #endif
|
---|
270 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
|
---|
271 | {
|
---|
272 | return(NULL);
|
---|
273 | }
|
---|
274 |
|
---|
275 | #if defined(__SGICC__)
|
---|
276 | template <>
|
---|
277 | #endif
|
---|
278 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
|
---|
279 | {
|
---|
280 | return(NULL);
|
---|
281 | }
|
---|
282 |
|
---|
283 | #if defined(__SGICC__)
|
---|
284 | template <>
|
---|
285 | #endif
|
---|
286 | GeneralFitData* NOMAdapter_TMatrix< complex<r_8> >::GetGeneralFitData(bool& adel
|
---|
287 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
288 | ,int i1,int i2,int j1,int j2)
|
---|
289 | {
|
---|
290 | return(NULL);
|
---|
291 | }
|
---|
292 |
|
---|
293 | #if defined(__SGICC__)
|
---|
294 | template <>
|
---|
295 | #endif
|
---|
296 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
|
---|
297 | {
|
---|
298 | return(NULL);
|
---|
299 | }
|
---|
300 |
|
---|
301 | #if defined(__SGICC__)
|
---|
302 | template <>
|
---|
303 | #endif
|
---|
304 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
|
---|
305 | {
|
---|
306 | return(NULL);
|
---|
307 | }
|
---|
308 |
|
---|
309 | // -------------------------------------------------------------
|
---|
310 |
|
---|
311 | /* --Methode-- */
|
---|
312 | template <class T>
|
---|
313 | NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
|
---|
314 | {
|
---|
315 | mMtx = m;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /* --Methode-- */
|
---|
319 | template <class T>
|
---|
320 | NTupInt_TMatrix<T>::~NTupInt_TMatrix()
|
---|
321 | {
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* --Methode-- */
|
---|
325 | template <class T>
|
---|
326 | uint_4 NTupInt_TMatrix<T>::NbLines() const
|
---|
327 | {
|
---|
328 | return( mMtx->NRows()*mMtx->NCols() );
|
---|
329 | }
|
---|
330 |
|
---|
331 | /* --Methode-- */
|
---|
332 | template <class T>
|
---|
333 | uint_4 NTupInt_TMatrix<T>::NbColumns() const
|
---|
334 | {
|
---|
335 | return(8);
|
---|
336 | }
|
---|
337 |
|
---|
338 | /* --Methode-- */
|
---|
339 | template <class T>
|
---|
340 | r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
|
---|
341 | {
|
---|
342 | int i,j;
|
---|
343 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
344 | mRet[0] = n;
|
---|
345 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
346 | }
|
---|
347 | else {
|
---|
348 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
349 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
350 | mRet[3] = (*mMtx)(i,j);
|
---|
351 | mRet[4] = mRet[2]; mRet[5] = 0.;
|
---|
352 | mRet[6] = mRet[2]; mRet[7] = 0.;
|
---|
353 | }
|
---|
354 | return(mRet);
|
---|
355 | }
|
---|
356 |
|
---|
357 | /* --Methode-- */
|
---|
358 | template <class T>
|
---|
359 | string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
|
---|
360 | {
|
---|
361 | string nomx;
|
---|
362 | if (nx) nomx = nx;
|
---|
363 | else nomx = "_xh_";
|
---|
364 | string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
|
---|
365 | vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
|
---|
366 | vardec += "val = " + nomx + "[3]; \n";
|
---|
367 | vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
|
---|
368 | vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
|
---|
369 | return(vardec);
|
---|
370 | }
|
---|
371 |
|
---|
372 | /* --Methode-- */
|
---|
373 | #if defined(__SGICC__)
|
---|
374 | template <>
|
---|
375 | #endif
|
---|
376 | r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(int n) const
|
---|
377 | {
|
---|
378 | int i,j;
|
---|
379 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
380 | mRet[0] = n;
|
---|
381 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
382 | }
|
---|
383 | else {
|
---|
384 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
385 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
386 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
387 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
388 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
389 | }
|
---|
390 | return(mRet);
|
---|
391 | }
|
---|
392 |
|
---|
393 | #if defined(__SGICC__)
|
---|
394 | template <>
|
---|
395 | #endif
|
---|
396 | r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(int n) const
|
---|
397 | {
|
---|
398 | int i,j;
|
---|
399 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
400 | mRet[0] = n;
|
---|
401 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
402 | }
|
---|
403 | else {
|
---|
404 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
405 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
406 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
407 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
408 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
409 | }
|
---|
410 | return(mRet);
|
---|
411 | }
|
---|
412 |
|
---|
413 |
|
---|
414 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
415 | //#pragma define_template NOMAdapter_TMatrix<uint_2>
|
---|
416 | //#pragma define_template NOMAdapter_TMatrix<int_2>
|
---|
417 | #pragma define_template NOMAdapter_TMatrix<int_4>
|
---|
418 | #pragma define_template NOMAdapter_TMatrix<r_4>
|
---|
419 | #pragma define_template NOMAdapter_TMatrix<r_8>
|
---|
420 | #pragma define_template NOMAdapter_TMatrix< complex<r_4> >
|
---|
421 | #pragma define_template NOMAdapter_TMatrix< complex<r_8> >
|
---|
422 | //#pragma define_template NTupInt_TMatrix<uint_2>
|
---|
423 | //#pragma define_template NTupInt_TMatrix<int_2>
|
---|
424 | #pragma define_template NTupInt_TMatrix<int_4>
|
---|
425 | #pragma define_template NTupInt_TMatrix<r_4>
|
---|
426 | #pragma define_template NTupInt_TMatrix<r_8>
|
---|
427 | #pragma define_template NTupInt_TMatrix< complex<r_4> >
|
---|
428 | #pragma define_template NTupInt_TMatrix< complex<r_8> >
|
---|
429 | #endif
|
---|
430 |
|
---|
431 | #if defined(ANSI_TEMPLATES)
|
---|
432 | //template class NOMAdapter_TMatrix<uint_2>;
|
---|
433 | //template class NOMAdapter_TMatrix<int_2>;
|
---|
434 | template class NOMAdapter_TMatrix<int_4>;
|
---|
435 | template class NOMAdapter_TMatrix<r_4>;
|
---|
436 | template class NOMAdapter_TMatrix<r_8>;
|
---|
437 | template class NOMAdapter_TMatrix< complex<r_4> >;
|
---|
438 | template class NOMAdapter_TMatrix< complex<r_8> >;
|
---|
439 | // template class NTupInt_TMatrix<uint_2>;
|
---|
440 | // template class NTupInt_TMatrix<int_2>;
|
---|
441 | template class NTupInt_TMatrix<int_4>;
|
---|
442 | template class NTupInt_TMatrix<r_4>;
|
---|
443 | template class NTupInt_TMatrix<r_8>;
|
---|
444 | template class NTupInt_TMatrix< complex<r_4> >;
|
---|
445 | template class NTupInt_TMatrix< complex<r_8> >;
|
---|
446 | #endif
|
---|