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

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

Correction Bug ds Clone TMatrix - Reza+CMV 24/7/2000

File size: 5.9 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>
47AnyDataObj* NOMAdapter_TMatrix<T>::GetCopyObj()
48{
49if (mMtx == NULL) return(NULL);
50TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
51if (v != NULL) return( new TVector<T>(*v, false) );
52else return ( new TMatrix<T>(*mMtx, false) );
53}
54
55/* --Methode-- */
56template <class T>
57void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
58{
59if (mMtx == NULL) return;
60TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
61if (v != NULL) {
62 FIO_TArray<T> fio(v);
63 fio.Write(pos, nom);
64 }
65else {
66 FIO_TArray<T> fio(mMtx);
67 fio.Write(pos, nom);
68 }
69}
70
71/* --Methode-- */
72template <class T>
73void NOMAdapter_TMatrix<T>::Print(ostream& os)
74{
75TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
76if (v != NULL) os << (*v);
77else os << (*mMtx);
78}
79
80/* --Methode-- */
81template <class T>
82PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
83{
84TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
85if (v == NULL) return(NULL);
86else {
87 dopt = "thinline," + dopt;
88 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
89 }
90}
91
92/* --Methode-- */
93template <class T>
94P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
95{
96return ( new POTMatrixAdapter<T>(mMtx, false) );
97}
98
99/* --Methode-- */
100template <class T>
101NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
102{
103adel = true;
104return( new NTupInt_TMatrix<T>(mMtx) );
105}
106
107
108
109// -------------------------------------------------------------
110
111/* --Methode-- */
112template <class T>
113NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
114{
115mMtx = m;
116}
117
118/* --Methode-- */
119template <class T>
120NTupInt_TMatrix<T>::~NTupInt_TMatrix()
121{
122}
123
124/* --Methode-- */
125template <class T>
126uint_4 NTupInt_TMatrix<T>::NbLines() const
127{
128return( mMtx->NRows()*mMtx->NCols() );
129}
130
131/* --Methode-- */
132template <class T>
133uint_4 NTupInt_TMatrix<T>::NbColumns() const
134{
135return(8);
136}
137
138/* --Methode-- */
139template <class T>
140r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
141{
142int i,j;
143if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
144 mRet[0] = n;
145 for(i=1; i<8; i++) mRet[i] = 0.;
146}
147else {
148 i = n/mMtx->NCols(); j = n%mMtx->NCols();
149 mRet[0] = n; mRet[1] = i; mRet[2] = j;
150 mRet[3] = (*mMtx)(i,j);
151 mRet[4] = mRet[2]; mRet[5] = 0.;
152 mRet[6] = mRet[2]; mRet[7] = 0.;
153 }
154return(mRet);
155}
156
157/* --Methode-- */
158template <class T>
159string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
160{
161string nomx;
162if (nx) nomx = nx;
163else nomx = "_xh_";
164string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
165vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
166vardec += "val = " + nomx + "[3]; \n";
167vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
168vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
169return(vardec);
170}
171
172/* --Methode-- */
173r_8* NTupInt_TMatrix< complex<float> >::GetLineD(int n) const
174{
175int i,j;
176if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
177 mRet[0] = n;
178 for(i=1; i<8; i++) mRet[i] = 0.;
179}
180else {
181 i = n/mMtx->NCols(); j = n%mMtx->NCols();
182 mRet[0] = n; mRet[1] = i; mRet[2] = j;
183 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
184 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
185 mRet[7] = atan2(mRet[5], mRet[4]);
186}
187return(mRet);
188}
189
190r_8* NTupInt_TMatrix< complex<double> >::GetLineD(int n) const
191{
192int i,j;
193if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
194 mRet[0] = n;
195 for(i=1; i<8; i++) mRet[i] = 0.;
196}
197else {
198 i = n/mMtx->NCols(); j = n%mMtx->NCols();
199 mRet[0] = n; mRet[1] = i; mRet[2] = j;
200 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
201 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
202 mRet[7] = atan2(mRet[5], mRet[4]);
203}
204return(mRet);
205}
206
207
208#ifdef __CXX_PRAGMA_TEMPLATES__
209//#pragma define_template NOMAdapter_TMatrix<uint_2>
210//#pragma define_template NOMAdapter_TMatrix<int_2>
211#pragma define_template NOMAdapter_TMatrix<int_4>
212#pragma define_template NOMAdapter_TMatrix<r_4>
213#pragma define_template NOMAdapter_TMatrix<r_8>
214#pragma define_template NOMAdapter_TMatrix< complex<r_4> >
215#pragma define_template NOMAdapter_TMatrix< complex<r_8> >
216//#pragma define_template NTupInt_TMatrix<uint_2>
217//#pragma define_template NTupInt_TMatrix<int_2>
218#pragma define_template NTupInt_TMatrix<int_4>
219#pragma define_template NTupInt_TMatrix<r_4>
220#pragma define_template NTupInt_TMatrix<r_8>
221#pragma define_template NTupInt_TMatrix< complex<r_4> >
222#pragma define_template NTupInt_TMatrix< complex<r_8> >
223#endif
224
225#if defined(ANSI_TEMPLATES)
226//template class NOMAdapter_TMatrix<uint_2>;
227//template class NOMAdapter_TMatrix<int_2>;
228template class NOMAdapter_TMatrix<int_4>;
229template class NOMAdapter_TMatrix<r_4>;
230template class NOMAdapter_TMatrix<r_8>;
231template class NOMAdapter_TMatrix< complex<r_4> >;
232template class NOMAdapter_TMatrix< complex<r_8> >;
233// template class NTupInt_TMatrix<uint_2>;
234// template class NTupInt_TMatrix<int_2>;
235template class NTupInt_TMatrix<int_4>;
236template class NTupInt_TMatrix<r_4>;
237template class NTupInt_TMatrix<r_8>;
238template class NTupInt_TMatrix< complex<r_4> >;
239template class NTupInt_TMatrix< complex<r_8> >;
240#endif
Note: See TracBrowser for help on using the repository browser.