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

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

normalisation des DVList

File size: 5.4 KB
Line 
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 Read(inputfile,hdunum);
27 // dobj_->SetTemp(true);
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>
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
70
71template <class T>
72void FITS_SphereHEALPix<T>::WriteToFits(FitsOutFile& os)
73{
74 if(dobj_ == NULL)
75 {
76 cout << " WriteToFits:: dobj_= null " << endl;
77 return;
78 }
79
80 DVList dvl( dobj_->Info() );
81
82 SphereCoordSys* cs= dobj_->GetCoordSys();
83 string description= cs->description();
84 dvl["COORDSYS"]= description;
85
86 dvl["PIXTYPE"] = "HEALPIX";
87 dvl.SetComment("PIXTYPE", "HEALPIX Pixelization");
88 dvl["ORDERING"]= dobj_->TypeOfMap();
89 dvl.SetComment("ORDERING", "Pixel ordering scheme, either RING or NESTED");
90
91 int nSide= dobj_->SizeIndex();
92 dvl["NSIDE"]= (int_4) nSide;
93 dvl.SetComment("NSIDE","Resolution parameter for HEALPIX" );
94
95 int nPix= dobj_->NbPixels();
96 dvl["FIRSTPIX"]= (int_4) 0;
97 dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
98 dvl["LASTPIX"]= (int_4) nPix-1;
99 dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
100 dvl["Content"]= "SphereHEALPix";
101
102 // On ecrit les dataBlocks
103 char** Noms = new char*[1];
104 Noms[0]= new char[15];
105 strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
106 char extname[15] = "SIMULATION";
107
108 char Type[2];
109 if (typeid(T) == typeid(r_8) ) Type[0]='D';
110 else
111 if (typeid(T) == typeid(r_4) ) Type[0]='E';
112 else
113 {
114 cout << " type de la sphere= " << typeid(T).name() << endl;
115 throw IOExc("FITS_SphereHEALPix:: unknown type");
116 }
117 Type[1]='\0';
118 vector<int> dummy;
119 os.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
120 delete [] Noms[0];
121 delete [] Noms;
122 os.putColToFits(0, nPix, dobj_->pixels_.Data());
123}
124
125template <class T>
126void FITS_SphereHEALPix<T>::ReadFromFits(FitsInFile& is)
127{
128 if(dobj_ == NULL)
129 {
130 dobj_= new SphereHEALPix<T>;
131 ownobj_= true;
132 }
133
134
135 int nbcols, nbentries;
136 nbcols = is.NbColsFromFits();
137 if (nbcols != 1)
138 {
139 throw IOExc("le fichier fits n'est pas une sphere Healpix");
140 }
141 DVList dvl=is.DVListFromFits();
142 nbentries = is.NentriesFromFits(0);
143 int lastpix=dvl.GetI("LASTPIX");
144 if (lastpix>0)
145 {
146 cout << " lastpix trouve= " << lastpix << endl;
147 if (nbentries!=lastpix+1)
148 {
149 cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
150 nbentries=lastpix+1;
151 }
152 }
153 // Let's Read the SphereCoordSys object
154 int id= SphereCoordSys_NEUTRAL;
155 string description= "NEUTRAL SphereCoordSystem";
156 string coordsys= dvl.GetS("COORDSYS");
157 // $CHECK$ - Reza 2/05/2000 - compare(size_t, size_t,...) passe pas sur g++
158 // if(coordsys.compare(0,7,"ROTATION",0,7) == 0) $CHECK$
159 if(coordsys.substr(0,8) == "ROTATION")
160 {
161 id= SphereCoordSys_ROTATION;
162 description= "ROTATION SphereCoordSystem";
163 }
164 // else if(coordsys.compare(0,4,"OTHER",0,4) == 0) $CHECK$ Reza 2/05/2000
165 else if(coordsys.substr(0,5) == "OTHER" )
166 {
167 id= SphereCoordSys_OTHER;
168 description= "OTHER SphereCoordSystem";
169 }
170 dobj_->SetCoordSys(new SphereCoordSys(id,description));
171
172 string ordering= dvl.GetS("ORDERING");
173 // if(ordering.compare(0,3,"RING",0,3) != 0) $CHECK$ Reza 2/05/2000
174 if(ordering.substr(0,4) != "RING" )
175 {
176 cerr << "FITS_SphereHEALPix/Error Not supported ORDERING= "
177 << ordering << " substr(0,4)=[" << ordering.substr(0,4) << "]" << endl;
178 throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
179 }
180
181 int nside= dvl.GetI("NSIDE");
182 if(nside <= 0)
183 throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
184 int nPix = 12*nside*nside;
185 if (nPix != nbentries)
186 {
187 cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
188 }
189 double Omega= 4.0*Pi/nPix;
190 dobj_->setParameters(nside,nPix,Omega);
191 // On lit les DataBlocks;
192 dobj_->pixels_.ReSize(nPix);
193 is.GetSingleColumn(dobj_->pixels_.Data(),nPix);
194
195 // on effectue le decoupage en tranches
196 dobj_->SetThetaSlices();
197 dobj_->Info() = is.DVListFromFits();
198
199
200}
201
202
203#ifdef __CXX_PRAGMA_TEMPLATES__
204#pragma define_template FITS_SphereHEALPix<r_8>
205#pragma define_template FITS_SphereHEALPix<r_4>
206#endif
207#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
208template class FITS_SphereHEALPix<r_8>;
209template class FITS_SphereHEALPix<r_4>;
210#endif
Note: See TracBrowser for help on using the repository browser.