source: Sophya/trunk/SophyaExt/FitsIOServer/fitslocalmap.cc@ 3064

Last change on this file since 3064 was 3047, checked in by ansari, 19 years ago

Ajout FitsInOutFile::SkipEmptyFirstHDU() , positionnement sur HDU 2 si HDU 1 vide ds operateur >> lisant des tables + autres petites corrections , Reza 11/08/2006

File size: 7.2 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include "fitslocalmap.h"
4///////////////////////////////////////////////////////////
5// Les objets delegues pour la gestion de persistance sur fichiers fits
6// pout LocalMap
7///////////////////////////////////////////////////////////
8
9/*!
10 \class SOPHYA::FITS_LocalMap
11 \ingroup FitsIOServer
12 FITS format I/O handler for SOPHYA::LocalMap objects.
13*/
14
15using namespace SOPHYA;
16
17template <class T>
18FITS_LocalMap<T>::FITS_LocalMap()
19{
20 dobj_= NULL;
21 ownobj_=false;
22}
23
24template <class T>
25FITS_LocalMap<T>::FITS_LocalMap(char inputfile[],int hdunum)
26{
27 dobj_=NULL;
28 ownobj_=false;
29 Read(inputfile,hdunum);
30}
31
32template <class T>
33FITS_LocalMap<T>::FITS_LocalMap(const LocalMap<T> & obj)
34{
35 dobj_ = new LocalMap<T>(obj);
36 ownobj_=true;
37}
38
39template <class T>
40FITS_LocalMap<T>::FITS_LocalMap(LocalMap<T> *obj)
41{
42 dobj_ = obj;
43 ownobj_=false;
44}
45
46
47template <class T>
48FITS_LocalMap<T>::~FITS_LocalMap()
49{
50 if (ownobj_ && dobj_) delete dobj_;
51}
52
53
54template <class T>
55AnyDataObj* FITS_LocalMap<T>::DataObj()
56{
57 return(dobj_);
58}
59
60
61template <class T>
62void FITS_LocalMap<T>::SetDataObj(AnyDataObj & o)
63 {
64 LocalMap<T>* po = dynamic_cast< LocalMap<T>* >(& o);
65 if (po == NULL) return;
66 if (ownobj_ && dobj_) delete dobj_;
67 dobj_ = po;
68 ownobj_ = false;
69 }
70
71template <class T>
72int FITS_LocalMap<T>::CheckHandling(AnyDataObj & o)
73{
74 if ( typeid(o) == typeid( LocalMap< T > ) ) return 2;
75 LocalMap<T> * po = dynamic_cast< LocalMap<T> * >(&o);
76 if (po == NULL) return 0;
77 else return 1;
78}
79
80template <class T>
81int FITS_LocalMap<T>::CheckReadability(FitsInOutFile& is)
82{
83 if (is.CurrentHDUType() != IMAGE_HDU ) return 0;
84 string key;
85 key = "Content";
86 string clsnm = is.KeyValue(key);
87 if (clsnm != "LocalMap") return 0;
88
89 long naxes[2];
90 int naxis=2;
91 int imgtyp = is.GetImageHDUInfo(naxis, naxes);
92 if (naxis != 2) return 0;
93
94 T x = 0;
95 if (imgtyp == FitsTypes::ImageType(x)) return 2 ;
96 else return 1;
97}
98
99template <class T>
100FitsHandlerInterface* FITS_LocalMap<T>::Clone()
101{
102 return new FITS_LocalMap<T>() ;
103}
104
105template <class T>
106void FITS_LocalMap<T>::ReadFromFits(FitsInFile& is)
107{
108 if(dobj_ == NULL)
109 {
110 dobj_= new LocalMap<T>;
111 ownobj_= true;
112 }
113 int nbentries;
114
115 // lecture sur bin-table
116 //
117 // if (!is.IsFitsTable())
118 // {
119 // throw PException("ReadFromFits: the fits file seems not to be a bintable");
120 // }
121 // int nbcols;
122 // nbcols = is.NbColsFromFits();
123 // if (nbcols != 1)
124 // {
125 // throw IOExc("le fichier fits n'est pas une LocalMap");
126 // }
127 // nbentries = is.NentriesFromFits(0);
128 //
129
130 // lecture sur image fits
131 //
132 if (!is.IsFitsImage())
133 throw PException("ReadFromFits: the fits file seems not to be an image");
134 int dimension = is.nbDimOfImage();
135 if (dimension != 2 )
136 cout << " WARNING::ReadFromFits: the fits image seems not to be a matrix" << endl;
137
138 nbentries = is.nbOfImageData();
139 //
140
141 DVList dvl=is.DVListFromFits();
142
143 int_4 nSzX = dvl.GetI("NSZX");
144 int_4 nSzY = dvl.GetI("NSZY");
145 int_4 nPix = dvl.GetI("NPIX");
146 if (nPix != nbentries)
147 throw IOExc("longueur datablock incompatible avec nPix");
148 dobj_->ReSize(nSzX, nSzY);
149 int_4 localMappingDone = dvl.GetI("LCMP");
150 if (localMappingDone)
151 {
152 int_4 x0 = dvl.GetI("X0");
153 int_4 y0 = dvl.GetI("Y0");
154 double theta = dvl.GetD("THETA");
155 double phi = dvl.GetD("PHI");
156 double angle = dvl.GetD("ANGLE");
157 dobj_->SetOrigin(theta, phi, x0, y0, angle);
158 double angleX = dvl.GetD("ANGLEX");
159 double angleY = dvl.GetD("ANGLEY");
160 dobj_->SetSize(angleX, angleY);
161 }
162 // On lit les DataBlocks;
163
164 dobj_->DataBlock().ReSize(nPix);
165 is.GetSingleColumn(dobj_->DataBlock().Data(),nPix);
166
167 // dvlist de LocalMap
168 dobj_->Info() = is.DVListFromFits();
169}
170
171template <class T>
172void FITS_LocalMap<T>::WriteToFits(FitsOutFile& os)
173{
174 if(dobj_ == NULL)
175 {
176 cout << " WriteToFits:: dobj_= null " << endl;
177 return;
178 }
179 int nx, ny;
180
181 DVList dvl( dobj_->Info() );
182 nx = dobj_->Size_x();
183 dvl["NSZX"] = nx;
184 dvl.SetComment("NSZX", "number of pixels in x direction");
185 ny = dobj_->Size_y();
186 dvl["NSZY"] = ny;
187 dvl.SetComment("NSZY", "number of pixels in y direction");
188 dvl["NPIX"] = dobj_->NbPixels();
189 dvl.SetComment("NPIX", "number of pixels in local map");
190
191 if(dobj_->LocalMap_isDone())
192 {
193 dvl["LCMP"] = (int_4) 1;
194 dvl.SetComment("LCMP", "local mapping 1= done, 0= not done");
195 int_4 x0 = 0;
196 int_4 y0 = 0;
197 double theta = 0.;
198 double phi = 0.;
199 double angle = 0.;
200 dobj_->Origin(theta, phi, x0, y0, angle);
201 dvl["X0"] = x0;
202 dvl.SetComment("X0", "number of pixel of the origin, x direction");
203 dvl["Y0"] = y0;
204 dvl.SetComment("Y0", "number of pixel of the origin, y direction");
205 dvl["THETA"] = theta;
206 dvl.SetComment("THETA", "theta position of the map-origin");
207 dvl["PHI"] = phi;
208 dvl.SetComment("PHI", "phi position of the map origin");
209 dvl["ANGLE"] = angle;
210 dvl.SetComment("ANGLE", "angle between max x axis and sphere phi-axis");
211
212 double angleX =0.;
213 double angleY = 0.;
214 dobj_->Aperture(angleX, angleY);
215 dvl["ANGLEX"] = angleX;
216 dvl.SetComment("ANGLEX", "sphere angle covered by map x-extension ");
217 dvl["ANGLEY"] = angleY;
218 dvl.SetComment("ANGLEY", "sphere angle covered by map y-extension ");
219 }
220 else
221 {
222 dvl["LCMP"] = (int_4) 0;
223 }
224 dvl["Content"]= "LocalMap";
225 dvl.SetComment("Content", "name of SOPHYA object");
226 dvl["SOPCLSNM"]= "SOPHYA::LocalMap<T>";
227 dvl.SetComment("SOPCLSNM", "SOPHYA class name");
228 // On ecrit les dataBlocks
229 vector<string> Noms;
230 Noms.push_back(dvl.GetS("Content"));
231 // string extname("SIMULATION");
232 string extname = os.NextExtensionName();
233
234 // sortie sur image fits
235 //
236 char type;
237 if ( typeid(T) == typeid(r_8) ) type='D';
238 else
239 if ( typeid(T) == typeid(r_4) ) type='E';
240 else
241 if ( typeid(T) == typeid(int_4) ) type='J';
242 else
243 {
244 cout << " type du tableau= " << typeid(T).name() << endl;
245 throw IOExc("FITS_LocalMap:: unknown type");
246 }
247 int nbdim = 2;
248 int* naxisn = new int[nbdim];
249 naxisn[0] = dobj_->Matrix().Size(0);
250 naxisn[1] = dobj_->Matrix().Size(1);
251 os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
252 os.PutImageToFits(nx*ny, dobj_->Matrix().Data());
253
254 delete [] naxisn;
255 //
256
257 // sortie sur bin-table fits
258 //
259 // string Type;
260 // if (typeid(T) == typeid(r_8) ) Type+='D';
261 // else
262 // if (typeid(T) == typeid(r_4) ) Type+='E';
263 // else
264 // {
265 // cout << " type de la LocalMap = " << typeid(T).name() << endl;
266 // throw IOExc("FITS_LocalMap:: unknown type");
267 // }
268 // vector<int> dummy;
269 // os.makeHeaderBntblOnFits(Type, Noms, dobj_->NbPixels(), 1, &dvl, extname, dummy);
270 // os.PutColToFits(0, dobj_->NbPixels(), dobj_->DataBlock().Data());
271 //
272
273}
274
275#ifdef __CXX_PRAGMA_TEMPLATES__
276#pragma define_template FITS_LocalMap<r_8>
277#pragma define_template FITS_LocalMap<r_4>
278#pragma define_template FITS_LocalMap<int_4>
279#endif
280#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
281namespace SOPHYA {
282template class FITS_LocalMap<r_8>;
283template class FITS_LocalMap<r_4>;
284template class FITS_LocalMap<int_4>;
285}
286#endif
Note: See TracBrowser for help on using the repository browser.