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

Last change on this file since 2322 was 2197, checked in by lemeur, 23 years ago

toilette d'ete : rationalisation de types...

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