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_= NULL;
|
---|
15 | ownobj_=false;
|
---|
16 | }
|
---|
17 |
|
---|
18 | template <class T>
|
---|
19 | FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
|
---|
20 | {
|
---|
21 | dobj_=NULL;
|
---|
22 | ownobj_=false;
|
---|
23 | Read(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 |
|
---|
48 | template <class T>
|
---|
49 | AnyDataObj* FITS_TArray<T>::DataObj()
|
---|
50 | {
|
---|
51 | return(dobj_);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | template <class T>
|
---|
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)
|
---|
69 | {
|
---|
70 | if (!is.IsFitsImage())
|
---|
71 | {
|
---|
72 | throw PException("ReadFromFits: the fits file seems not to be an image");
|
---|
73 | }
|
---|
74 | int dimension = is.nbDimOfImage();
|
---|
75 | cout << " dimension de l'image a lire: " << dimension << endl;
|
---|
76 |
|
---|
77 | sa_size_t * siz = new sa_size_t[dimension];
|
---|
78 | for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
|
---|
79 | if(dobj_ == NULL)
|
---|
80 | {
|
---|
81 | dobj_ = new TArray<T>(dimension,siz);
|
---|
82 | ownobj_ = true;
|
---|
83 | }
|
---|
84 | else
|
---|
85 | dobj_->ReSize(dimension,siz);
|
---|
86 |
|
---|
87 | delete [] siz;
|
---|
88 | if (dobj_->Size() != is.nbOfImageData() )
|
---|
89 | {
|
---|
90 | cout << " total size of TArray: " << dobj_->Size() << endl;
|
---|
91 | cout << " total size from fits file: " << is.nbOfImageData() << endl;
|
---|
92 | throw PException("ReadFromFits: size conflict");
|
---|
93 | }
|
---|
94 | // On lit le tableau
|
---|
95 | is.GetSingleColumn( dobj_->Data(),dobj_->Size());
|
---|
96 | dobj_->Info() = is.DVListFromFits();
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | template <class T>
|
---|
102 | void FITS_TArray<T>::WriteToFits(FitsOutFile& os)
|
---|
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 | }
|
---|
110 | cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
|
---|
111 | int* naxisn = new int[nbdim];
|
---|
112 | int k;
|
---|
113 | for (k=0; k< nbdim; k++)
|
---|
114 | {
|
---|
115 | naxisn[k] = dobj_->Size(k);
|
---|
116 | cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
|
---|
117 | }
|
---|
118 | char type;
|
---|
119 | if ( typeid(T) == typeid(r_8) ) type='D';
|
---|
120 | else
|
---|
121 | if ( typeid(T) == typeid(r_4) ) type='E';
|
---|
122 | else
|
---|
123 | if ( typeid(T) == typeid(int_4) ) type='I';
|
---|
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;
|
---|
131 | for (k=0; k< nbdim; k++)
|
---|
132 | {
|
---|
133 | if (naxisn[k] > 0) nbels *= naxisn[k];
|
---|
134 | }
|
---|
135 | cout << " nombre total d'elements a copier " << nbels << endl;
|
---|
136 | os.makeHeaderImageOnFits(type, nbdim, naxisn, dobj_->Info());
|
---|
137 | if (!dobj_->IsPacked())
|
---|
138 | {
|
---|
139 | cout << " IsPacked() = " << dobj_->IsPacked() << endl;
|
---|
140 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
141 |
|
---|
142 | }
|
---|
143 | if (dobj_->MinStep() != 1)
|
---|
144 | {
|
---|
145 | cout << " MinStep()) = " << dobj_->MinStep() << endl;
|
---|
146 | throw PException(" FITS_TARRAY: this case is not yet programmed");
|
---|
147 |
|
---|
148 | }
|
---|
149 | os.PutImageToFits(nbels, dobj_->Data());
|
---|
150 |
|
---|
151 | delete [] naxisn;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
156 | #pragma define_template FITS_TArray<r_8>
|
---|
157 | #pragma define_template FITS_TArray<r_4>
|
---|
158 | #endif
|
---|
159 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
160 | template class FITS_TArray<r_8>;
|
---|
161 | template class FITS_TArray<r_4>;
|
---|
162 | #endif
|
---|