[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>
|
---|
| 71 | void FITS_SphereHEALPix<T>::Write(char outputfile[],int hdunum)
|
---|
| 72 | {
|
---|
| 73 | WriteF(outputfile, hdunum);
|
---|
| 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>
|
---|
[854] | 82 | void FITS_SphereHEALPix<T>::WriteToFits(const FitsFile& fn)
|
---|
| 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 |
|
---|
| 96 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
| 97 |
|
---|
| 98 | int nSide= dobj_->SizeIndex();
|
---|
| 99 | dvl["NSIDE"]= nSide;
|
---|
| 100 |
|
---|
| 101 | int nPix= dobj_->NbPixels();
|
---|
| 102 | dvl["FIRSTPIX"]= 0;
|
---|
| 103 | dvl["LASTPIX"]= nPix-1;
|
---|
| 104 | dvl["Content"]= "SphereHEALPix";
|
---|
| 105 | dvl["EXTNAME"]= "SIMULATION";
|
---|
| 106 | dvl["COMMENT"]= "Sky Map Pixelisation Specific Keywords";
|
---|
| 107 |
|
---|
| 108 | // On ecrit les dataBlocks
|
---|
| 109 | char** Noms = new char*[1];
|
---|
| 110 | Noms[0]= new char[15];
|
---|
| 111 | strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
|
---|
| 112 | char extname[15];
|
---|
| 113 | strncpy(extname,dvl.GetS("EXTNAME").c_str(),15);
|
---|
| 114 |
|
---|
| 115 | char Type[2];
|
---|
[874] | 116 | if (typeid(T) == typeid(r_8) ) Type[0]='D';
|
---|
[854] | 117 | else
|
---|
[874] | 118 | if (typeid(T) == typeid(r_4) ) Type[0]='E';
|
---|
[854] | 119 | else
|
---|
| 120 | {
|
---|
| 121 | cout << " type de la sphere= " << typeid(T).name() << endl;
|
---|
| 122 | throw IOExc("FITS_SphereHEALPix:: unknown type");
|
---|
| 123 | }
|
---|
| 124 | Type[1]='\0';
|
---|
| 125 | vector<int> dummy;
|
---|
| 126 | fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
|
---|
| 127 | delete [] Noms[0];
|
---|
| 128 | delete [] Noms;
|
---|
| 129 | putColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | template <class T>
|
---|
| 133 | void FITS_SphereHEALPix<T>::ReadFromFits(const FitsFile& fn)
|
---|
| 134 | {
|
---|
| 135 | if(dobj_ == NULL)
|
---|
| 136 | {
|
---|
| 137 | dobj_= new SphereHEALPix<T>;
|
---|
| 138 | dobj_->SetTemp(true);
|
---|
| 139 | ownobj= true;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | int nbcols, nbentries;
|
---|
| 144 | nbcols = fn.NbColsFromFits();
|
---|
| 145 | if (nbcols != 1)
|
---|
| 146 | {
|
---|
| 147 | throw IOExc("le fichier fits n'est pas une sphere Healpix");
|
---|
| 148 | }
|
---|
| 149 | // const DVList* dvl = &fn.DVListFromFits();
|
---|
| 150 | DVList dvl=fn.DVListFromFits();
|
---|
[873] | 151 | // dvl.Print();
|
---|
[854] | 152 | nbentries = fn.NentriesFromFits(0);
|
---|
| 153 | int lastpix=dvl.GetI("LASTPIX");
|
---|
| 154 | if (lastpix>0)
|
---|
| 155 | {
|
---|
| 156 | cout << " lastpix trouve= " << lastpix << endl;
|
---|
| 157 | if (nbentries!=lastpix+1)
|
---|
| 158 | {
|
---|
| 159 | cout << " nb pixels from LASTPIX = " << lastpix+1 << endl;
|
---|
| 160 | nbentries=lastpix+1;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | // Let's Read the SphereCoordSys object
|
---|
| 164 | int id= SphereCoordSys_NEUTRAL;
|
---|
| 165 | string description= "NEUTRAL SphereCoordSystem";
|
---|
| 166 | const char* coordsys= dvl.GetS("COORDSYS").c_str();
|
---|
| 167 | if(strncmp(coordsys,"ROTATION",8) == 0)
|
---|
| 168 | {
|
---|
| 169 | id= SphereCoordSys_ROTATION;
|
---|
| 170 | description= "ROTATION SphereCoordSystem";
|
---|
| 171 | }
|
---|
| 172 | else if(strncmp(coordsys,"OTHER",5) == 0)
|
---|
| 173 | {
|
---|
| 174 | id= SphereCoordSys_OTHER;
|
---|
| 175 | description= "OTHER SphereCoordSystem";
|
---|
| 176 | }
|
---|
| 177 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
| 178 |
|
---|
| 179 | const char* ordering= dvl.GetS("ORDERING").c_str();
|
---|
| 180 | if(strncmp(ordering,"RING",4) != 0)
|
---|
| 181 | {
|
---|
| 182 | cout << " ORDERING= " << ordering << endl;
|
---|
| 183 | throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | int nside= dvl.GetI("NSIDE");
|
---|
| 187 | if(nside <= 0)
|
---|
| 188 | throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
|
---|
| 189 | int nPix = 12*nside*nside;
|
---|
| 190 | if (nPix != nbentries)
|
---|
| 191 | {
|
---|
[873] | 192 | cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
|
---|
[854] | 193 | }
|
---|
| 194 | double Omega= 4.0*Pi/nPix;
|
---|
| 195 | dobj_->setParameters(nside,nPix,Omega);
|
---|
| 196 | // On lit les DataBlocks;
|
---|
| 197 | dobj_->pixels_.ReSize(nPix);
|
---|
| 198 | fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
|
---|
| 199 |
|
---|
| 200 | // on effectue le decoupage en tranches
|
---|
| 201 | dobj_->SetThetaSlices();
|
---|
| 202 | dobj_->Info()=fn.DVListFromFits();
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 209 | #pragma define_template FITS_SphereHEALPix<r_8>
|
---|
| 210 | #pragma define_template FITS_SphereHEALPix<r_4>
|
---|
| 211 | #endif
|
---|
| 212 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 213 | template class FITS_SphereHEALPix<r_8>;
|
---|
| 214 | template class FITS_SphereHEALPix<r_4>;
|
---|
| 215 | #endif
|
---|