source: Sophya/trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc@ 1057

Last change on this file since 1057 was 1047, checked in by ansari, 25 years ago

modifs pour introduction lecteur de fits par lignes

File size: 6.1 KB
RevLine 
[854]1#include "pexceptions.h"
2#include "fitsspherehealpix.h"
3
4
5
6
7///////////////////////////////////////////////////////////////////////
8// ----objets delegues pour la gestion de persistance I/O format fits--
9// SphereHealpix
10////////////////////////////////////////////////////////////////////
11
12
13template <class T>
14FITS_SphereHEALPix<T>::FITS_SphereHEALPix()
15{
16 dobj_= new SphereHEALPix<T>;
17 ownobj= true;
18}
19
20template <class T>
21FITS_SphereHEALPix<T>::FITS_SphereHEALPix(char inputfile[],int hdunum)
22{
23 dobj_= new SphereHEALPix<T>;
24 ownobj= true;
25
26 ReadF(inputfile,hdunum);
[910]27 dobj_->SetTemp(true);
[854]28}
29
30
31template <class T>
32FITS_SphereHEALPix<T>::FITS_SphereHEALPix(const SphereHEALPix<T>& obj)
33{
34 dobj_= new SphereHEALPix<T>(obj, true);
35 dobj_->SetTemp(true);
36 ownobj= true;
37}
38
39template <class T>
40FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
41{
42 dobj_= obj;
43 ownobj= false;
44}
45
46template <class T>
47FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
48{
49 if (ownobj && dobj_) delete dobj_;
50}
51
52template <class T>
53AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
54{
55 return(dobj_);
56}
57
58template <class T>
[921]59void FITS_SphereHEALPix<T>::SetDataObj(AnyDataObj & o)
60{
61 SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
62 if (po == NULL) return;
63 if (ownobj && dobj_) delete dobj_;
64 dobj_ = po;
65 ownobj = false;
66}
67
68
69
70template <class T>
[972]71void FITS_SphereHEALPix<T>::Write(char outputfile[], bool OldFile)
[921]72{
[972]73 WriteF(outputfile, OldFile);
[921]74}
75template <class T>
76void FITS_SphereHEALPix<T>::Read(char inputfile[],int hdunum)
77{
78 ReadF(inputfile,hdunum);
79}
80
81template <class T>
[1047]82void FITS_SphereHEALPix<T>::WriteToFits()
[854]83{
84 if(dobj_ == NULL)
85 {
[921]86 cout << " WriteToFits:: dobj_= null " << endl;
[854]87 return;
88 }
89
90 DVList dvl;
91
92 SphereCoordSys* cs= dobj_->GetCoordSys();
93 string description= cs->description();
94 dvl["COORDSYS"]= description;
95
[972]96 dvl["PIXTYPE"] = "HEALPIX";
97 dvl.SetComment("PIXTYPE", "HEALPIX Pixelization");
[854]98 dvl["ORDERING"]= dobj_->TypeOfMap();
[972]99 dvl.SetComment("ORDERING", "Pixel ordering scheme, either RING or NESTED");
[854]100
101 int nSide= dobj_->SizeIndex();
[1004]102 dvl["NSIDE"]= (int_4) nSide;
[972]103 dvl.SetComment("NSIDE","Resolution parameter for HEALPIX" );
[854]104
105 int nPix= dobj_->NbPixels();
[1004]106 dvl["FIRSTPIX"]= (int_4) 0;
[972]107 dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
[1004]108 dvl["LASTPIX"]= (int_4) nPix-1;
[972]109 dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
[854]110 dvl["Content"]= "SphereHEALPix";
111 dvl["EXTNAME"]= "SIMULATION";
112 dvl["COMMENT"]= "Sky Map Pixelisation Specific Keywords";
113
114 // On ecrit les dataBlocks
115 char** Noms = new char*[1];
116 Noms[0]= new char[15];
117 strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
118 char extname[15];
119 strncpy(extname,dvl.GetS("EXTNAME").c_str(),15);
120
121 char Type[2];
[874]122 if (typeid(T) == typeid(r_8) ) Type[0]='D';
[854]123 else
[874]124 if (typeid(T) == typeid(r_4) ) Type[0]='E';
[854]125 else
126 {
127 cout << " type de la sphere= " << typeid(T).name() << endl;
128 throw IOExc("FITS_SphereHEALPix:: unknown type");
129 }
130 Type[1]='\0';
131 vector<int> dummy;
[1047]132 // fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
133 makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
[854]134 delete [] Noms[0];
135 delete [] Noms;
136 putColToFits(0, nPix, dobj_->pixels_.Data());
137}
138
139template <class T>
[1047]140void FITS_SphereHEALPix<T>::ReadFromFits()
[854]141{
142 if(dobj_ == NULL)
143 {
144 dobj_= new SphereHEALPix<T>;
145 dobj_->SetTemp(true);
146 ownobj= true;
147 }
148
149
150 int nbcols, nbentries;
[1047]151 // nbcols = fn.NbColsFromFits();
152 nbcols = NbColsFromFits();
[854]153 if (nbcols != 1)
154 {
155 throw IOExc("le fichier fits n'est pas une sphere Healpix");
156 }
157 // const DVList* dvl = &fn.DVListFromFits();
[1047]158 // DVList dvl=fn.DVListFromFits();
159 DVList dvl=DVListFromFits();
[873]160 // dvl.Print();
[1047]161 // nbentries = fn.NentriesFromFits(0);
162 nbentries = NentriesFromFits(0);
[854]163 int lastpix=dvl.GetI("LASTPIX");
164 if (lastpix>0)
165 {
166 cout << " lastpix trouve= " << lastpix << endl;
167 if (nbentries!=lastpix+1)
168 {
169 cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
170 nbentries=lastpix+1;
171 }
172 }
173 // Let's Read the SphereCoordSys object
174 int id= SphereCoordSys_NEUTRAL;
175 string description= "NEUTRAL SphereCoordSystem";
[985]176 string coordsys= dvl.GetS("COORDSYS");
177 // $CHECK$ - Reza 2/05/2000 - compare(size_t, size_t,...) passe pas sur g++
178 // if(coordsys.compare(0,7,"ROTATION",0,7) == 0) $CHECK$
179 if(coordsys.substr(0,8) == "ROTATION")
[854]180 {
181 id= SphereCoordSys_ROTATION;
182 description= "ROTATION SphereCoordSystem";
183 }
[985]184 // else if(coordsys.compare(0,4,"OTHER",0,4) == 0) $CHECK$ Reza 2/05/2000
185 else if(coordsys.substr(0,5) == "OTHER" )
[854]186 {
187 id= SphereCoordSys_OTHER;
188 description= "OTHER SphereCoordSystem";
189 }
190 dobj_->SetCoordSys(new SphereCoordSys(id,description));
191
[972]192 string ordering= dvl.GetS("ORDERING");
[985]193 // if(ordering.compare(0,3,"RING",0,3) != 0) $CHECK$ Reza 2/05/2000
194 if(ordering.substr(0,4) != "RING" )
[854]195 {
[985]196 cerr << "FITS_SphereHEALPix/Error Not supported ORDERING= "
197 << ordering << " substr(0,4)=[" << ordering.substr(0,4) << "]" << endl;
[854]198 throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
199 }
200
201 int nside= dvl.GetI("NSIDE");
202 if(nside <= 0)
203 throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
204 int nPix = 12*nside*nside;
205 if (nPix != nbentries)
206 {
[873]207 cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
[854]208 }
209 double Omega= 4.0*Pi/nPix;
210 dobj_->setParameters(nside,nPix,Omega);
211 // On lit les DataBlocks;
212 dobj_->pixels_.ReSize(nPix);
[1047]213 // fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
214 GetSingleColumn(dobj_->pixels_.Data(),nPix);
[854]215
216 // on effectue le decoupage en tranches
217 dobj_->SetThetaSlices();
[1047]218 // dobj_->Info()=fn.DVListFromFits();
219 dobj_->Info()=DVListFromFits();
[854]220
221
222}
223
224
225#ifdef __CXX_PRAGMA_TEMPLATES__
226#pragma define_template FITS_SphereHEALPix<r_8>
227#pragma define_template FITS_SphereHEALPix<r_4>
228#endif
229#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
230template class FITS_SphereHEALPix<r_8>;
231template class FITS_SphereHEALPix<r_4>;
232#endif
Note: See TracBrowser for help on using the repository browser.