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

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

Compilation avec SGI-CC -LANG:std - Reza 10/03/2003

File size: 11.0 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 -----
89DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
90void NOMAdapter_TMatrix< complex<r_4> >::ReadFits(string const & flnm)
91{
92cout << " NOMAdapter_TMatrix< complex<r_4> >::ReadFits() - Error "
93 << " Not supported (complex data type)" << endl;
94}
95DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
96void NOMAdapter_TMatrix< complex<r_4> >::SaveFits(string const & flnm)
97{
98cout << " NOMAdapter_TMatrix< complex<r_4> >::SaveFits() - Error "
99 << " Not supported (complex data type)" << endl;
100}
101
102DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
103void NOMAdapter_TMatrix< complex<r_8> >::ReadFits(string const & flnm)
104{
105cout << " NOMAdapter_TMatrix< complex<r_8> >::ReadFits() - Error "
106 << " Not supported (complex data type)" << endl;
107}
108DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
109void NOMAdapter_TMatrix< complex<r_8> >::SaveFits(string const & flnm)
110{
111cout << " NOMAdapter_TMatrix< complex<r_8> >::SaveFits() - Error "
112 << " Not supported (complex data type)" << endl;
113}
114
115/* --Methode-- */
116template <class T>
117void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
118{
119if (mMtx == NULL) return;
120TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
121if (v != NULL) {
122 FIO_TArray<T> fio(v);
123 fio.Write(pos, nom);
124 }
125else {
126 FIO_TArray<T> fio(mMtx);
127 fio.Write(pos, nom);
128 }
129}
130
131/* --Methode-- */
132template <class T>
133void NOMAdapter_TMatrix<T>::Print(ostream& os)
134{
135TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
136if (v != NULL) os << (*v);
137else os << (*mMtx);
138}
139
140/* --Methode-- */
141template <class T>
142PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
143{
144TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
145if (v == NULL) return(NULL);
146else {
147 dopt = "thinline " + dopt;
148 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
149 }
150}
151
152/* --Methode-- */
153template <class T>
154P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
155{
156return ( new POTMatrixAdapter<T>(mMtx, false) );
157}
158
159/* --Methode-- */
160template <class T>
161NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
162{
163adel = true;
164return( new NTupInt_TMatrix<T>(mMtx) );
165}
166
167
168/* --Methode-- */
169template <class T>
170GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
171 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
172 ,int i1,int i2,int j1,int j2)
173{
174adel = false;
175if(!mMtx) return(NULL);
176
177int nx,ny;
178TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
179
180if(vec) { // C'est un TVector
181 nx = vec->NElts();
182 ny = 1;
183} else {
184 nx = mMtx->NRows();
185 ny = mMtx->NCol();
186 if(nx<=0 || ny<=0) return(NULL);
187}
188
189i1 = (i1<0||i1>=nx)? 0: i1;
190i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
191j1 = (j1<0||j1>=ny)? 0: j1;
192j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
193
194GeneralFitData* mGData = NULL;
195
196if(vec) { // C'est un TVector
197 mGData = new GeneralFitData(1,(i2-i1+1),0);
198 adel = true;
199 for(int i=i1;i<=i2;i++) {
200 double x = (double) i;
201 double f = (*vec)(i);
202 double e = 1.;
203 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
204 mGData->AddData1(x,f,e);
205 }
206} else {
207 mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
208 adel = true;
209 for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
210 double x = (double) i;
211 double y = (double) j;
212 double f = (*mMtx)(i,j);
213 double e = 1.;
214 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
215 mGData->AddData2(x,y,f,e);
216 }
217}
218
219return mGData;
220}
221
222template <class T>
223AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
224{
225TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
226if(vec) {
227 TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true);
228 return v;
229} else {
230 TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true);
231 return m;
232}
233}
234
235template <class T>
236AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
237{
238TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
239if(vec) {
240 TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true);
241 return v;
242} else {
243 TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true);
244 return m;
245}
246}
247
248// ---- Specialisation pour complexes -----
249DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
250GeneralFitData* NOMAdapter_TMatrix< complex<r_4> >::GetGeneralFitData(bool& adel
251 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
252 ,int i1,int i2,int j1,int j2)
253{
254 return(NULL);
255}
256
257DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
258AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
259{
260 return(NULL);
261}
262
263DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
264AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
265{
266 return(NULL);
267}
268
269DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
270GeneralFitData* NOMAdapter_TMatrix< complex<r_8> >::GetGeneralFitData(bool& adel
271 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
272 ,int i1,int i2,int j1,int j2)
273{
274 return(NULL);
275}
276
277DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
278AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
279{
280 return(NULL);
281}
282
283DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
284AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
285{
286 return(NULL);
287}
288
289// -------------------------------------------------------------
290
291/* --Methode-- */
292template <class T>
293NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
294{
295mMtx = m;
296}
297
298/* --Methode-- */
299template <class T>
300NTupInt_TMatrix<T>::~NTupInt_TMatrix()
301{
302}
303
304/* --Methode-- */
305template <class T>
306uint_4 NTupInt_TMatrix<T>::NbLines() const
307{
308return( mMtx->NRows()*mMtx->NCols() );
309}
310
311/* --Methode-- */
312template <class T>
313uint_4 NTupInt_TMatrix<T>::NbColumns() const
314{
315return(8);
316}
317
318/* --Methode-- */
319template <class T>
320r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
321{
322int i,j;
323if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
324 mRet[0] = n;
325 for(i=1; i<8; i++) mRet[i] = 0.;
326}
327else {
328 i = n/mMtx->NCols(); j = n%mMtx->NCols();
329 mRet[0] = n; mRet[1] = i; mRet[2] = j;
330 mRet[3] = (*mMtx)(i,j);
331 mRet[4] = mRet[2]; mRet[5] = 0.;
332 mRet[6] = mRet[2]; mRet[7] = 0.;
333 }
334return(mRet);
335}
336
337/* --Methode-- */
338template <class T>
339string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
340{
341string nomx;
342if (nx) nomx = nx;
343else nomx = "_xh_";
344string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
345vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
346vardec += "val = " + nomx + "[3]; \n";
347vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
348vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
349return(vardec);
350}
351
352/* --Methode-- */
353DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
354r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(int n) const
355{
356int i,j;
357if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
358 mRet[0] = n;
359 for(i=1; i<8; i++) mRet[i] = 0.;
360}
361else {
362 i = n/mMtx->NCols(); j = n%mMtx->NCols();
363 mRet[0] = n; mRet[1] = i; mRet[2] = j;
364 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
365 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
366 mRet[7] = atan2(mRet[5], mRet[4]);
367}
368return(mRet);
369}
370
371DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
372r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(int n) const
373{
374int i,j;
375if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
376 mRet[0] = n;
377 for(i=1; i<8; i++) mRet[i] = 0.;
378}
379else {
380 i = n/mMtx->NCols(); j = n%mMtx->NCols();
381 mRet[0] = n; mRet[1] = i; mRet[2] = j;
382 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
383 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
384 mRet[7] = atan2(mRet[5], mRet[4]);
385}
386return(mRet);
387}
388
389
390#ifdef __CXX_PRAGMA_TEMPLATES__
391//#pragma define_template NOMAdapter_TMatrix<uint_2>
392//#pragma define_template NOMAdapter_TMatrix<int_2>
393#pragma define_template NOMAdapter_TMatrix<int_4>
394#pragma define_template NOMAdapter_TMatrix<r_4>
395#pragma define_template NOMAdapter_TMatrix<r_8>
396#pragma define_template NOMAdapter_TMatrix< complex<r_4> >
397#pragma define_template NOMAdapter_TMatrix< complex<r_8> >
398//#pragma define_template NTupInt_TMatrix<uint_2>
399//#pragma define_template NTupInt_TMatrix<int_2>
400#pragma define_template NTupInt_TMatrix<int_4>
401#pragma define_template NTupInt_TMatrix<r_4>
402#pragma define_template NTupInt_TMatrix<r_8>
403#pragma define_template NTupInt_TMatrix< complex<r_4> >
404#pragma define_template NTupInt_TMatrix< complex<r_8> >
405#endif
406
407#if defined(ANSI_TEMPLATES)
408//template class NOMAdapter_TMatrix<uint_2>;
409//template class NOMAdapter_TMatrix<int_2>;
410template class NOMAdapter_TMatrix<int_4>;
411template class NOMAdapter_TMatrix<r_4>;
412template class NOMAdapter_TMatrix<r_8>;
413template class NOMAdapter_TMatrix< complex<r_4> >;
414template class NOMAdapter_TMatrix< complex<r_8> >;
415// template class NTupInt_TMatrix<uint_2>;
416// template class NTupInt_TMatrix<int_2>;
417template class NTupInt_TMatrix<int_4>;
418template class NTupInt_TMatrix<r_4>;
419template class NTupInt_TMatrix<r_8>;
420template class NTupInt_TMatrix< complex<r_4> >;
421template class NTupInt_TMatrix< complex<r_8> >;
422#endif
Note: See TracBrowser for help on using the repository browser.