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