[2615] | 1 | #include "sopnamsp.h"
|
---|
[585] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <typeinfo>
|
---|
[2322] | 5 | #include <iostream>
|
---|
[585] | 6 | #include <string>
|
---|
| 7 | #include <complex>
|
---|
| 8 |
|
---|
[1224] | 9 | #include "datatype.h"
|
---|
| 10 |
|
---|
[585] | 11 | #include "tvector.h"
|
---|
[1207] | 12 | #include "objfitter.h"
|
---|
[585] | 13 | #include "nomtmatvecadapter.h"
|
---|
[1905] | 14 | #include "piyfxdrw.h"
|
---|
[585] | 15 | #include "pitvmaad.h"
|
---|
| 16 |
|
---|
[810] | 17 | #include "fioarr.h"
|
---|
[1321] | 18 | #include "fitstarray.h"
|
---|
[585] | 19 |
|
---|
| 20 |
|
---|
| 21 | //----------------------------------------------------------------
|
---|
| 22 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet TMatrix<T>
|
---|
| 23 | //----------------------------------------------------------------
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | /* --Methode-- */
|
---|
| 27 | template <class T>
|
---|
| 28 | NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
|
---|
| 29 | : NObjMgrAdapter(o)
|
---|
| 30 | {
|
---|
| 31 | mMtx = o;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /* --Methode-- */
|
---|
| 35 | template <class T>
|
---|
| 36 | NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
|
---|
| 37 | {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /* --Methode-- */
|
---|
| 41 | template <class T>
|
---|
| 42 | NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
|
---|
| 43 | {
|
---|
| 44 | TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
|
---|
| 45 | if (m) return ( new NOMAdapter_TMatrix<T>(m) );
|
---|
| 46 | return ( new NObjMgrAdapter(o) );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /* --Methode-- */
|
---|
| 50 | template <class T>
|
---|
[1165] | 51 | string NOMAdapter_TMatrix<T>::GetDataObjType()
|
---|
[585] | 52 | {
|
---|
[1165] | 53 | string type = "TMatrix< ";
|
---|
| 54 |
|
---|
| 55 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 56 | if (v != NULL) type = "TVector< ";
|
---|
| 57 |
|
---|
[1224] | 58 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
[1237] | 59 | type += DataTypeInfo<T>::getTypeName();
|
---|
[1165] | 60 | type += " > ";
|
---|
| 61 | return(type);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /* --Methode-- */
|
---|
| 65 | template <class T>
|
---|
[1315] | 66 | AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj(bool share)
|
---|
[1165] | 67 | {
|
---|
[585] | 68 | if (mMtx == NULL) return(NULL);
|
---|
| 69 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
[1315] | 70 | if (v != NULL) return( new TVector<T>(*v, share) );
|
---|
| 71 | else return ( new TMatrix<T>(*mMtx, share) );
|
---|
[585] | 72 | }
|
---|
| 73 |
|
---|
[1321] | 74 |
|
---|
| 75 | /* --Methode-- */
|
---|
| 76 | template <class T>
|
---|
[585] | 77 | void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
| 78 | {
|
---|
| 79 | if (mMtx == NULL) return;
|
---|
| 80 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 81 | if (v != NULL) {
|
---|
[810] | 82 | FIO_TArray<T> fio(v);
|
---|
[585] | 83 | fio.Write(pos, nom);
|
---|
| 84 | }
|
---|
| 85 | else {
|
---|
[810] | 86 | FIO_TArray<T> fio(mMtx);
|
---|
[585] | 87 | fio.Write(pos, nom);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /* --Methode-- */
|
---|
| 92 | template <class T>
|
---|
| 93 | void NOMAdapter_TMatrix<T>::Print(ostream& os)
|
---|
| 94 | {
|
---|
| 95 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 96 | if (v != NULL) os << (*v);
|
---|
| 97 | else os << (*mMtx);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /* --Methode-- */
|
---|
| 101 | template <class T>
|
---|
| 102 | PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
|
---|
| 103 | {
|
---|
| 104 | TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 105 | if (v == NULL) return(NULL);
|
---|
| 106 | else {
|
---|
[1971] | 107 | dopt = "thinline " + dopt;
|
---|
[585] | 108 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /* --Methode-- */
|
---|
| 113 | template <class T>
|
---|
| 114 | P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
|
---|
| 115 | {
|
---|
| 116 | return ( new POTMatrixAdapter<T>(mMtx, false) );
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /* --Methode-- */
|
---|
| 120 | template <class T>
|
---|
| 121 | NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
|
---|
| 122 | {
|
---|
| 123 | adel = true;
|
---|
| 124 | return( new NTupInt_TMatrix<T>(mMtx) );
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 |
|
---|
[1207] | 128 | /* --Methode-- */
|
---|
| 129 | template <class T>
|
---|
| 130 | GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
|
---|
| 131 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
| 132 | ,int i1,int i2,int j1,int j2)
|
---|
| 133 | {
|
---|
| 134 | adel = false;
|
---|
| 135 | if(!mMtx) return(NULL);
|
---|
[585] | 136 |
|
---|
[1207] | 137 | int nx,ny;
|
---|
| 138 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 139 |
|
---|
| 140 | if(vec) { // C'est un TVector
|
---|
| 141 | nx = vec->NElts();
|
---|
| 142 | ny = 1;
|
---|
| 143 | } else {
|
---|
| 144 | nx = mMtx->NRows();
|
---|
| 145 | ny = mMtx->NCol();
|
---|
| 146 | if(nx<=0 || ny<=0) return(NULL);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | i1 = (i1<0||i1>=nx)? 0: i1;
|
---|
| 150 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
|
---|
| 151 | j1 = (j1<0||j1>=ny)? 0: j1;
|
---|
| 152 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
|
---|
| 153 |
|
---|
| 154 | GeneralFitData* mGData = NULL;
|
---|
| 155 |
|
---|
| 156 | if(vec) { // C'est un TVector
|
---|
| 157 | mGData = new GeneralFitData(1,(i2-i1+1),0);
|
---|
| 158 | adel = true;
|
---|
| 159 | for(int i=i1;i<=i2;i++) {
|
---|
| 160 | double x = (double) i;
|
---|
| 161 | double f = (*vec)(i);
|
---|
| 162 | double e = 1.;
|
---|
| 163 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
| 164 | mGData->AddData1(x,f,e);
|
---|
| 165 | }
|
---|
| 166 | } else {
|
---|
| 167 | mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
|
---|
| 168 | adel = true;
|
---|
| 169 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
|
---|
| 170 | double x = (double) i;
|
---|
| 171 | double y = (double) j;
|
---|
| 172 | double f = (*mMtx)(i,j);
|
---|
| 173 | double e = 1.;
|
---|
| 174 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
| 175 | mGData->AddData2(x,y,f,e);
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | return mGData;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | template <class T>
|
---|
| 183 | AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
|
---|
| 184 | {
|
---|
| 185 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 186 | if(vec) {
|
---|
| 187 | TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true);
|
---|
| 188 | return v;
|
---|
| 189 | } else {
|
---|
| 190 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true);
|
---|
| 191 | return m;
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | template <class T>
|
---|
| 196 | AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
|
---|
| 197 | {
|
---|
| 198 | TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
|
---|
| 199 | if(vec) {
|
---|
| 200 | TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true);
|
---|
| 201 | return v;
|
---|
| 202 | } else {
|
---|
| 203 | TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true);
|
---|
| 204 | return m;
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[1315] | 208 | // ---- Specialisation pour complexes -----
|
---|
[2343] | 209 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 210 | GeneralFitData* NOMAdapter_TMatrix< complex<r_4> >::GetGeneralFitData(bool& adel
|
---|
| 211 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
| 212 | ,int i1,int i2,int j1,int j2)
|
---|
| 213 | {
|
---|
| 214 | return(NULL);
|
---|
| 215 | }
|
---|
[1207] | 216 |
|
---|
[2343] | 217 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 218 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
|
---|
| 219 | {
|
---|
| 220 | return(NULL);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[2343] | 223 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 224 | AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
|
---|
| 225 | {
|
---|
| 226 | return(NULL);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[2343] | 229 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 230 | GeneralFitData* NOMAdapter_TMatrix< complex<r_8> >::GetGeneralFitData(bool& adel
|
---|
| 231 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
| 232 | ,int i1,int i2,int j1,int j2)
|
---|
| 233 | {
|
---|
| 234 | return(NULL);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[2343] | 237 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 238 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
|
---|
| 239 | {
|
---|
| 240 | return(NULL);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[2343] | 243 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1315] | 244 | AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
|
---|
| 245 | {
|
---|
| 246 | return(NULL);
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[585] | 249 | // -------------------------------------------------------------
|
---|
| 250 |
|
---|
| 251 | /* --Methode-- */
|
---|
| 252 | template <class T>
|
---|
| 253 | NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
|
---|
| 254 | {
|
---|
| 255 | mMtx = m;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /* --Methode-- */
|
---|
| 259 | template <class T>
|
---|
| 260 | NTupInt_TMatrix<T>::~NTupInt_TMatrix()
|
---|
| 261 | {
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | /* --Methode-- */
|
---|
| 265 | template <class T>
|
---|
[2683] | 266 | sa_size_t NTupInt_TMatrix<T>::NbLines() const
|
---|
[585] | 267 | {
|
---|
| 268 | return( mMtx->NRows()*mMtx->NCols() );
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /* --Methode-- */
|
---|
| 272 | template <class T>
|
---|
[2683] | 273 | sa_size_t NTupInt_TMatrix<T>::NbColumns() const
|
---|
[585] | 274 | {
|
---|
| 275 | return(8);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | /* --Methode-- */
|
---|
| 279 | template <class T>
|
---|
[2683] | 280 | r_8* NTupInt_TMatrix<T>::GetLineD(sa_size_t n) const
|
---|
[585] | 281 | {
|
---|
| 282 | int i,j;
|
---|
| 283 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
| 284 | mRet[0] = n;
|
---|
| 285 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
| 286 | }
|
---|
| 287 | else {
|
---|
| 288 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
| 289 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
| 290 | mRet[3] = (*mMtx)(i,j);
|
---|
| 291 | mRet[4] = mRet[2]; mRet[5] = 0.;
|
---|
| 292 | mRet[6] = mRet[2]; mRet[7] = 0.;
|
---|
| 293 | }
|
---|
| 294 | return(mRet);
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /* --Methode-- */
|
---|
| 298 | template <class T>
|
---|
| 299 | string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
|
---|
| 300 | {
|
---|
| 301 | string nomx;
|
---|
| 302 | if (nx) nomx = nx;
|
---|
| 303 | else nomx = "_xh_";
|
---|
| 304 | string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
|
---|
| 305 | vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
|
---|
| 306 | vardec += "val = " + nomx + "[3]; \n";
|
---|
| 307 | vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
|
---|
| 308 | vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
|
---|
| 309 | return(vardec);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | /* --Methode-- */
|
---|
[2343] | 313 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[2689] | 314 | r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(sa_size_t n) const
|
---|
[585] | 315 | {
|
---|
| 316 | int i,j;
|
---|
| 317 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
| 318 | mRet[0] = n;
|
---|
| 319 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
| 320 | }
|
---|
| 321 | else {
|
---|
| 322 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
| 323 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
| 324 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
| 325 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
| 326 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
| 327 | }
|
---|
| 328 | return(mRet);
|
---|
| 329 | }
|
---|
| 330 |
|
---|
[2343] | 331 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[2689] | 332 | r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(sa_size_t n) const
|
---|
[585] | 333 | {
|
---|
| 334 | int i,j;
|
---|
| 335 | if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
|
---|
| 336 | mRet[0] = n;
|
---|
| 337 | for(i=1; i<8; i++) mRet[i] = 0.;
|
---|
| 338 | }
|
---|
| 339 | else {
|
---|
| 340 | i = n/mMtx->NCols(); j = n%mMtx->NCols();
|
---|
| 341 | mRet[0] = n; mRet[1] = i; mRet[2] = j;
|
---|
| 342 | mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
|
---|
| 343 | mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
|
---|
| 344 | mRet[7] = atan2(mRet[5], mRet[4]);
|
---|
| 345 | }
|
---|
| 346 | return(mRet);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[2930] | 351 | #pragma define_template NOMAdapter_TMatrix<uint_2>
|
---|
| 352 | #pragma define_template NOMAdapter_TMatrix<int_2>
|
---|
[585] | 353 | #pragma define_template NOMAdapter_TMatrix<int_4>
|
---|
[2930] | 354 | #pragma define_template NOMAdapter_TMatrix<int_8>
|
---|
[585] | 355 | #pragma define_template NOMAdapter_TMatrix<r_4>
|
---|
| 356 | #pragma define_template NOMAdapter_TMatrix<r_8>
|
---|
[1315] | 357 | #pragma define_template NOMAdapter_TMatrix< complex<r_4> >
|
---|
| 358 | #pragma define_template NOMAdapter_TMatrix< complex<r_8> >
|
---|
[2930] | 359 | #pragma define_template NTupInt_TMatrix<uint_2>
|
---|
| 360 | #pragma define_template NTupInt_TMatrix<int_2>
|
---|
[585] | 361 | #pragma define_template NTupInt_TMatrix<int_4>
|
---|
[2930] | 362 | #pragma define_template NTupInt_TMatrix<int_8>
|
---|
[585] | 363 | #pragma define_template NTupInt_TMatrix<r_4>
|
---|
| 364 | #pragma define_template NTupInt_TMatrix<r_8>
|
---|
[719] | 365 | #pragma define_template NTupInt_TMatrix< complex<r_4> >
|
---|
| 366 | #pragma define_template NTupInt_TMatrix< complex<r_8> >
|
---|
[585] | 367 | #endif
|
---|
| 368 |
|
---|
| 369 | #if defined(ANSI_TEMPLATES)
|
---|
[2930] | 370 | template class NOMAdapter_TMatrix<uint_2>;
|
---|
| 371 | template class NOMAdapter_TMatrix<int_2>;
|
---|
[585] | 372 | template class NOMAdapter_TMatrix<int_4>;
|
---|
[2930] | 373 | template class NOMAdapter_TMatrix<int_8>;
|
---|
[585] | 374 | template class NOMAdapter_TMatrix<r_4>;
|
---|
| 375 | template class NOMAdapter_TMatrix<r_8>;
|
---|
[1315] | 376 | template class NOMAdapter_TMatrix< complex<r_4> >;
|
---|
| 377 | template class NOMAdapter_TMatrix< complex<r_8> >;
|
---|
[2930] | 378 | template class NTupInt_TMatrix<uint_2>;
|
---|
| 379 | template class NTupInt_TMatrix<int_2>;
|
---|
[585] | 380 | template class NTupInt_TMatrix<int_4>;
|
---|
[2930] | 381 | template class NTupInt_TMatrix<int_8>;
|
---|
[585] | 382 | template class NTupInt_TMatrix<r_4>;
|
---|
| 383 | template class NTupInt_TMatrix<r_8>;
|
---|
[719] | 384 | template class NTupInt_TMatrix< complex<r_4> >;
|
---|
| 385 | template class NTupInt_TMatrix< complex<r_8> >;
|
---|
[585] | 386 | #endif
|
---|