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

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

hdunum=0 par defaut

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