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

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

structuration a la ppersist+ convention sur hdu

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