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