[2615] | 1 | #include "sopnamsp.h"
|
---|
[1315] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <typeinfo>
|
---|
[2322] | 5 | #include <iostream>
|
---|
[1315] | 6 | #include <string>
|
---|
| 7 | #include <complex>
|
---|
| 8 |
|
---|
| 9 | #include "datatype.h"
|
---|
| 10 |
|
---|
| 11 | #include "nomtarradapter.h"
|
---|
[1321] | 12 | #include "tvector.h"
|
---|
| 13 | #include "pitvmaad.h"
|
---|
[1905] | 14 | #include "piyfxdrw.h"
|
---|
[1315] | 15 |
|
---|
| 16 | #include "fioarr.h"
|
---|
| 17 |
|
---|
[2999] | 18 | #include "nobjmgr.h"
|
---|
[1315] | 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_TArray<T>::NOMAdapter_TArray(TArray<T>* o)
|
---|
| 29 | : NObjMgrAdapter(o)
|
---|
| 30 | {
|
---|
| 31 | mArr = o;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /* --Methode-- */
|
---|
| 35 | template <class T>
|
---|
| 36 | NOMAdapter_TArray<T>::~NOMAdapter_TArray()
|
---|
| 37 | {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /* --Methode-- */
|
---|
| 41 | template <class T>
|
---|
| 42 | NObjMgrAdapter* NOMAdapter_TArray<T>::Clone(AnyDataObj* o)
|
---|
| 43 | {
|
---|
| 44 | TArray<T>* a = dynamic_cast<TArray<T> *>(o);
|
---|
| 45 | if (a) return ( new NOMAdapter_TArray<T>(a) );
|
---|
| 46 | return ( new NObjMgrAdapter(o) );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /* --Methode-- */
|
---|
| 50 | template <class T>
|
---|
| 51 | string NOMAdapter_TArray<T>::GetDataObjType()
|
---|
| 52 | {
|
---|
| 53 | string type = "TArray< ";
|
---|
| 54 |
|
---|
| 55 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
| 56 | type += DataTypeInfo<T>::getTypeName();
|
---|
| 57 | type += " > ";
|
---|
| 58 | return(type);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /* --Methode-- */
|
---|
| 62 | template <class T>
|
---|
| 63 | AnyDataObj* NOMAdapter_TArray<T>::CloneDataObj(bool share)
|
---|
| 64 | {
|
---|
| 65 | return ( new TArray<T>(*mArr, share) );
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[2999] | 68 | /* --Methode-- */
|
---|
| 69 | template <class T>
|
---|
| 70 | string NOMAdapter_TArray<T>::GetInfoString(vector<string>& opts)
|
---|
| 71 | {
|
---|
| 72 | if (opts.size() == 0) return mArr->InfoString();
|
---|
| 73 | else {
|
---|
| 74 | char buff[128];
|
---|
| 75 | if (opts[0] == "rank") {
|
---|
| 76 | sprintf(buff,"%d", (int)mArr->Rank());
|
---|
| 77 | return string(buff);
|
---|
| 78 | }
|
---|
| 79 | if (opts[0] == "sizes") {
|
---|
| 80 | for(int_4 kd=0; kd<mArr->Rank(); kd++)
|
---|
| 81 | sprintf(buff,"%ld ", (long)mArr->Size(kd));
|
---|
| 82 | return string(buff);
|
---|
| 83 | }
|
---|
| 84 | else if ((opts[0] == "size") || (opts[0] == "nelts")) {
|
---|
| 85 | sprintf(buff, "%ld", (long)mArr->Size());
|
---|
| 86 | return string(buff);
|
---|
| 87 | }
|
---|
| 88 | else if (opts[0] == "sum") {
|
---|
| 89 | MuTyV mtv(mArr->Sum());
|
---|
| 90 | string s;
|
---|
| 91 | return mtv.Convert(s);
|
---|
| 92 | }
|
---|
| 93 | else return mArr->InfoString();
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
[1321] | 96 |
|
---|
| 97 | /* --Methode-- */
|
---|
| 98 | template <class T>
|
---|
[2999] | 99 | int NOMAdapter_TArray<T>::PerformOperation(vector<string>& opts)
|
---|
| 100 | {
|
---|
| 101 | bool ok = false;
|
---|
| 102 | if ((mArr->Rank() >= 3) && (opts.size() >= 2)) {
|
---|
| 103 | int_4 ks = atoi(opts[1].c_str());
|
---|
| 104 | TMatrix<T> * slice = new TMatrix<T>;
|
---|
| 105 | char buff[40];
|
---|
| 106 | if (opts[0] == "slicexy") {
|
---|
| 107 | slice->Share(mArr->SubArray(Range::all(), Range::all(), Range(ks),
|
---|
| 108 | Range::first(), Range::first()) );
|
---|
| 109 | ok = true;
|
---|
| 110 | sprintf(buff,"slicexy_%ld",(long)ks);
|
---|
| 111 | cout << "PerformOperation(): Extracting SliceXY(" << ks << ") from array" << endl;
|
---|
| 112 | }
|
---|
| 113 | else if (opts[0] == "sliceyz") {
|
---|
| 114 | slice->Share(mArr->SubArray(Range(ks), Range::all(), Range::all(),
|
---|
| 115 | Range::first(), Range::first()) );
|
---|
| 116 | ok = true;
|
---|
| 117 | sprintf(buff,"sliceyz_%ld",(long)ks);
|
---|
| 118 | cout << "PerformOperation(): Extracting SliceYZ(" << ks << ") from array" << endl;
|
---|
| 119 | }
|
---|
| 120 | else if (opts[0] == "slicexz") {
|
---|
| 121 | slice->Share(mArr->SubArray(Range::all(), Range(ks), Range::all(),
|
---|
| 122 | Range::first(), Range::first()) );
|
---|
| 123 | ok = true;
|
---|
| 124 | sprintf(buff,"slicexz_%ld",(long)ks);
|
---|
| 125 | cout << "PerformOperation(): Extracting SliceYZ(" << ks << ") from array" << endl;
|
---|
| 126 | }
|
---|
| 127 | if (ok) {
|
---|
| 128 | string nslice;
|
---|
| 129 | if (opts.size() > 2) nslice = opts[2];
|
---|
| 130 | else nslice = buff;
|
---|
| 131 | NamedObjMgr omg;
|
---|
| 132 | omg.AddObj(slice, nslice, true);
|
---|
| 133 | return 0;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | cout << "NOMAdapter_TArray<T>::PerformOperation(): Error operation/arguments !" << endl;
|
---|
| 138 | return 1;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /* --Methode-- */
|
---|
| 142 | template <class T>
|
---|
[1315] | 143 | void NOMAdapter_TArray<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
| 144 | {
|
---|
| 145 | FIO_TArray<T> fio(mArr);
|
---|
| 146 | fio.Write(pos, nom);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /* --Methode-- */
|
---|
| 150 | template <class T>
|
---|
[2975] | 151 | void NOMAdapter_TArray<T>::Print(ostream& os, int lev)
|
---|
[1315] | 152 | {
|
---|
[2975] | 153 | if (lev < 3) mArr->Show(os, false);
|
---|
| 154 | else mArr->Show(os, true);
|
---|
| 155 | if (lev > 0) mArr->Print(os, 10*lev);
|
---|
[1315] | 156 | }
|
---|
| 157 |
|
---|
[1321] | 158 | /* --Methode-- */
|
---|
| 159 | template <class T>
|
---|
| 160 | PIDrawer * NOMAdapter_TArray<T>::GetDrawer(string & dopt)
|
---|
| 161 | {
|
---|
| 162 | if (mArr->NbDimensions() == 1) {
|
---|
| 163 | // On peut en faire un vecteur ...
|
---|
| 164 | TVector<T>* v = new TVector<T>(*mArr, true); // on partage les donnees
|
---|
| 165 | dopt = "thinline," + dopt;
|
---|
| 166 | return( new PIYfXDrawer( new POTVectorAdapter<T>(v, true), NULL, true) );
|
---|
| 167 | }
|
---|
| 168 | else return(NULL);
|
---|
| 169 | }
|
---|
[1315] | 170 |
|
---|
| 171 | /* --Methode-- */
|
---|
| 172 | template <class T>
|
---|
[1321] | 173 | P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string &)
|
---|
| 174 | {
|
---|
| 175 | if (mArr->NbDimensions() <= 2) {
|
---|
| 176 | // On peut en faire un tableau 2-D ...
|
---|
| 177 | TMatrix<T>* m = new TMatrix<T>(*mArr, true); // on partage les donnees
|
---|
| 178 | return ( new POTMatrixAdapter<T>(m, true) );
|
---|
| 179 | }
|
---|
| 180 | else return(NULL);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | /* --Methode-- */
|
---|
| 184 | template <class T>
|
---|
[1315] | 185 | NTupleInterface* NOMAdapter_TArray<T>::GetNTupleInterface(bool& adel)
|
---|
| 186 | {
|
---|
| 187 | adel = true;
|
---|
| 188 | return( new NTupInt_TArray<T>(mArr) );
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | // -------------------------------------------------------------
|
---|
| 195 |
|
---|
| 196 | /* --Methode-- */
|
---|
| 197 | template <class T>
|
---|
| 198 | NTupInt_TArray<T>::NTupInt_TArray(TArray<T>* a)
|
---|
| 199 | {
|
---|
| 200 | mArr = a;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /* --Methode-- */
|
---|
| 204 | template <class T>
|
---|
| 205 | NTupInt_TArray<T>::~NTupInt_TArray()
|
---|
| 206 | {
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | /* --Methode-- */
|
---|
| 210 | template <class T>
|
---|
[2683] | 211 | sa_size_t NTupInt_TArray<T>::NbLines() const
|
---|
[1315] | 212 | {
|
---|
| 213 | return( mArr->Size() );
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | /* --Methode-- */
|
---|
| 217 | template <class T>
|
---|
[2683] | 218 | sa_size_t NTupInt_TArray<T>::NbColumns() const
|
---|
[1315] | 219 | {
|
---|
| 220 | return(11);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /* --Methode-- */
|
---|
| 224 | template <class T>
|
---|
[2683] | 225 | r_8* NTupInt_TArray<T>::GetLineD(sa_size_t n) const
|
---|
[1315] | 226 | {
|
---|
| 227 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
|
---|
| 228 | mRet[0] = n;
|
---|
| 229 | for(int i=1; i<11; i++) mRet[i] = 0.;
|
---|
| 230 | }
|
---|
| 231 | else {
|
---|
| 232 | sa_size_t ix, iy, iz, it, iu;
|
---|
| 233 | mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
|
---|
| 234 | mRet[0] = n; mRet[1] = ix; mRet[2] = iy;
|
---|
| 235 | mRet[3] = iz; mRet[4] = it; mRet[5] = iu;
|
---|
| 236 | mRet[6] = (*mArr)(ix,iy,iz,it,iu);
|
---|
| 237 | mRet[7] = mRet[2]; mRet[8] = 0.;
|
---|
| 238 | mRet[9] = mRet[2]; mRet[10] = 0.;
|
---|
| 239 | }
|
---|
| 240 | return(mRet);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | /* --Methode-- */
|
---|
| 244 | template <class T>
|
---|
| 245 | string NTupInt_TArray<T>::VarList_C(const char* nx) const
|
---|
| 246 | {
|
---|
| 247 | string nomx;
|
---|
| 248 | if (nx) nomx = nx;
|
---|
| 249 | else nomx = "_xh_";
|
---|
| 250 | string vardec = "double n,x,y,z,t,u,val,real,imag,mod,phas; \n";
|
---|
| 251 | vardec += "n = " + nomx + "[0]; x = " + nomx + "[1]; y = " + nomx + "[2]; \n";
|
---|
| 252 | vardec += "z = " + nomx + "[3]; t = " + nomx + "[4]; u = " + nomx + "[5]; \n";
|
---|
| 253 | vardec += "val = " + nomx + "[6]; \n";
|
---|
| 254 | vardec += "real = " + nomx + "[7]; imag = " + nomx + "[8]; \n";
|
---|
| 255 | vardec += "mod = " + nomx + "[9]; phas = " + nomx + "[10]; \n";
|
---|
| 256 | return(vardec);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | /* --Methode-- */
|
---|
[2343] | 260 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[2689] | 261 | r_8* NTupInt_TArray< complex<r_4> >::GetLineD(sa_size_t n) const
|
---|
[1315] | 262 | {
|
---|
| 263 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
|
---|
| 264 | mRet[0] = n;
|
---|
| 265 | for(int i=1; i<11; i++) mRet[i] = 0.;
|
---|
| 266 | }
|
---|
| 267 | else {
|
---|
| 268 | sa_size_t ix, iy, iz, it, iu;
|
---|
| 269 | mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
|
---|
| 270 | mRet[0] = n; mRet[1] = ix; mRet[2] = iy;
|
---|
| 271 | mRet[3] = iz; mRet[4] = it; mRet[5] = iu;
|
---|
| 272 | mRet[7] = (*mArr)(ix,iy,iz,it,iu).real();
|
---|
| 273 | mRet[8] = (*mArr)(ix,iy,iz,it,iu).imag();
|
---|
| 274 | mRet[3] = mRet[6] = sqrt(mRet[7]*mRet[7]+mRet[8]*mRet[8]);
|
---|
| 275 | mRet[7] = atan2(mRet[8], mRet[7]);
|
---|
| 276 | }
|
---|
| 277 | return(mRet);
|
---|
| 278 | }
|
---|
| 279 |
|
---|
[2343] | 280 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[2689] | 281 | r_8* NTupInt_TArray< complex<r_8> >::GetLineD(sa_size_t n) const
|
---|
[1315] | 282 | {
|
---|
| 283 | if ((n < 0) || (n >= (int)(mArr->Size()) ) ) {
|
---|
| 284 | mRet[0] = n;
|
---|
| 285 | for(int i=1; i<11; i++) mRet[i] = 0.;
|
---|
| 286 | }
|
---|
| 287 | else {
|
---|
| 288 | sa_size_t ix, iy, iz, it, iu;
|
---|
| 289 | mArr->IndexAtPosition(n, ix, iy, iz, it, iu);
|
---|
| 290 | mRet[0] = n; mRet[1] = ix; mRet[2] = iy;
|
---|
| 291 | mRet[3] = iz; mRet[4] = it; mRet[5] = iu;
|
---|
| 292 | mRet[7] = (*mArr)(ix,iy,iz,it,iu).real();
|
---|
| 293 | mRet[8] = (*mArr)(ix,iy,iz,it,iu).imag();
|
---|
| 294 | mRet[3] = mRet[6] = sqrt(mRet[7]*mRet[7]+mRet[8]*mRet[8]);
|
---|
| 295 | mRet[7] = atan2(mRet[8], mRet[7]);
|
---|
| 296 | }
|
---|
| 297 | return(mRet);
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 |
|
---|
| 301 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[2930] | 302 | #pragma define_template NOMAdapter_TArray<uint_2>
|
---|
| 303 | #pragma define_template NOMAdapter_TArray<int_2>
|
---|
[1315] | 304 | #pragma define_template NOMAdapter_TArray<int_4>
|
---|
[2930] | 305 | #pragma define_template NOMAdapter_TArray<int_8>
|
---|
[1315] | 306 | #pragma define_template NOMAdapter_TArray<r_4>
|
---|
| 307 | #pragma define_template NOMAdapter_TArray<r_8>
|
---|
| 308 | #pragma define_template NOMAdapter_TArray< complex<r_4> >
|
---|
| 309 | #pragma define_template NOMAdapter_TArray< complex<r_8> >
|
---|
[2930] | 310 | #pragma define_template NTupInt_TArray<uint_2>
|
---|
| 311 | #pragma define_template NTupInt_TArray<int_2>
|
---|
[1315] | 312 | #pragma define_template NTupInt_TArray<int_4>
|
---|
[2930] | 313 | #pragma define_template NTupInt_TArray<int_8>
|
---|
[1315] | 314 | #pragma define_template NTupInt_TArray<r_4>
|
---|
| 315 | #pragma define_template NTupInt_TArray<r_8>
|
---|
| 316 | #pragma define_template NTupInt_TArray< complex<r_4> >
|
---|
| 317 | #pragma define_template NTupInt_TArray< complex<r_8> >
|
---|
| 318 | #endif
|
---|
| 319 |
|
---|
| 320 | #if defined(ANSI_TEMPLATES)
|
---|
[2930] | 321 | template class NOMAdapter_TArray<uint_2>;
|
---|
| 322 | template class NOMAdapter_TArray<int_2>;
|
---|
[1315] | 323 | template class NOMAdapter_TArray<int_4>;
|
---|
[2930] | 324 | template class NOMAdapter_TArray<int_8>;
|
---|
[1315] | 325 | template class NOMAdapter_TArray<r_4>;
|
---|
| 326 | template class NOMAdapter_TArray<r_8>;
|
---|
| 327 | template class NOMAdapter_TArray< complex<r_4> >;
|
---|
| 328 | template class NOMAdapter_TArray< complex<r_8> >;
|
---|
[2930] | 329 | template class NTupInt_TArray<uint_2>;
|
---|
| 330 | template class NTupInt_TArray<int_2>;
|
---|
[1315] | 331 | template class NTupInt_TArray<int_4>;
|
---|
[2930] | 332 | template class NTupInt_TArray<int_8>;
|
---|
[1315] | 333 | template class NTupInt_TArray<r_4>;
|
---|
| 334 | template class NTupInt_TArray<r_8>;
|
---|
| 335 | template class NTupInt_TArray< complex<r_4> >;
|
---|
| 336 | template class NTupInt_TArray< complex<r_8> >;
|
---|
| 337 | #endif
|
---|