[863] | 1 | #include "machdefs.h"
|
---|
| 2 | #include "pexceptions.h"
|
---|
| 3 | #include "fitstarray.h"
|
---|
| 4 | ///////////////////////////////////////////////////////////
|
---|
| 5 | // Les objets delegues pour la gestion de persistance sur fichiers fits
|
---|
| 6 | // pout TArray
|
---|
| 7 | ///////////////////////////////////////////////////////////
|
---|
| 8 |
|
---|
| 9 | using namespace SOPHYA;
|
---|
| 10 |
|
---|
| 11 | template <class T>
|
---|
| 12 | FITS_TArray<T>::FITS_TArray()
|
---|
| 13 | {
|
---|
| 14 | dobj_=new TArray<T>;
|
---|
| 15 | ownobj=true;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | template <class T>
|
---|
| 19 | FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
|
---|
| 20 | {
|
---|
| 21 | dobj_=new TArray<T>;
|
---|
| 22 | ownobj=true;
|
---|
| 23 | ReadF(inputfile,hdunum);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | template <class T>
|
---|
| 27 | FITS_TArray<T>::FITS_TArray(const TArray<T> & obj)
|
---|
| 28 | {
|
---|
| 29 | dobj_ = new TArray<T>(obj);
|
---|
| 30 | ownobj=true;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | template <class T>
|
---|
| 34 | FITS_TArray<T>::FITS_TArray(TArray<T> *obj)
|
---|
| 35 | {
|
---|
| 36 | dobj_ = obj;
|
---|
| 37 | ownobj=false;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | template <class T>
|
---|
| 42 | FITS_TArray<T>::~FITS_TArray()
|
---|
| 43 | {
|
---|
| 44 | if (ownobj && dobj_) delete dobj_;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | template <class T>
|
---|
| 48 | void FITS_TArray<T>::Write(char outputfile[])
|
---|
| 49 | {
|
---|
| 50 | WriteF(outputfile);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | template <class T>
|
---|
| 56 | AnyDataObj* FITS_TArray<T>::DataObj()
|
---|
| 57 | {
|
---|
| 58 | return(dobj_);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | template <class T>
|
---|
| 62 | void FITS_TArray<T>::ReadFromFits(const FitsFile& fn)
|
---|
| 63 | {
|
---|
| 64 |
|
---|
| 65 | if (!fn.IsFitsImage())
|
---|
| 66 | {
|
---|
| 67 | throw PException("ReadFromFits: the fits file seems not to be an image");
|
---|
| 68 | }
|
---|
| 69 | int dimension = fn.nbDimOfImage();
|
---|
| 70 | cout << " dimension de l'image a lire: " << dimension << endl;
|
---|
| 71 |
|
---|
| 72 | uint_4* siz = new uint_4[dimension];
|
---|
| 73 | for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k];
|
---|
| 74 | if(dobj_ == NULL)
|
---|
| 75 | dobj_ = new TArray<T>(dimension,siz);
|
---|
| 76 | else
|
---|
| 77 | dobj_->ReSize(dimension,siz);
|
---|
| 78 |
|
---|
| 79 | delete [] siz;
|
---|
| 80 | if (dobj_->Size() != fn.nbOfImageData() )
|
---|
| 81 | {
|
---|
| 82 | cout << " total size of TArray: " << dobj_->Size() << endl;
|
---|
| 83 | cout << " total size from fits file: " << fn.nbOfImageData() << endl;
|
---|
| 84 | throw PException("ReadFromFits: size conflict");
|
---|
| 85 | }
|
---|
| 86 | // On lit le tableau
|
---|
| 87 | fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | template <class T>
|
---|
| 93 | void FITS_TArray<T>::WriteToFits(const FitsFile& fn)
|
---|
| 94 | {
|
---|
| 95 | if(dobj_ == NULL) return;
|
---|
| 96 | uint_4 nbdim = dobj_->NbDimensions();
|
---|
| 97 | if ( nbdim == 0)
|
---|
| 98 | {
|
---|
| 99 | throw PException(" FITS_TARRAY: number of dimensions of the array = 0?");
|
---|
| 100 | }
|
---|
| 101 | cout << "FITS_TARRAY: nombrede dimension du tableau a ecrire: " << nbdim << endl;
|
---|
| 102 | int* naxisn = new int[nbdim];
|
---|
| 103 | for (int k=0; k< nbdim; k++)
|
---|
| 104 | {
|
---|
| 105 | naxisn[k] = dobj_->Size(k);
|
---|
| 106 | cout << " taille de la dimension " << k << " : " << naxisn[k] << endl;
|
---|
| 107 | }
|
---|
| 108 | char type;
|
---|
| 109 | if (strncmp( typeid(T).name(),"r_8",3)==0 || strncmp( typeid(T).name(),"double",6)==0 ) type='D';
|
---|
| 110 | else
|
---|
| 111 | if (strncmp( typeid(T).name(),"r_4",3)==0 || strncmp( typeid(T).name(),"float",5)==0 ) type='E';
|
---|
| 112 | else
|
---|
| 113 | if (strncmp( typeid(T).name(),"int_4",5)==0 || strncmp( typeid(T).name(),"int",3)==0 ) type='I';
|
---|
| 114 | else
|
---|
| 115 | {
|
---|
| 116 | cout << " type du tableau= " << typeid(T).name() << endl;
|
---|
| 117 | throw IOExc("FITS_TArray:: unknown type");
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | int nbels = 1;
|
---|
| 121 | for (int k=0; k< nbdim; k++)
|
---|
| 122 | {
|
---|
| 123 | if (naxisn[k] > 0) nbels *= naxisn[k];
|
---|
| 124 | }
|
---|
| 125 | cout << " nombre total d'elements a copier " << nbels << endl;
|
---|
| 126 | fn.makeHeaderImageOnFits(type, nbdim, naxisn);
|
---|
| 127 | if (!dobj_->IsPacked())
|
---|
| 128 | {
|
---|
| 129 | cout << " IsPacked() = " << dobj_->IsPacked() << endl;
|
---|
| 130 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
| 131 |
|
---|
| 132 | }
|
---|
| 133 | if (dobj_->MinStep() != 1)
|
---|
| 134 | {
|
---|
| 135 | cout << " MinStep()) = " << dobj_->MinStep() << endl;
|
---|
| 136 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
| 137 |
|
---|
| 138 | }
|
---|
| 139 | fn.putImageToFits(nbels, dobj_->Data());
|
---|
| 140 |
|
---|
| 141 | delete [] naxisn;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 146 | #pragma define_template FITS_TArray<r_8>
|
---|
| 147 | #pragma define_template FITS_TArray<r_4>
|
---|
| 148 | #endif
|
---|
| 149 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 150 | template class FITS_TArray<r_8>;
|
---|
| 151 | template class FITS_TArray<r_4>;
|
---|
| 152 | #endif
|
---|