[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 |
|
---|
[1160] | 77 | sa_size_t * siz = new sa_size_t[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());
|
---|
[1143] | 96 | dobj_->Info() = is.DVListFromFits();
|
---|
[863] | 97 |
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[1136] | 101 | template <class T>
|
---|
| 102 | void FITS_TArray<T>::WriteToFits(FitsOutFile& os)
|
---|
[863] | 103 | {
|
---|
| 104 | if(dobj_ == NULL) return;
|
---|
| 105 | uint_4 nbdim = dobj_->NbDimensions();
|
---|
| 106 | if ( nbdim == 0)
|
---|
| 107 | {
|
---|
| 108 | throw PException(" FITS_TARRAY: number of dimensions of the array = 0?");
|
---|
| 109 | }
|
---|
[873] | 110 | cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
|
---|
[863] | 111 | int* naxisn = new int[nbdim];
|
---|
[923] | 112 | int k;
|
---|
| 113 | for (k=0; k< nbdim; k++)
|
---|
[863] | 114 | {
|
---|
| 115 | naxisn[k] = dobj_->Size(k);
|
---|
[873] | 116 | cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
|
---|
[863] | 117 | }
|
---|
| 118 | char type;
|
---|
[874] | 119 | if ( typeid(T) == typeid(r_8) ) type='D';
|
---|
[863] | 120 | else
|
---|
[874] | 121 | if ( typeid(T) == typeid(r_4) ) type='E';
|
---|
[863] | 122 | else
|
---|
[874] | 123 | if ( typeid(T) == typeid(int_4) ) type='I';
|
---|
[863] | 124 | else
|
---|
| 125 | {
|
---|
| 126 | cout << " type du tableau= " << typeid(T).name() << endl;
|
---|
| 127 | throw IOExc("FITS_TArray:: unknown type");
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | int nbels = 1;
|
---|
[923] | 131 | for (k=0; k< nbdim; k++)
|
---|
[863] | 132 | {
|
---|
| 133 | if (naxisn[k] > 0) nbels *= naxisn[k];
|
---|
| 134 | }
|
---|
| 135 | cout << " nombre total d'elements a copier " << nbels << endl;
|
---|
[1300] | 136 | DVList dvl( dobj_->Info() );
|
---|
| 137 | dvl["Content"]= "TArray";
|
---|
| 138 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
| 139 | os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
|
---|
[863] | 140 | if (!dobj_->IsPacked())
|
---|
| 141 | {
|
---|
| 142 | cout << " IsPacked() = " << dobj_->IsPacked() << endl;
|
---|
| 143 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
| 144 |
|
---|
| 145 | }
|
---|
| 146 | if (dobj_->MinStep() != 1)
|
---|
| 147 | {
|
---|
| 148 | cout << " MinStep()) = " << dobj_->MinStep() << endl;
|
---|
| 149 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
| 150 |
|
---|
| 151 | }
|
---|
[1210] | 152 | os.PutImageToFits(nbels, dobj_->Data());
|
---|
[863] | 153 |
|
---|
| 154 | delete [] naxisn;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 159 | #pragma define_template FITS_TArray<r_8>
|
---|
| 160 | #pragma define_template FITS_TArray<r_4>
|
---|
[1300] | 161 | #pragma define_template FITS_TArray<int_4>
|
---|
[863] | 162 | #endif
|
---|
| 163 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 164 | template class FITS_TArray<r_8>;
|
---|
| 165 | template class FITS_TArray<r_4>;
|
---|
[1300] | 166 | template class FITS_TArray<int_4>;
|
---|
[863] | 167 | #endif
|
---|