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