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

Last change on this file since 2977 was 2975, checked in by ansari, 19 years ago

Ajout flag int lev ds les adaptateurs NObjMgrAdapter::Print(ostream& os, int lev=0) et NamedObjMgr::Print() + modif commande print - Reza 20 Juin 2006

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