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 |
|
---|
13 | template <class T>
|
---|
14 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix()
|
---|
15 | {
|
---|
16 | dobj_= new SphereHEALPix<T>;
|
---|
17 | ownobj= true;
|
---|
18 | }
|
---|
19 |
|
---|
20 | template <class T>
|
---|
21 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(char inputfile[],int hdunum)
|
---|
22 | {
|
---|
23 | dobj_= new SphereHEALPix<T>;
|
---|
24 | ownobj= true;
|
---|
25 |
|
---|
26 | ReadF(inputfile,hdunum);
|
---|
27 | dobj_->SetTemp(true);
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | template <class T>
|
---|
32 | FITS_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 |
|
---|
39 | template <class T>
|
---|
40 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
|
---|
41 | {
|
---|
42 | dobj_= obj;
|
---|
43 | ownobj= false;
|
---|
44 | }
|
---|
45 |
|
---|
46 | template <class T>
|
---|
47 | FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
|
---|
48 | {
|
---|
49 | if (ownobj && dobj_) delete dobj_;
|
---|
50 | }
|
---|
51 |
|
---|
52 | template <class T>
|
---|
53 | AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
|
---|
54 | {
|
---|
55 | return(dobj_);
|
---|
56 | }
|
---|
57 |
|
---|
58 | template <class T>
|
---|
59 | void 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 |
|
---|
70 | template <class T>
|
---|
71 | void FITS_SphereHEALPix<T>::Write(char outputfile[], bool OldFile)
|
---|
72 | {
|
---|
73 | WriteF(outputfile, OldFile);
|
---|
74 | }
|
---|
75 | template <class T>
|
---|
76 | void FITS_SphereHEALPix<T>::Read(char inputfile[],int hdunum)
|
---|
77 | {
|
---|
78 | ReadF(inputfile,hdunum);
|
---|
79 | }
|
---|
80 |
|
---|
81 | template <class T>
|
---|
82 | void FITS_SphereHEALPix<T>::WriteToFits(FitsFile& fn)
|
---|
83 | {
|
---|
84 | if(dobj_ == NULL)
|
---|
85 | {
|
---|
86 | cout << " WriteToFits:: dobj_= null " << endl;
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | DVList dvl;
|
---|
91 |
|
---|
92 | SphereCoordSys* cs= dobj_->GetCoordSys();
|
---|
93 | string description= cs->description();
|
---|
94 | dvl["COORDSYS"]= description;
|
---|
95 |
|
---|
96 | dvl["PIXTYPE"] = "HEALPIX";
|
---|
97 | dvl.SetComment("PIXTYPE", "HEALPIX Pixelization");
|
---|
98 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
99 | dvl.SetComment("ORDERING", "Pixel ordering scheme, either RING or NESTED");
|
---|
100 |
|
---|
101 | int nSide= dobj_->SizeIndex();
|
---|
102 | dvl["NSIDE"]= (int_4) nSide;
|
---|
103 | dvl.SetComment("NSIDE","Resolution parameter for HEALPIX" );
|
---|
104 |
|
---|
105 | int nPix= dobj_->NbPixels();
|
---|
106 | dvl["FIRSTPIX"]= (int_4) 0;
|
---|
107 | dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
|
---|
108 | dvl["LASTPIX"]= (int_4) nPix-1;
|
---|
109 | dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
|
---|
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];
|
---|
122 | if (typeid(T) == typeid(r_8) ) Type[0]='D';
|
---|
123 | else
|
---|
124 | if (typeid(T) == typeid(r_4) ) Type[0]='E';
|
---|
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;
|
---|
132 | fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
|
---|
133 | delete [] Noms[0];
|
---|
134 | delete [] Noms;
|
---|
135 | putColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
136 | }
|
---|
137 |
|
---|
138 | template <class T>
|
---|
139 | void FITS_SphereHEALPix<T>::ReadFromFits(FitsFile& fn)
|
---|
140 | {
|
---|
141 | if(dobj_ == NULL)
|
---|
142 | {
|
---|
143 | dobj_= new SphereHEALPix<T>;
|
---|
144 | dobj_->SetTemp(true);
|
---|
145 | ownobj= true;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | int nbcols, nbentries;
|
---|
150 | nbcols = fn.NbColsFromFits();
|
---|
151 | if (nbcols != 1)
|
---|
152 | {
|
---|
153 | throw IOExc("le fichier fits n'est pas une sphere Healpix");
|
---|
154 | }
|
---|
155 | // const DVList* dvl = &fn.DVListFromFits();
|
---|
156 | DVList dvl=fn.DVListFromFits();
|
---|
157 | // dvl.Print();
|
---|
158 | nbentries = fn.NentriesFromFits(0);
|
---|
159 | int lastpix=dvl.GetI("LASTPIX");
|
---|
160 | if (lastpix>0)
|
---|
161 | {
|
---|
162 | cout << " lastpix trouve= " << lastpix << endl;
|
---|
163 | if (nbentries!=lastpix+1)
|
---|
164 | {
|
---|
165 | cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
|
---|
166 | nbentries=lastpix+1;
|
---|
167 | }
|
---|
168 | }
|
---|
169 | // Let's Read the SphereCoordSys object
|
---|
170 | int id= SphereCoordSys_NEUTRAL;
|
---|
171 | string description= "NEUTRAL SphereCoordSystem";
|
---|
172 | string coordsys= dvl.GetS("COORDSYS");
|
---|
173 | // $CHECK$ - Reza 2/05/2000 - compare(size_t, size_t,...) passe pas sur g++
|
---|
174 | // if(coordsys.compare(0,7,"ROTATION",0,7) == 0) $CHECK$
|
---|
175 | if(coordsys.substr(0,8) == "ROTATION")
|
---|
176 | {
|
---|
177 | id= SphereCoordSys_ROTATION;
|
---|
178 | description= "ROTATION SphereCoordSystem";
|
---|
179 | }
|
---|
180 | // else if(coordsys.compare(0,4,"OTHER",0,4) == 0) $CHECK$ Reza 2/05/2000
|
---|
181 | else if(coordsys.substr(0,5) == "OTHER" )
|
---|
182 | {
|
---|
183 | id= SphereCoordSys_OTHER;
|
---|
184 | description= "OTHER SphereCoordSystem";
|
---|
185 | }
|
---|
186 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
187 |
|
---|
188 | string ordering= dvl.GetS("ORDERING");
|
---|
189 | // if(ordering.compare(0,3,"RING",0,3) != 0) $CHECK$ Reza 2/05/2000
|
---|
190 | if(ordering.substr(0,4) != "RING" )
|
---|
191 | {
|
---|
192 | cerr << "FITS_SphereHEALPix/Error Not supported ORDERING= "
|
---|
193 | << ordering << " substr(0,4)=[" << ordering.substr(0,4) << "]" << endl;
|
---|
194 | throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
|
---|
195 | }
|
---|
196 |
|
---|
197 | int nside= dvl.GetI("NSIDE");
|
---|
198 | if(nside <= 0)
|
---|
199 | throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
|
---|
200 | int nPix = 12*nside*nside;
|
---|
201 | if (nPix != nbentries)
|
---|
202 | {
|
---|
203 | cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
|
---|
204 | }
|
---|
205 | double Omega= 4.0*Pi/nPix;
|
---|
206 | dobj_->setParameters(nside,nPix,Omega);
|
---|
207 | // On lit les DataBlocks;
|
---|
208 | dobj_->pixels_.ReSize(nPix);
|
---|
209 | fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
|
---|
210 |
|
---|
211 | // on effectue le decoupage en tranches
|
---|
212 | dobj_->SetThetaSlices();
|
---|
213 | dobj_->Info()=fn.DVListFromFits();
|
---|
214 |
|
---|
215 |
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
220 | #pragma define_template FITS_SphereHEALPix<r_8>
|
---|
221 | #pragma define_template FITS_SphereHEALPix<r_4>
|
---|
222 | #endif
|
---|
223 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
224 | template class FITS_SphereHEALPix<r_8>;
|
---|
225 | template class FITS_SphereHEALPix<r_4>;
|
---|
226 | #endif
|
---|