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