1 | #include "sopnamsp.h"
|
---|
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 |
|
---|
10 | /*!
|
---|
11 | \class SOPHYA::FITS_TArray
|
---|
12 | \ingroup FitsIOServer
|
---|
13 | FITS format I/O handler for SOPHYA::TArray objects in Sophya.
|
---|
14 | */
|
---|
15 |
|
---|
16 | using namespace SOPHYA;
|
---|
17 |
|
---|
18 | template <class T>
|
---|
19 | FITS_TArray<T>::FITS_TArray()
|
---|
20 | {
|
---|
21 | dobj_= NULL;
|
---|
22 | ownobj_=false;
|
---|
23 | }
|
---|
24 |
|
---|
25 | template <class T>
|
---|
26 | FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
|
---|
27 | {
|
---|
28 | dobj_=NULL;
|
---|
29 | ownobj_=false;
|
---|
30 | Read(inputfile,hdunum);
|
---|
31 | }
|
---|
32 |
|
---|
33 | template <class T>
|
---|
34 | FITS_TArray<T>::FITS_TArray(const TArray<T> & obj)
|
---|
35 | {
|
---|
36 | dobj_ = new TArray<T>(obj);
|
---|
37 | ownobj_=true;
|
---|
38 | }
|
---|
39 |
|
---|
40 | template <class T>
|
---|
41 | FITS_TArray<T>::FITS_TArray(TArray<T> *obj)
|
---|
42 | {
|
---|
43 | dobj_ = obj;
|
---|
44 | ownobj_=false;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | template <class T>
|
---|
49 | FITS_TArray<T>::~FITS_TArray()
|
---|
50 | {
|
---|
51 | if (ownobj_ && dobj_) delete dobj_;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | template <class T>
|
---|
56 | AnyDataObj* FITS_TArray<T>::DataObj()
|
---|
57 | {
|
---|
58 | return(dobj_);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | template <class T>
|
---|
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)
|
---|
76 | {
|
---|
77 | if (!is.IsFitsImage())
|
---|
78 | {
|
---|
79 | throw PException("ReadFromFits: the fits file seems not to be an image");
|
---|
80 | }
|
---|
81 | int dimension = is.nbDimOfImage();
|
---|
82 | sa_size_t * siz = new sa_size_t[dimension];
|
---|
83 | for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
|
---|
84 | if(dobj_ == NULL)
|
---|
85 | {
|
---|
86 | dobj_ = new TArray<T>(dimension,siz);
|
---|
87 | ownobj_ = true;
|
---|
88 | }
|
---|
89 | else
|
---|
90 | dobj_->ReSize(dimension,siz);
|
---|
91 |
|
---|
92 | delete [] siz;
|
---|
93 | if (dobj_->Size() != is.nbOfImageData() )
|
---|
94 | {
|
---|
95 | cout << " total size of TArray: " << dobj_->Size() << endl;
|
---|
96 | cout << " total size from fits file: " << is.nbOfImageData() << endl;
|
---|
97 | throw PException("ReadFromFits: size conflict");
|
---|
98 | }
|
---|
99 | // On lit le tableau
|
---|
100 | is.GetSingleColumn( dobj_->Data(),dobj_->Size());
|
---|
101 | dobj_->Info() = is.DVListFromFits();
|
---|
102 |
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | template <class T>
|
---|
107 | void FITS_TArray<T>::WriteToFits(FitsOutFile& os)
|
---|
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 | }
|
---|
115 | //cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
|
---|
116 | int* naxisn = new int[nbdim];
|
---|
117 | int k;
|
---|
118 | for (k=0; k< nbdim; k++)
|
---|
119 | {
|
---|
120 | naxisn[k] = dobj_->Size(k);
|
---|
121 | // cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
|
---|
122 | }
|
---|
123 | char type;
|
---|
124 | if ( typeid(T) == typeid(r_8) ) type='D';
|
---|
125 | else
|
---|
126 | if ( typeid(T) == typeid(r_4) ) type='E';
|
---|
127 | else
|
---|
128 | if ( typeid(T) == typeid(int_4) ) type='J';
|
---|
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;
|
---|
136 | for (k=0; k< nbdim; k++)
|
---|
137 | {
|
---|
138 | if (naxisn[k] > 0) nbels *= naxisn[k];
|
---|
139 | }
|
---|
140 | // cout << " nombre total d'elements a copier " << nbels << endl;
|
---|
141 | DVList dvl( dobj_->Info() );
|
---|
142 | dvl["Content"]= "TArray";
|
---|
143 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
144 | os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
|
---|
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 | }
|
---|
157 | os.PutImageToFits(nbels, dobj_->Data());
|
---|
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>
|
---|
166 | #pragma define_template FITS_TArray<int_4>
|
---|
167 | #endif
|
---|
168 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
169 | namespace SOPHYA {
|
---|
170 | template class FITS_TArray<r_8>;
|
---|
171 | template class FITS_TArray<r_4>;
|
---|
172 | template class FITS_TArray<int_4>;
|
---|
173 | }
|
---|
174 | #endif
|
---|