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