source: Sophya/trunk/SophyaPI/PIext/nomtmatvecadapter.cc@ 2335

Last change on this file since 2335 was 2335, checked in by ansari, 23 years ago

Compil sur SGI-CC avec LANG:std suite au remplacement xxstream.h par xxstream (gcc 3.1) / ajout template <> pour specialisation template - Reza 10/03/2003

File size: 10.6 KB
Line 
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-- */
26template <class T>
27NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
28 : NObjMgrAdapter(o)
29{
30mMtx = o;
31}
32
33/* --Methode-- */
34template <class T>
35NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
36{
37}
38
39/* --Methode-- */
40template <class T>
41NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
42{
43TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
44if (m) return ( new NOMAdapter_TMatrix<T>(m) );
45return ( new NObjMgrAdapter(o) );
46}
47
48/* --Methode-- */
49template <class T>
50string NOMAdapter_TMatrix<T>::GetDataObjType()
51{
52string type = "TMatrix< ";
53
54TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
55if (v != NULL) type = "TVector< ";
56
57// type += DecodeTypeIdName(typeid(T).name());
58type += DataTypeInfo<T>::getTypeName();
59type += " > ";
60return(type);
61}
62
63/* --Methode-- */
64template <class T>
65AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj(bool share)
66{
67if (mMtx == NULL) return(NULL);
68TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
69if (v != NULL) return( new TVector<T>(*v, share) );
70else return ( new TMatrix<T>(*mMtx, share) );
71}
72
73/* --Methode-- */
74template <class T>
75void NOMAdapter_TMatrix<T>::ReadFits(string const & flnm)
76{
77 FitsInFile fis(flnm);
78 fis >> (*mMtx);
79}
80
81/* --Methode-- */
82template <class T>
83void NOMAdapter_TMatrix<T>::SaveFits(string const & flnm)
84{
85 FitsOutFile fos(flnm);
86 fos << (*mMtx);
87}
88// ---- Specialisation pour complexes -----
89#if defined(__SGICC__)
90template <>
91#endif
92void NOMAdapter_TMatrix< complex<r_4> >::ReadFits(string const & flnm)
93{
94cout << " NOMAdapter_TMatrix< complex<r_4> >::ReadFits() - Error "
95 << " Not supported (complex data type)" << endl;
96}
97#if defined(__SGICC__)
98template <>
99#endif
100void NOMAdapter_TMatrix< complex<r_4> >::SaveFits(string const & flnm)
101{
102cout << " NOMAdapter_TMatrix< complex<r_4> >::SaveFits() - Error "
103 << " Not supported (complex data type)" << endl;
104}
105
106#if defined(__SGICC__)
107template <>
108#endif
109void NOMAdapter_TMatrix< complex<r_8> >::ReadFits(string const & flnm)
110{
111cout << " NOMAdapter_TMatrix< complex<r_8> >::ReadFits() - Error "
112 << " Not supported (complex data type)" << endl;
113}
114#if defined(__SGICC__)
115template <>
116#endif
117void NOMAdapter_TMatrix< complex<r_8> >::SaveFits(string const & flnm)
118{
119cout << " NOMAdapter_TMatrix< complex<r_8> >::SaveFits() - Error "
120 << " Not supported (complex data type)" << endl;
121}
122
123/* --Methode-- */
124template <class T>
125void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
126{
127if (mMtx == NULL) return;
128TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
129if (v != NULL) {
130 FIO_TArray<T> fio(v);
131 fio.Write(pos, nom);
132 }
133else {
134 FIO_TArray<T> fio(mMtx);
135 fio.Write(pos, nom);
136 }
137}
138
139/* --Methode-- */
140template <class T>
141void NOMAdapter_TMatrix<T>::Print(ostream& os)
142{
143TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
144if (v != NULL) os << (*v);
145else os << (*mMtx);
146}
147
148/* --Methode-- */
149template <class T>
150PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
151{
152TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
153if (v == NULL) return(NULL);
154else {
155 dopt = "thinline " + dopt;
156 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
157 }
158}
159
160/* --Methode-- */
161template <class T>
162P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
163{
164return ( new POTMatrixAdapter<T>(mMtx, false) );
165}
166
167/* --Methode-- */
168template <class T>
169NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
170{
171adel = true;
172return( new NTupInt_TMatrix<T>(mMtx) );
173}
174
175
176/* --Methode-- */
177template <class T>
178GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
179 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
180 ,int i1,int i2,int j1,int j2)
181{
182adel = false;
183if(!mMtx) return(NULL);
184
185int nx,ny;
186TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
187
188if(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
197i1 = (i1<0||i1>=nx)? 0: i1;
198i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
199j1 = (j1<0||j1>=ny)? 0: j1;
200j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
201
202GeneralFitData* mGData = NULL;
203
204if(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
227return mGData;
228}
229
230template <class T>
231AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
232{
233TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
234if(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
243template <class T>
244AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
245{
246TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
247if(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__)
258template <>
259#endif
260GeneralFitData* 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__)
268template <>
269#endif
270AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
271{
272 return(NULL);
273}
274
275#if defined(__SGICC__)
276template <>
277#endif
278AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
279{
280 return(NULL);
281}
282
283#if defined(__SGICC__)
284template <>
285#endif
286GeneralFitData* 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__)
294template <>
295#endif
296AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
297{
298 return(NULL);
299}
300
301#if defined(__SGICC__)
302template <>
303#endif
304AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
305{
306 return(NULL);
307}
308
309// -------------------------------------------------------------
310
311/* --Methode-- */
312template <class T>
313NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
314{
315mMtx = m;
316}
317
318/* --Methode-- */
319template <class T>
320NTupInt_TMatrix<T>::~NTupInt_TMatrix()
321{
322}
323
324/* --Methode-- */
325template <class T>
326uint_4 NTupInt_TMatrix<T>::NbLines() const
327{
328return( mMtx->NRows()*mMtx->NCols() );
329}
330
331/* --Methode-- */
332template <class T>
333uint_4 NTupInt_TMatrix<T>::NbColumns() const
334{
335return(8);
336}
337
338/* --Methode-- */
339template <class T>
340r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
341{
342int i,j;
343if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
344 mRet[0] = n;
345 for(i=1; i<8; i++) mRet[i] = 0.;
346}
347else {
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 }
354return(mRet);
355}
356
357/* --Methode-- */
358template <class T>
359string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
360{
361string nomx;
362if (nx) nomx = nx;
363else nomx = "_xh_";
364string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
365vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
366vardec += "val = " + nomx + "[3]; \n";
367vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
368vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
369return(vardec);
370}
371
372/* --Methode-- */
373#if defined(__SGICC__)
374template <>
375#endif
376r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(int n) const
377{
378int i,j;
379if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
380 mRet[0] = n;
381 for(i=1; i<8; i++) mRet[i] = 0.;
382}
383else {
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}
390return(mRet);
391}
392
393#if defined(__SGICC__)
394template <>
395#endif
396r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(int n) const
397{
398int i,j;
399if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
400 mRet[0] = n;
401 for(i=1; i<8; i++) mRet[i] = 0.;
402}
403else {
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}
410return(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>;
434template class NOMAdapter_TMatrix<int_4>;
435template class NOMAdapter_TMatrix<r_4>;
436template class NOMAdapter_TMatrix<r_8>;
437template class NOMAdapter_TMatrix< complex<r_4> >;
438template class NOMAdapter_TMatrix< complex<r_8> >;
439// template class NTupInt_TMatrix<uint_2>;
440// template class NTupInt_TMatrix<int_2>;
441template class NTupInt_TMatrix<int_4>;
442template class NTupInt_TMatrix<r_4>;
443template class NTupInt_TMatrix<r_8>;
444template class NTupInt_TMatrix< complex<r_4> >;
445template class NTupInt_TMatrix< complex<r_8> >;
446#endif
Note: See TracBrowser for help on using the repository browser.