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

Last change on this file since 2615 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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