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 | dobj_->SetTemp(true);
|
---|
25 | ownobj= true;
|
---|
26 |
|
---|
27 | ReadF(inputfile,hdunum);
|
---|
28 | }
|
---|
29 |
|
---|
30 | template <class T>
|
---|
31 | void FITS_SphereHEALPix<T>::Write(char outputfile[],int hdunum)
|
---|
32 | {
|
---|
33 | WriteF(outputfile, hdunum);
|
---|
34 | }
|
---|
35 |
|
---|
36 | template <class T>
|
---|
37 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(const SphereHEALPix<T>& obj)
|
---|
38 | {
|
---|
39 | dobj_= new SphereHEALPix<T>(obj, true);
|
---|
40 | dobj_->SetTemp(true);
|
---|
41 | ownobj= true;
|
---|
42 | }
|
---|
43 |
|
---|
44 | template <class T>
|
---|
45 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
|
---|
46 | {
|
---|
47 | dobj_= obj;
|
---|
48 | ownobj= false;
|
---|
49 | }
|
---|
50 |
|
---|
51 | template <class T>
|
---|
52 | FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
|
---|
53 | {
|
---|
54 | if (ownobj && dobj_) delete dobj_;
|
---|
55 | }
|
---|
56 |
|
---|
57 | template <class T>
|
---|
58 | AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
|
---|
59 | {
|
---|
60 | return(dobj_);
|
---|
61 | }
|
---|
62 |
|
---|
63 | template <class T>
|
---|
64 | void FITS_SphereHEALPix<T>::WriteToFits(const FitsFile& fn)
|
---|
65 | {
|
---|
66 | if(dobj_ == NULL)
|
---|
67 | {
|
---|
68 | cout << " WriteTo:: dobj_= null " << endl;
|
---|
69 | return;
|
---|
70 | }
|
---|
71 |
|
---|
72 | DVList dvl;
|
---|
73 |
|
---|
74 | SphereCoordSys* cs= dobj_->GetCoordSys();
|
---|
75 | string description= cs->description();
|
---|
76 | dvl["COORDSYS"]= description;
|
---|
77 |
|
---|
78 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
79 |
|
---|
80 | int nSide= dobj_->SizeIndex();
|
---|
81 | dvl["NSIDE"]= nSide;
|
---|
82 |
|
---|
83 | int nPix= dobj_->NbPixels();
|
---|
84 | dvl["FIRSTPIX"]= 0;
|
---|
85 | dvl["LASTPIX"]= nPix-1;
|
---|
86 | dvl["Content"]= "SphereHEALPix";
|
---|
87 | dvl["EXTNAME"]= "SIMULATION";
|
---|
88 | dvl["COMMENT"]= "Sky Map Pixelisation Specific Keywords";
|
---|
89 |
|
---|
90 | // On ecrit les dataBlocks
|
---|
91 | // fn.put_fits_bintab(dobj_->pixels_,dvl);
|
---|
92 | char** Noms = new char*[1];
|
---|
93 | Noms[0]= new char[15];
|
---|
94 | strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
|
---|
95 | char extname[15];
|
---|
96 | strncpy(extname,dvl.GetS("EXTNAME").c_str(),15);
|
---|
97 |
|
---|
98 | char Type[2];
|
---|
99 | if (typeid(T) == typeid(r_8) ) Type[0]='D';
|
---|
100 | else
|
---|
101 | if (typeid(T) == typeid(r_4) ) Type[0]='E';
|
---|
102 | else
|
---|
103 | {
|
---|
104 | cout << " type de la sphere= " << typeid(T).name() << endl;
|
---|
105 | throw IOExc("FITS_SphereHEALPix:: unknown type");
|
---|
106 | }
|
---|
107 | Type[1]='\0';
|
---|
108 | vector<int> dummy;
|
---|
109 | fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
|
---|
110 | delete [] Noms[0];
|
---|
111 | delete [] Noms;
|
---|
112 | putColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
113 | }
|
---|
114 |
|
---|
115 | template <class T>
|
---|
116 | void FITS_SphereHEALPix<T>::ReadFromFits(const FitsFile& fn)
|
---|
117 | {
|
---|
118 | if(dobj_ == NULL)
|
---|
119 | {
|
---|
120 | dobj_= new SphereHEALPix<T>;
|
---|
121 | dobj_->SetTemp(true);
|
---|
122 | ownobj= true;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | int nbcols, nbentries;
|
---|
127 | nbcols = fn.NbColsFromFits();
|
---|
128 | if (nbcols != 1)
|
---|
129 | {
|
---|
130 | throw IOExc("le fichier fits n'est pas une sphere Healpix");
|
---|
131 | }
|
---|
132 | // const DVList* dvl = &fn.DVListFromFits();
|
---|
133 | DVList dvl=fn.DVListFromFits();
|
---|
134 | // dvl.Print();
|
---|
135 | nbentries = fn.NentriesFromFits(0);
|
---|
136 | int lastpix=dvl.GetI("LASTPIX");
|
---|
137 | if (lastpix>0)
|
---|
138 | {
|
---|
139 | cout << " lastpix trouve= " << lastpix << endl;
|
---|
140 | if (nbentries!=lastpix+1)
|
---|
141 | {
|
---|
142 | cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
|
---|
143 | nbentries=lastpix+1;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | // Let's Read the SphereCoordSys object
|
---|
147 | int id= SphereCoordSys_NEUTRAL;
|
---|
148 | string description= "NEUTRAL SphereCoordSystem";
|
---|
149 | const char* coordsys= dvl.GetS("COORDSYS").c_str();
|
---|
150 | if(strncmp(coordsys,"ROTATION",8) == 0)
|
---|
151 | {
|
---|
152 | id= SphereCoordSys_ROTATION;
|
---|
153 | description= "ROTATION SphereCoordSystem";
|
---|
154 | }
|
---|
155 | else if(strncmp(coordsys,"OTHER",5) == 0)
|
---|
156 | {
|
---|
157 | id= SphereCoordSys_OTHER;
|
---|
158 | description= "OTHER SphereCoordSystem";
|
---|
159 | }
|
---|
160 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
161 |
|
---|
162 | const char* ordering= dvl.GetS("ORDERING").c_str();
|
---|
163 | if(strncmp(ordering,"RING",4) != 0)
|
---|
164 | {
|
---|
165 | cout << " ORDERING= " << ordering << endl;
|
---|
166 | throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
|
---|
167 | }
|
---|
168 |
|
---|
169 | int nside= dvl.GetI("NSIDE");
|
---|
170 | if(nside <= 0)
|
---|
171 | throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
|
---|
172 | int nPix = 12*nside*nside;
|
---|
173 | if (nPix != nbentries)
|
---|
174 | {
|
---|
175 | cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
|
---|
176 | }
|
---|
177 | double Omega= 4.0*Pi/nPix;
|
---|
178 | dobj_->setParameters(nside,nPix,Omega);
|
---|
179 | // On lit les DataBlocks;
|
---|
180 | dobj_->pixels_.ReSize(nPix);
|
---|
181 | fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
|
---|
182 |
|
---|
183 | // on effectue le decoupage en tranches
|
---|
184 | dobj_->SetThetaSlices();
|
---|
185 | dobj_->Info()=fn.DVListFromFits();
|
---|
186 |
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
192 | #pragma define_template FITS_SphereHEALPix<r_8>
|
---|
193 | #pragma define_template FITS_SphereHEALPix<r_4>
|
---|
194 | #endif
|
---|
195 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
196 | template class FITS_SphereHEALPix<r_8>;
|
---|
197 | template class FITS_SphereHEALPix<r_4>;
|
---|
198 | #endif
|
---|