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

Last change on this file since 1165 was 1165, checked in by ercodmgr, 25 years ago

Extension de l'interface NObjMgrAdapter et ajout de DVList pour les variables globales ds NamedObjMgr - Reza 30/8/2000

File size: 6.2 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <typeinfo>
4#include <iostream.h>
5#include <string>
6#include <complex>
7
8#include "tvector.h"
9#include "nomtmatvecadapter.h"
10#include "piscdrawwdg.h"
11#include "pitvmaad.h"
12
13#include "fioarr.h"
14
15
16
17//----------------------------------------------------------------
18// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet TMatrix<T>
19//----------------------------------------------------------------
20
21
22/* --Methode-- */
23template <class T>
24NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
25 : NObjMgrAdapter(o)
26{
27mMtx = o;
28}
29
30/* --Methode-- */
31template <class T>
32NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
33{
34}
35
36/* --Methode-- */
37template <class T>
38NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
39{
40TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
41if (m) return ( new NOMAdapter_TMatrix<T>(m) );
42return ( new NObjMgrAdapter(o) );
43}
44
45/* --Methode-- */
46template <class T>
47string NOMAdapter_TMatrix<T>::GetDataObjType()
48{
49string type = "TMatrix< ";
50
51TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
52if (v != NULL) type = "TVector< ";
53
54type += typeid(T).name();
55type += " > ";
56return(type);
57}
58
59/* --Methode-- */
60template <class T>
61AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj()
62{
63if (mMtx == NULL) return(NULL);
64TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
65if (v != NULL) return( new TVector<T>(*v, false) );
66else return ( new TMatrix<T>(*mMtx, false) );
67}
68
69/* --Methode-- */
70template <class T>
71void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
72{
73if (mMtx == NULL) return;
74TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
75if (v != NULL) {
76 FIO_TArray<T> fio(v);
77 fio.Write(pos, nom);
78 }
79else {
80 FIO_TArray<T> fio(mMtx);
81 fio.Write(pos, nom);
82 }
83}
84
85/* --Methode-- */
86template <class T>
87void NOMAdapter_TMatrix<T>::Print(ostream& os)
88{
89TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
90if (v != NULL) os << (*v);
91else os << (*mMtx);
92}
93
94/* --Methode-- */
95template <class T>
96PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
97{
98TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
99if (v == NULL) return(NULL);
100else {
101 dopt = "thinline," + dopt;
102 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
103 }
104}
105
106/* --Methode-- */
107template <class T>
108P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
109{
110return ( new POTMatrixAdapter<T>(mMtx, false) );
111}
112
113/* --Methode-- */
114template <class T>
115NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
116{
117adel = true;
118return( new NTupInt_TMatrix<T>(mMtx) );
119}
120
121
122
123// -------------------------------------------------------------
124
125/* --Methode-- */
126template <class T>
127NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
128{
129mMtx = m;
130}
131
132/* --Methode-- */
133template <class T>
134NTupInt_TMatrix<T>::~NTupInt_TMatrix()
135{
136}
137
138/* --Methode-- */
139template <class T>
140uint_4 NTupInt_TMatrix<T>::NbLines() const
141{
142return( mMtx->NRows()*mMtx->NCols() );
143}
144
145/* --Methode-- */
146template <class T>
147uint_4 NTupInt_TMatrix<T>::NbColumns() const
148{
149return(8);
150}
151
152/* --Methode-- */
153template <class T>
154r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
155{
156int i,j;
157if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
158 mRet[0] = n;
159 for(i=1; i<8; i++) mRet[i] = 0.;
160}
161else {
162 i = n/mMtx->NCols(); j = n%mMtx->NCols();
163 mRet[0] = n; mRet[1] = i; mRet[2] = j;
164 mRet[3] = (*mMtx)(i,j);
165 mRet[4] = mRet[2]; mRet[5] = 0.;
166 mRet[6] = mRet[2]; mRet[7] = 0.;
167 }
168return(mRet);
169}
170
171/* --Methode-- */
172template <class T>
173string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
174{
175string nomx;
176if (nx) nomx = nx;
177else nomx = "_xh_";
178string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
179vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
180vardec += "val = " + nomx + "[3]; \n";
181vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
182vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
183return(vardec);
184}
185
186/* --Methode-- */
187r_8* NTupInt_TMatrix< complex<float> >::GetLineD(int n) const
188{
189int i,j;
190if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
191 mRet[0] = n;
192 for(i=1; i<8; i++) mRet[i] = 0.;
193}
194else {
195 i = n/mMtx->NCols(); j = n%mMtx->NCols();
196 mRet[0] = n; mRet[1] = i; mRet[2] = j;
197 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
198 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
199 mRet[7] = atan2(mRet[5], mRet[4]);
200}
201return(mRet);
202}
203
204r_8* NTupInt_TMatrix< complex<double> >::GetLineD(int n) const
205{
206int i,j;
207if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
208 mRet[0] = n;
209 for(i=1; i<8; i++) mRet[i] = 0.;
210}
211else {
212 i = n/mMtx->NCols(); j = n%mMtx->NCols();
213 mRet[0] = n; mRet[1] = i; mRet[2] = j;
214 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
215 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
216 mRet[7] = atan2(mRet[5], mRet[4]);
217}
218return(mRet);
219}
220
221
222#ifdef __CXX_PRAGMA_TEMPLATES__
223//#pragma define_template NOMAdapter_TMatrix<uint_2>
224//#pragma define_template NOMAdapter_TMatrix<int_2>
225#pragma define_template NOMAdapter_TMatrix<int_4>
226#pragma define_template NOMAdapter_TMatrix<r_4>
227#pragma define_template NOMAdapter_TMatrix<r_8>
228#pragma define_template NOMAdapter_TMatrix< complex<r_4> >
229#pragma define_template NOMAdapter_TMatrix< complex<r_8> >
230//#pragma define_template NTupInt_TMatrix<uint_2>
231//#pragma define_template NTupInt_TMatrix<int_2>
232#pragma define_template NTupInt_TMatrix<int_4>
233#pragma define_template NTupInt_TMatrix<r_4>
234#pragma define_template NTupInt_TMatrix<r_8>
235#pragma define_template NTupInt_TMatrix< complex<r_4> >
236#pragma define_template NTupInt_TMatrix< complex<r_8> >
237#endif
238
239#if defined(ANSI_TEMPLATES)
240//template class NOMAdapter_TMatrix<uint_2>;
241//template class NOMAdapter_TMatrix<int_2>;
242template class NOMAdapter_TMatrix<int_4>;
243template class NOMAdapter_TMatrix<r_4>;
244template class NOMAdapter_TMatrix<r_8>;
245template class NOMAdapter_TMatrix< complex<r_4> >;
246template class NOMAdapter_TMatrix< complex<r_8> >;
247// template class NTupInt_TMatrix<uint_2>;
248// template class NTupInt_TMatrix<int_2>;
249template class NTupInt_TMatrix<int_4>;
250template class NTupInt_TMatrix<r_4>;
251template class NTupInt_TMatrix<r_8>;
252template class NTupInt_TMatrix< complex<r_4> >;
253template class NTupInt_TMatrix< complex<r_8> >;
254#endif
Note: See TracBrowser for help on using the repository browser.