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

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

1/ Basculement de decodage des options de display aux methodes
PIDrawer/PIWdg::DecodeOptionString()
2/ Possibilite de Show/Hide de la partie Zoom/ColorMap/Stat du MainWindow

Reza 30/4/2002

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