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