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-- */
|
---|
23 | template <class T>
|
---|
24 | NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
|
---|
25 | : NObjMgrAdapter(o)
|
---|
26 | {
|
---|
27 | mMtx = o;
|
---|
28 | }
|
---|
29 |
|
---|
30 | /* --Methode-- */
|
---|
31 | template <class T>
|
---|
32 | NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 | /* --Methode-- */
|
---|
37 | template <class T>
|
---|
38 | NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
|
---|
39 | {
|
---|
40 | TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
|
---|
41 | if (m) return ( new NOMAdapter_TMatrix<T>(m) );
|
---|
42 | return ( new NObjMgrAdapter(o) );
|
---|
43 | }
|
---|
44 |
|
---|
45 | /* --Methode-- */
|
---|
46 | template <class T>
|
---|
47 | string NOMAdapter_TMatrix<T>::GetDataObjType()
|
---|
48 | {
|
---|
49 | string type = "TMatrix< ";
|
---|
50 |
|
---|
51 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
52 | if (v != NULL) type = "TVector< ";
|
---|
53 |
|
---|
54 | type += typeid(T).name();
|
---|
55 | type += " > ";
|
---|
56 | return(type);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* --Methode-- */
|
---|
60 | template <class T>
|
---|
61 | AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj()
|
---|
62 | {
|
---|
63 | if (mMtx == NULL) return(NULL);
|
---|
64 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
65 | if (v != NULL) return( new TVector<T>(*v, false) );
|
---|
66 | else return ( new TMatrix<T>(*mMtx, false) );
|
---|
67 | }
|
---|
68 |
|
---|
69 | /* --Methode-- */
|
---|
70 | template <class T>
|
---|
71 | void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
72 | {
|
---|
73 | if (mMtx == NULL) return;
|
---|
74 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
75 | if (v != NULL) {
|
---|
76 | FIO_TArray<T> fio(v);
|
---|
77 | fio.Write(pos, nom);
|
---|
78 | }
|
---|
79 | else {
|
---|
80 | FIO_TArray<T> fio(mMtx);
|
---|
81 | fio.Write(pos, nom);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* --Methode-- */
|
---|
86 | template <class T>
|
---|
87 | void NOMAdapter_TMatrix<T>::Print(ostream& os)
|
---|
88 | {
|
---|
89 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
90 | if (v != NULL) os << (*v);
|
---|
91 | else os << (*mMtx);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* --Methode-- */
|
---|
95 | template <class T>
|
---|
96 | PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
|
---|
97 | {
|
---|
98 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
99 | if (v == NULL) return(NULL);
|
---|
100 | else {
|
---|
101 | dopt = "thinline," + dopt;
|
---|
102 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* --Methode-- */
|
---|
107 | template <class T>
|
---|
108 | P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
|
---|
109 | {
|
---|
110 | return ( new POTMatrixAdapter<T>(mMtx, false) );
|
---|
111 | }
|
---|
112 |
|
---|
113 | /* --Methode-- */
|
---|
114 | template <class T>
|
---|
115 | NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
|
---|
116 | {
|
---|
117 | adel = true;
|
---|
118 | return( new NTupInt_TMatrix<T>(mMtx) );
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 | // -------------------------------------------------------------
|
---|
124 |
|
---|
125 | /* --Methode-- */
|
---|
126 | template <class T>
|
---|
127 | NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
|
---|
128 | {
|
---|
129 | mMtx = m;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* --Methode-- */
|
---|
133 | template <class T>
|
---|
134 | NTupInt_TMatrix<T>::~NTupInt_TMatrix()
|
---|
135 | {
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* --Methode-- */
|
---|
139 | template <class T>
|
---|
140 | uint_4 NTupInt_TMatrix<T>::NbLines() const
|
---|
141 | {
|
---|
142 | return( mMtx->NRows()*mMtx->NCols() );
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* --Methode-- */
|
---|
146 | template <class T>
|
---|
147 | uint_4 NTupInt_TMatrix<T>::NbColumns() const
|
---|
148 | {
|
---|
149 | return(8);
|
---|
150 | }
|
---|
151 |
|
---|
152 | /* --Methode-- */
|
---|
153 | template <class T>
|
---|
154 | r_8* NTupInt_TMatrix<T>::GetLineD(int n) const
|
---|
155 | {
|
---|
156 | int i,j;
|
---|
157 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
158 | mRet[0] = n;
|
---|
159 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
160 | }
|
---|
161 | else {
|
---|
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 | }
|
---|
168 | return(mRet);
|
---|
169 | }
|
---|
170 |
|
---|
171 | /* --Methode-- */
|
---|
172 | template <class T>
|
---|
173 | string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
|
---|
174 | {
|
---|
175 | string nomx;
|
---|
176 | if (nx) nomx = nx;
|
---|
177 | else nomx = "_xh_";
|
---|
178 | string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
|
---|
179 | vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
|
---|
180 | vardec += "val = " + nomx + "[3]; \n";
|
---|
181 | vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
|
---|
182 | vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
|
---|
183 | return(vardec);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /* --Methode-- */
|
---|
187 | r_8* NTupInt_TMatrix< complex<float> >::GetLineD(int n) const
|
---|
188 | {
|
---|
189 | int i,j;
|
---|
190 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
191 | mRet[0] = n;
|
---|
192 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
193 | }
|
---|
194 | else {
|
---|
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 | }
|
---|
201 | return(mRet);
|
---|
202 | }
|
---|
203 |
|
---|
204 | r_8* NTupInt_TMatrix< complex<double> >::GetLineD(int n) const
|
---|
205 | {
|
---|
206 | int i,j;
|
---|
207 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
208 | mRet[0] = n;
|
---|
209 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
210 | }
|
---|
211 | else {
|
---|
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 | }
|
---|
218 | return(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>;
|
---|
242 | template class NOMAdapter_TMatrix<int_4>;
|
---|
243 | template class NOMAdapter_TMatrix<r_4>;
|
---|
244 | template class NOMAdapter_TMatrix<r_8>;
|
---|
245 | template class NOMAdapter_TMatrix< complex<r_4> >;
|
---|
246 | template class NOMAdapter_TMatrix< complex<r_8> >;
|
---|
247 | // template class NTupInt_TMatrix<uint_2>;
|
---|
248 | // template class NTupInt_TMatrix<int_2>;
|
---|
249 | template class NTupInt_TMatrix<int_4>;
|
---|
250 | template class NTupInt_TMatrix<r_4>;
|
---|
251 | template class NTupInt_TMatrix<r_8>;
|
---|
252 | template class NTupInt_TMatrix< complex<r_4> >;
|
---|
253 | template class NTupInt_TMatrix< complex<r_8> >;
|
---|
254 | #endif
|
---|