| 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[], bool OldFile) | 
|---|
| 49 | { | 
|---|
| 50 | WriteF(outputfile, OldFile); | 
|---|
| 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(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(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: nombre de dimension du tableau a ecrire: " << nbdim << endl; | 
|---|
| 102 | int* naxisn = new int[nbdim]; | 
|---|
| 103 | int k; | 
|---|
| 104 | for (k=0; k< nbdim; k++) | 
|---|
| 105 | { | 
|---|
| 106 | naxisn[k] = dobj_->Size(k); | 
|---|
| 107 | cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl; | 
|---|
| 108 | } | 
|---|
| 109 | char type; | 
|---|
| 110 | if ( typeid(T) == typeid(r_8) ) type='D'; | 
|---|
| 111 | else | 
|---|
| 112 | if ( typeid(T) == typeid(r_4) )  type='E'; | 
|---|
| 113 | else | 
|---|
| 114 | if ( typeid(T) == typeid(int_4) )  type='I'; | 
|---|
| 115 | else | 
|---|
| 116 | { | 
|---|
| 117 | cout <<  " type du tableau= " <<  typeid(T).name() << endl; | 
|---|
| 118 | throw IOExc("FITS_TArray:: unknown type"); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | int nbels = 1; | 
|---|
| 122 | for (k=0; k< nbdim; k++) | 
|---|
| 123 | { | 
|---|
| 124 | if (naxisn[k] > 0) nbels *= naxisn[k]; | 
|---|
| 125 | } | 
|---|
| 126 | cout << " nombre total d'elements a copier " << nbels << endl; | 
|---|
| 127 | fn.makeHeaderImageOnFits(type, nbdim, naxisn); | 
|---|
| 128 | if (!dobj_->IsPacked()) | 
|---|
| 129 | { | 
|---|
| 130 | cout << " IsPacked() = " << dobj_->IsPacked() << endl; | 
|---|
| 131 | throw PException(" FITS_TARRAY: this case is not yet programmed"); | 
|---|
| 132 |  | 
|---|
| 133 | } | 
|---|
| 134 | if (dobj_->MinStep() != 1) | 
|---|
| 135 | { | 
|---|
| 136 | cout << " MinStep()) = " << dobj_->MinStep() << endl; | 
|---|
| 137 | throw PException(" FITS_TARRAY: this case is not yet programmed"); | 
|---|
| 138 |  | 
|---|
| 139 | } | 
|---|
| 140 | fn.putImageToFits(nbels, dobj_->Data()); | 
|---|
| 141 |  | 
|---|
| 142 | delete [] naxisn; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| 147 | #pragma define_template FITS_TArray<r_8> | 
|---|
| 148 | #pragma define_template FITS_TArray<r_4> | 
|---|
| 149 | #endif | 
|---|
| 150 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| 151 | template class FITS_TArray<r_8>; | 
|---|
| 152 | template class FITS_TArray<r_4>; | 
|---|
| 153 | #endif | 
|---|