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