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

Last change on this file since 863 was 854, checked in by ansari, 25 years ago

Adaptation s SphereHEALPix et deplacement SkyMap/fitsspherehealpix ici

Reza 10/4/2000

File size: 5.2 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 dobj_->SetTemp(true);
25 ownobj= true;
26
27 ReadF(inputfile,hdunum);
28}
29
30template <class T>
31void FITS_SphereHEALPix<T>::Write(char outputfile[],int hdunum)
32{
33 WriteF(outputfile, hdunum);
34}
35
36template <class T>
37FITS_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
44template <class T>
45FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
46{
47 dobj_= obj;
48 ownobj= false;
49}
50
51template <class T>
52FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
53{
54 if (ownobj && dobj_) delete dobj_;
55}
56
57template <class T>
58AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
59{
60 return(dobj_);
61}
62
63template <class T>
64void 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 cout << " nom entre dans sphereHealpix: " << Noms[0] << endl;
99 char Type[2];
100 if (strncmp( typeid(T).name(),"r_8",3)==0 || strncmp( typeid(T).name(),"double",6)==0 ) Type[0]='D';
101 else
102 if (strncmp( typeid(T).name(),"r_4",3)==0 || strncmp( typeid(T).name(),"float",5)==0 ) Type[0]='E';
103 else
104 {
105 cout << " type de la sphere= " << typeid(T).name() << endl;
106 throw IOExc("FITS_SphereHEALPix:: unknown type");
107 }
108 Type[1]='\0';
109 vector<int> dummy;
110 fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
111 delete [] Noms[0];
112 delete [] Noms;
113 putColToFits(0, nPix, dobj_->pixels_.Data());
114}
115
116template <class T>
117void FITS_SphereHEALPix<T>::ReadFromFits(const FitsFile& fn)
118{
119 if(dobj_ == NULL)
120 {
121 dobj_= new SphereHEALPix<T>;
122 dobj_->SetTemp(true);
123 ownobj= true;
124 }
125
126
127 int nbcols, nbentries;
128 nbcols = fn.NbColsFromFits();
129 if (nbcols != 1)
130 {
131 throw IOExc("le fichier fits n'est pas une sphere Healpix");
132 }
133 // const DVList* dvl = &fn.DVListFromFits();
134 DVList dvl=fn.DVListFromFits();
135 dvl.Print();
136 nbentries = fn.NentriesFromFits(0);
137 int lastpix=dvl.GetI("LASTPIX");
138 if (lastpix>0)
139 {
140 cout << " lastpix trouve= " << lastpix << endl;
141 if (nbentries!=lastpix+1)
142 {
143 cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
144 nbentries=lastpix+1;
145 }
146 }
147 // Let's Read the SphereCoordSys object
148 int id= SphereCoordSys_NEUTRAL;
149 string description= "NEUTRAL SphereCoordSystem";
150 const char* coordsys= dvl.GetS("COORDSYS").c_str();
151 if(strncmp(coordsys,"ROTATION",8) == 0)
152 {
153 id= SphereCoordSys_ROTATION;
154 description= "ROTATION SphereCoordSystem";
155 }
156 else if(strncmp(coordsys,"OTHER",5) == 0)
157 {
158 id= SphereCoordSys_OTHER;
159 description= "OTHER SphereCoordSystem";
160 }
161 dobj_->SetCoordSys(new SphereCoordSys(id,description));
162
163 const char* ordering= dvl.GetS("ORDERING").c_str();
164 if(strncmp(ordering,"RING",4) != 0)
165 {
166 cout << " ORDERING= " << ordering << endl;
167 throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
168 }
169
170 int nside= dvl.GetI("NSIDE");
171 if(nside <= 0)
172 throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
173 int nPix = 12*nside*nside;
174 if (nPix != nbentries)
175 {
176 cout << " le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
177 }
178 double Omega= 4.0*Pi/nPix;
179 dobj_->setParameters(nside,nPix,Omega);
180 cout << " sphere Healpix : las parametres sont introduits" << endl;
181 // On lit les DataBlocks;
182 cout << "nside= " << nside << "nPix= " << nPix << endl;
183 dobj_->pixels_.ReSize(nPix);
184 cout << " sphere Healpix : resize fait" << endl;
185 fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
186
187 // on effectue le decoupage en tranches
188 dobj_->SetThetaSlices();
189 dobj_->Info()=fn.DVListFromFits();
190
191
192}
193
194
195#ifdef __CXX_PRAGMA_TEMPLATES__
196#pragma define_template FITS_SphereHEALPix<r_8>
197#pragma define_template FITS_SphereHEALPix<r_4>
198#endif
199#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
200template class FITS_SphereHEALPix<r_8>;
201template class FITS_SphereHEALPix<r_4>;
202#endif
Note: See TracBrowser for help on using the repository browser.