| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include <stdlib.h>
 | 
|---|
| 3 | #include <typeinfo>
 | 
|---|
| 4 | #include <iostream>
 | 
|---|
| 5 | #include <string>
 | 
|---|
| 6 | #include <complex>
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "datatype.h"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "nomtarradapter.h"
 | 
|---|
| 11 | #include "tvector.h"
 | 
|---|
| 12 | #include "pitvmaad.h"
 | 
|---|
| 13 | #include "piyfxdrw.h"
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "fioarr.h"
 | 
|---|
| 16 | #include "fitstarray.h"
 | 
|---|
| 17 | 
 | 
|---|
| 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_TArray<T>::NOMAdapter_TArray(TArray<T>* o)
 | 
|---|
| 28 |   : NObjMgrAdapter(o)
 | 
|---|
| 29 | {
 | 
|---|
| 30 | mArr = o;
 | 
|---|
| 31 | }
 | 
|---|
| 32 | 
 | 
|---|
| 33 | /* --Methode-- */
 | 
|---|
| 34 | template <class T> 
 | 
|---|
| 35 | NOMAdapter_TArray<T>::~NOMAdapter_TArray()
 | 
|---|
| 36 | {
 | 
|---|
| 37 | }
 | 
|---|
| 38 | 
 | 
|---|
| 39 | /* --Methode-- */
 | 
|---|
| 40 | template <class T> 
 | 
|---|
| 41 | NObjMgrAdapter* NOMAdapter_TArray<T>::Clone(AnyDataObj* o)
 | 
|---|
| 42 | {
 | 
|---|
| 43 | TArray<T>* a = dynamic_cast<TArray<T> *>(o);
 | 
|---|
| 44 | if (a) return ( new NOMAdapter_TArray<T>(a) );
 | 
|---|
| 45 | return ( new NObjMgrAdapter(o) );
 | 
|---|
| 46 | }
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /* --Methode-- */
 | 
|---|
| 49 | template <class T> 
 | 
|---|
| 50 | string NOMAdapter_TArray<T>::GetDataObjType()
 | 
|---|
| 51 | {
 | 
|---|
| 52 | string type = "TArray< ";
 | 
|---|
| 53 | 
 | 
|---|
| 54 | // type +=  DecodeTypeIdName(typeid(T).name());
 | 
|---|
| 55 | type += DataTypeInfo<T>::getTypeName();
 | 
|---|
| 56 | type +=  " > ";
 | 
|---|
| 57 | return(type);
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | /* --Methode-- */
 | 
|---|
| 61 | template <class T> 
 | 
|---|
| 62 | AnyDataObj* NOMAdapter_TArray<T>::CloneDataObj(bool share)
 | 
|---|
| 63 | {
 | 
|---|
| 64 | return ( new TArray<T>(*mArr, share) );
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | /* --Methode-- */
 | 
|---|
| 68 | template <class T> 
 | 
|---|
| 69 | void NOMAdapter_TArray<T>::ReadFits(string const & flnm)
 | 
|---|
| 70 | {
 | 
|---|
| 71 |   FitsInFile fis(flnm);
 | 
|---|
| 72 |   fis >> (*mArr);
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | /* --Methode-- */
 | 
|---|
| 76 | template <class T> 
 | 
|---|
| 77 | void NOMAdapter_TArray<T>::SaveFits(string const & flnm)
 | 
|---|
| 78 | {
 | 
|---|
| 79 |   FitsOutFile fos(flnm);
 | 
|---|
| 80 |   fos << (*mArr);
 | 
|---|
| 81 | }
 | 
|---|
| 82 | 
 | 
|---|
| 83 | // ---- Specialisation pour complexes -----
 | 
|---|
| 84 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 85 | void NOMAdapter_TArray< complex<r_4> >::ReadFits(string const & flnm)
 | 
|---|
| 86 | {
 | 
|---|
| 87 | cout << " NOMAdapter_TArray< complex<r_4> >::ReadFits() - Error " 
 | 
|---|
| 88 |      << " Not supported (complex data type)" << endl;
 | 
|---|
| 89 | }
 | 
|---|
| 90 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 91 | void NOMAdapter_TArray< complex<r_4> >::SaveFits(string const & flnm)
 | 
|---|
| 92 | {
 | 
|---|
| 93 | cout << " NOMAdapter_TArray< complex<r_4> >::SaveFits() - Error " 
 | 
|---|
| 94 |      << " Not supported (complex data type)" << endl;
 | 
|---|
| 95 | }
 | 
|---|
| 96 | 
 | 
|---|
| 97 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 98 | void NOMAdapter_TArray< complex<r_8> >::ReadFits(string const & flnm)
 | 
|---|
| 99 | {
 | 
|---|
| 100 | cout << " NOMAdapter_TArray< complex<r_8> >::ReadFits() - Error " 
 | 
|---|
| 101 |      << " Not supported (complex data type)" << endl;
 | 
|---|
| 102 | }
 | 
|---|
| 103 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 104 | void NOMAdapter_TArray< complex<r_8> >::SaveFits(string const & flnm)
 | 
|---|
| 105 | {
 | 
|---|
| 106 | cout << " NOMAdapter_TArray< complex<r_8> >::SaveFits() - Error " 
 | 
|---|
| 107 |      << " Not supported (complex data type)" << endl;
 | 
|---|
| 108 | }
 | 
|---|
| 109 | 
 | 
|---|
| 110 | /* --Methode-- */
 | 
|---|
| 111 | template <class T> 
 | 
|---|
| 112 | void NOMAdapter_TArray<T>::SavePPF(POutPersist& pos, string const & nom)
 | 
|---|
| 113 | {
 | 
|---|
| 114 | FIO_TArray<T> fio(mArr);
 | 
|---|
| 115 | fio.Write(pos, nom);
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | /* --Methode-- */
 | 
|---|
| 119 | template <class T> 
 | 
|---|
| 120 | void NOMAdapter_TArray<T>::Print(ostream& os)
 | 
|---|
| 121 | {
 | 
|---|
| 122 | os << (*mArr);
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | /* --Methode-- */
 | 
|---|
| 126 | template <class T> 
 | 
|---|
| 127 | PIDrawer * NOMAdapter_TArray<T>::GetDrawer(string & dopt)
 | 
|---|
| 128 | {
 | 
|---|
| 129 | if (mArr->NbDimensions() == 1) {
 | 
|---|
| 130 |   // On peut en faire un vecteur ...
 | 
|---|
| 131 |   TVector<T>* v = new TVector<T>(*mArr, true);  // on partage les donnees
 | 
|---|
| 132 |   dopt = "thinline," + dopt;
 | 
|---|
| 133 |   return( new PIYfXDrawer( new POTVectorAdapter<T>(v, true), NULL, true) );
 | 
|---|
| 134 | }
 | 
|---|
| 135 |  else return(NULL);
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | /* --Methode-- */
 | 
|---|
| 139 | template <class T> 
 | 
|---|
| 140 | P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string &)
 | 
|---|
| 141 | {
 | 
|---|
| 142 | if (mArr->NbDimensions() <= 2) {
 | 
|---|
| 143 |   // On peut en faire un tableau 2-D ...
 | 
|---|
| 144 |   TMatrix<T>* m = new TMatrix<T>(*mArr, true);  // on partage les donnees
 | 
|---|
| 145 |   return ( new POTMatrixAdapter<T>(m, true) );
 | 
|---|
| 146 | }
 | 
|---|
| 147 | else return(NULL);
 | 
|---|
| 148 | }
 | 
|---|
| 149 | 
 | 
|---|
| 150 | /* --Methode-- */
 | 
|---|
| 151 | template <class T> 
 | 
|---|
| 152 | NTupleInterface* NOMAdapter_TArray<T>::GetNTupleInterface(bool& adel)
 | 
|---|
| 153 | {
 | 
|---|
| 154 | adel = true;
 | 
|---|
| 155 | return( new NTupInt_TArray<T>(mArr) );
 | 
|---|
| 156 | }
 | 
|---|
| 157 | 
 | 
|---|
| 158 | 
 | 
|---|
| 159 | 
 | 
|---|
| 160 | 
 | 
|---|
| 161 | // -------------------------------------------------------------
 | 
|---|
| 162 | 
 | 
|---|
| 163 | /* --Methode-- */
 | 
|---|
| 164 | template <class T> 
 | 
|---|
| 165 | NTupInt_TArray<T>::NTupInt_TArray(TArray<T>* a)
 | 
|---|
| 166 | {
 | 
|---|
| 167 | mArr = a;
 | 
|---|
| 168 | }
 | 
|---|
| 169 | 
 | 
|---|
| 170 | /* --Methode-- */
 | 
|---|
| 171 | template <class T> 
 | 
|---|
| 172 | NTupInt_TArray<T>::~NTupInt_TArray()
 | 
|---|
| 173 | {
 | 
|---|
| 174 | }
 | 
|---|
| 175 | 
 | 
|---|
| 176 | /* --Methode-- */
 | 
|---|
| 177 | template <class T> 
 | 
|---|
| 178 | uint_4 NTupInt_TArray<T>::NbLines() const
 | 
|---|
| 179 | {
 | 
|---|
| 180 | return( mArr->Size() );
 | 
|---|
| 181 | }
 | 
|---|
| 182 | 
 | 
|---|
| 183 | /* --Methode-- */
 | 
|---|
| 184 | template <class T> 
 | 
|---|
| 185 | uint_4 NTupInt_TArray<T>::NbColumns() const 
 | 
|---|
| 186 | {
 | 
|---|
| 187 | return(11);
 | 
|---|
| 188 | }
 | 
|---|
| 189 | 
 | 
|---|
| 190 | /* --Methode-- */
 | 
|---|
| 191 | template <class T> 
 | 
|---|
| 192 | r_8* NTupInt_TArray<T>::GetLineD(int n) const 
 | 
|---|
| 193 | {
 | 
|---|
| 194 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
 | 
|---|
| 195 |   mRet[0] = n;
 | 
|---|
| 196 |   for(int i=1; i<11; i++)  mRet[i] = 0.;
 | 
|---|
| 197 | }
 | 
|---|
| 198 | else { 
 | 
|---|
| 199 |   sa_size_t ix, iy, iz, it, iu;
 | 
|---|
| 200 |   mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
 | 
|---|
| 201 |   mRet[0] = n;   mRet[1] = ix;  mRet[2] = iy;  
 | 
|---|
| 202 |   mRet[3] = iz;  mRet[4] = it;  mRet[5] = iu;  
 | 
|---|
| 203 |   mRet[6] = (*mArr)(ix,iy,iz,it,iu);
 | 
|---|
| 204 |   mRet[7] = mRet[2];  mRet[8] = 0.;
 | 
|---|
| 205 |   mRet[9] = mRet[2];  mRet[10] = 0.;
 | 
|---|
| 206 |   }
 | 
|---|
| 207 | return(mRet);
 | 
|---|
| 208 | }
 | 
|---|
| 209 | 
 | 
|---|
| 210 | /* --Methode-- */
 | 
|---|
| 211 | template <class T> 
 | 
|---|
| 212 | string NTupInt_TArray<T>::VarList_C(const char* nx) const 
 | 
|---|
| 213 | {
 | 
|---|
| 214 | string nomx;
 | 
|---|
| 215 | if (nx) nomx = nx;
 | 
|---|
| 216 | else nomx = "_xh_";
 | 
|---|
| 217 | string vardec = "double n,x,y,z,t,u,val,real,imag,mod,phas; \n";
 | 
|---|
| 218 | vardec += "n = " + nomx + "[0];  x = " + nomx + "[1]; y = " + nomx + "[2]; \n"; 
 | 
|---|
| 219 | vardec += "z = " + nomx + "[3];  t = " + nomx + "[4]; u = " + nomx + "[5]; \n"; 
 | 
|---|
| 220 | vardec += "val = " + nomx + "[6]; \n";
 | 
|---|
| 221 | vardec += "real = " + nomx + "[7];  imag = " + nomx + "[8]; \n";
 | 
|---|
| 222 | vardec += "mod  = " + nomx + "[9];  phas = " + nomx + "[10]; \n";
 | 
|---|
| 223 | return(vardec);
 | 
|---|
| 224 | }
 | 
|---|
| 225 | 
 | 
|---|
| 226 | /* --Methode-- */
 | 
|---|
| 227 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 228 | r_8* NTupInt_TArray< complex<r_4> >::GetLineD(int n) const 
 | 
|---|
| 229 | {
 | 
|---|
| 230 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
 | 
|---|
| 231 |   mRet[0] = n;
 | 
|---|
| 232 |   for(int i=1; i<11; i++)  mRet[i] = 0.;
 | 
|---|
| 233 | }
 | 
|---|
| 234 | else { 
 | 
|---|
| 235 |   sa_size_t ix, iy, iz, it, iu;
 | 
|---|
| 236 |   mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
 | 
|---|
| 237 |   mRet[0] = n;   mRet[1] = ix;  mRet[2] = iy;  
 | 
|---|
| 238 |   mRet[3] = iz;  mRet[4] = it;  mRet[5] = iu;  
 | 
|---|
| 239 |   mRet[7] = (*mArr)(ix,iy,iz,it,iu).real();
 | 
|---|
| 240 |   mRet[8] = (*mArr)(ix,iy,iz,it,iu).imag();
 | 
|---|
| 241 |   mRet[3] = mRet[6] = sqrt(mRet[7]*mRet[7]+mRet[8]*mRet[8]);
 | 
|---|
| 242 |   mRet[7] = atan2(mRet[8], mRet[7]);
 | 
|---|
| 243 | }
 | 
|---|
| 244 | return(mRet);
 | 
|---|
| 245 | }
 | 
|---|
| 246 | 
 | 
|---|
| 247 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
 | 
|---|
| 248 | r_8* NTupInt_TArray< complex<r_8> >::GetLineD(int n) const 
 | 
|---|
| 249 | {
 | 
|---|
| 250 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
 | 
|---|
| 251 |   mRet[0] = n;
 | 
|---|
| 252 |   for(int i=1; i<11; i++)  mRet[i] = 0.;
 | 
|---|
| 253 | }
 | 
|---|
| 254 | else { 
 | 
|---|
| 255 |   sa_size_t ix, iy, iz, it, iu;
 | 
|---|
| 256 |   mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
 | 
|---|
| 257 |   mRet[0] = n;   mRet[1] = ix;  mRet[2] = iy;  
 | 
|---|
| 258 |   mRet[3] = iz;  mRet[4] = it;  mRet[5] = iu;  
 | 
|---|
| 259 |   mRet[7] = (*mArr)(ix,iy,iz,it,iu).real();
 | 
|---|
| 260 |   mRet[8] = (*mArr)(ix,iy,iz,it,iu).imag();
 | 
|---|
| 261 |   mRet[3] = mRet[6] = sqrt(mRet[7]*mRet[7]+mRet[8]*mRet[8]);
 | 
|---|
| 262 |   mRet[7] = atan2(mRet[8], mRet[7]);
 | 
|---|
| 263 | }
 | 
|---|
| 264 | return(mRet);
 | 
|---|
| 265 | }
 | 
|---|
| 266 | 
 | 
|---|
| 267 | 
 | 
|---|
| 268 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 269 | //#pragma define_template NOMAdapter_TArray<uint_2>
 | 
|---|
| 270 | //#pragma define_template NOMAdapter_TArray<int_2>
 | 
|---|
| 271 | #pragma define_template NOMAdapter_TArray<int_4>
 | 
|---|
| 272 | #pragma define_template NOMAdapter_TArray<r_4>
 | 
|---|
| 273 | #pragma define_template NOMAdapter_TArray<r_8>
 | 
|---|
| 274 | #pragma define_template NOMAdapter_TArray< complex<r_4> >
 | 
|---|
| 275 | #pragma define_template NOMAdapter_TArray< complex<r_8> >
 | 
|---|
| 276 | //#pragma define_template NTupInt_TArray<uint_2>
 | 
|---|
| 277 | //#pragma define_template NTupInt_TArray<int_2>
 | 
|---|
| 278 | #pragma define_template NTupInt_TArray<int_4>
 | 
|---|
| 279 | #pragma define_template NTupInt_TArray<r_4>
 | 
|---|
| 280 | #pragma define_template NTupInt_TArray<r_8>
 | 
|---|
| 281 | #pragma define_template NTupInt_TArray< complex<r_4> >
 | 
|---|
| 282 | #pragma define_template NTupInt_TArray< complex<r_8> >
 | 
|---|
| 283 | #endif
 | 
|---|
| 284 | 
 | 
|---|
| 285 | #if defined(ANSI_TEMPLATES) 
 | 
|---|
| 286 | //template class NOMAdapter_TArray<uint_2>;
 | 
|---|
| 287 | //template class NOMAdapter_TArray<int_2>;
 | 
|---|
| 288 | template class NOMAdapter_TArray<int_4>;
 | 
|---|
| 289 | template class NOMAdapter_TArray<r_4>;
 | 
|---|
| 290 | template class NOMAdapter_TArray<r_8>;
 | 
|---|
| 291 | template class NOMAdapter_TArray< complex<r_4> >;
 | 
|---|
| 292 | template class NOMAdapter_TArray< complex<r_8> >;
 | 
|---|
| 293 | // template class NTupInt_TArray<uint_2>;
 | 
|---|
| 294 | // template class NTupInt_TArray<int_2>;
 | 
|---|
| 295 | template class NTupInt_TArray<int_4>;
 | 
|---|
| 296 | template class NTupInt_TArray<r_4>;
 | 
|---|
| 297 | template class NTupInt_TArray<r_8>;
 | 
|---|
| 298 | template class NTupInt_TArray< complex<r_4> >;
 | 
|---|
| 299 | template class NTupInt_TArray< complex<r_8> >;
 | 
|---|
| 300 | #endif
 | 
|---|