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