| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [1181] | 2 | #include "machdefs.h" | 
|---|
|  | 3 | #include "fitslocalmap.h" | 
|---|
|  | 4 | /////////////////////////////////////////////////////////// | 
|---|
|  | 5 | //   Les objets delegues pour la gestion de persistance sur fichiers fits | 
|---|
|  | 6 | //    pout LocalMap | 
|---|
|  | 7 | /////////////////////////////////////////////////////////// | 
|---|
| [2013] | 8 |  | 
|---|
| [1371] | 9 | /*! | 
|---|
|  | 10 | \class SOPHYA::FITS_LocalMap | 
|---|
|  | 11 | \ingroup FitsIOServer | 
|---|
|  | 12 | FITS format I/O handler for SOPHYA::LocalMap objects. | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [1181] | 15 | using namespace SOPHYA; | 
|---|
|  | 16 |  | 
|---|
|  | 17 | template <class T> | 
|---|
|  | 18 | FITS_LocalMap<T>::FITS_LocalMap() | 
|---|
|  | 19 | { | 
|---|
|  | 20 | dobj_= NULL; | 
|---|
|  | 21 | ownobj_=false; | 
|---|
|  | 22 | } | 
|---|
|  | 23 |  | 
|---|
|  | 24 | template <class T> | 
|---|
|  | 25 | FITS_LocalMap<T>::FITS_LocalMap(char inputfile[],int hdunum) | 
|---|
|  | 26 | { | 
|---|
|  | 27 | dobj_=NULL; | 
|---|
|  | 28 | ownobj_=false; | 
|---|
|  | 29 | Read(inputfile,hdunum); | 
|---|
|  | 30 | } | 
|---|
|  | 31 |  | 
|---|
|  | 32 | template <class T> | 
|---|
|  | 33 | FITS_LocalMap<T>::FITS_LocalMap(const LocalMap<T> & obj) | 
|---|
|  | 34 | { | 
|---|
|  | 35 | dobj_ = new LocalMap<T>(obj); | 
|---|
|  | 36 | ownobj_=true; | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | template <class T> | 
|---|
|  | 40 | FITS_LocalMap<T>::FITS_LocalMap(LocalMap<T> *obj) | 
|---|
|  | 41 | { | 
|---|
|  | 42 | dobj_ = obj; | 
|---|
|  | 43 | ownobj_=false; | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 |  | 
|---|
|  | 47 | template <class T> | 
|---|
|  | 48 | FITS_LocalMap<T>::~FITS_LocalMap() | 
|---|
|  | 49 | { | 
|---|
|  | 50 | if (ownobj_ && dobj_) delete dobj_; | 
|---|
|  | 51 | } | 
|---|
|  | 52 |  | 
|---|
|  | 53 |  | 
|---|
|  | 54 | template <class T> | 
|---|
|  | 55 | AnyDataObj* FITS_LocalMap<T>::DataObj() | 
|---|
|  | 56 | { | 
|---|
|  | 57 | return(dobj_); | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
|  | 60 |  | 
|---|
|  | 61 | template <class T> | 
|---|
|  | 62 | void   FITS_LocalMap<T>::SetDataObj(AnyDataObj & o) | 
|---|
|  | 63 | { | 
|---|
|  | 64 | LocalMap<T>* po = dynamic_cast<  LocalMap<T>* >(& o); | 
|---|
|  | 65 | if (po == NULL) return; | 
|---|
|  | 66 | if (ownobj_ && dobj_) delete dobj_; | 
|---|
|  | 67 | dobj_ = po; | 
|---|
|  | 68 | ownobj_ = false; | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | template <class T> | 
|---|
| [2897] | 72 | int FITS_LocalMap<T>::CheckHandling(AnyDataObj & o) | 
|---|
|  | 73 | { | 
|---|
|  | 74 | if ( typeid(o) == typeid( LocalMap< T > ) ) return 2; | 
|---|
|  | 75 | LocalMap<T> * po = dynamic_cast< LocalMap<T> * >(&o); | 
|---|
|  | 76 | if (po == NULL) return 0; | 
|---|
|  | 77 | else return 1; | 
|---|
|  | 78 | } | 
|---|
|  | 79 |  | 
|---|
|  | 80 | template <class T> | 
|---|
|  | 81 | int FITS_LocalMap<T>::CheckReadability(FitsInOutFile& is) | 
|---|
|  | 82 | { | 
|---|
| [3047] | 83 | if (is.CurrentHDUType() !=  IMAGE_HDU ) return 0; | 
|---|
| [2897] | 84 | string key; | 
|---|
|  | 85 | key = "Content"; | 
|---|
|  | 86 | string clsnm = is.KeyValue(key); | 
|---|
|  | 87 | if (clsnm != "LocalMap") return 0; | 
|---|
| [3047] | 88 |  | 
|---|
| [3167] | 89 | LONGLONG naxes[2]; | 
|---|
| [3047] | 90 | int naxis=2; | 
|---|
|  | 91 | int imgtyp = is.GetImageHDUInfo(naxis, naxes); | 
|---|
|  | 92 | if (naxis != 2) return 0; | 
|---|
| [2897] | 93 |  | 
|---|
| [2898] | 94 | T x = 0; | 
|---|
| [3047] | 95 | if (imgtyp == FitsTypes::ImageType(x)) return 2 ; | 
|---|
| [2897] | 96 | else return 1; | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | template <class T> | 
|---|
|  | 100 | FitsHandlerInterface* FITS_LocalMap<T>::Clone() | 
|---|
|  | 101 | { | 
|---|
|  | 102 | return new FITS_LocalMap<T>() ; | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | template <class T> | 
|---|
| [1181] | 106 | void FITS_LocalMap<T>::ReadFromFits(FitsInFile& is) | 
|---|
|  | 107 | { | 
|---|
|  | 108 | if(dobj_ == NULL) | 
|---|
|  | 109 | { | 
|---|
|  | 110 | dobj_= new LocalMap<T>; | 
|---|
|  | 111 | ownobj_= true; | 
|---|
|  | 112 | } | 
|---|
| [2197] | 113 | int nbentries; | 
|---|
|  | 114 |  | 
|---|
|  | 115 | // lecture sur bin-table | 
|---|
|  | 116 | // | 
|---|
|  | 117 | //  if (!is.IsFitsTable()) | 
|---|
|  | 118 | // { | 
|---|
|  | 119 | //     throw PException("ReadFromFits: the fits file seems not to be a bintable"); | 
|---|
|  | 120 | //  } | 
|---|
|  | 121 | // int nbcols; | 
|---|
|  | 122 | // nbcols = is.NbColsFromFits(); | 
|---|
|  | 123 | // if (nbcols != 1) | 
|---|
|  | 124 | //  { | 
|---|
|  | 125 | //    throw IOExc("le fichier fits n'est pas une LocalMap"); | 
|---|
|  | 126 | //  } | 
|---|
|  | 127 | // nbentries = is.NentriesFromFits(0); | 
|---|
|  | 128 | // | 
|---|
|  | 129 |  | 
|---|
|  | 130 | // lecture sur image fits | 
|---|
|  | 131 | // | 
|---|
|  | 132 | if (!is.IsFitsImage()) | 
|---|
| [3047] | 133 | throw PException("ReadFromFits: the fits file seems not to be an image"); | 
|---|
| [2197] | 134 | int dimension = is.nbDimOfImage(); | 
|---|
|  | 135 | if (dimension != 2 ) | 
|---|
| [3047] | 136 | cout << " WARNING::ReadFromFits: the fits image seems not to be a matrix" << endl; | 
|---|
|  | 137 |  | 
|---|
| [2197] | 138 | nbentries =  is.nbOfImageData(); | 
|---|
|  | 139 | // | 
|---|
|  | 140 |  | 
|---|
| [1181] | 141 | DVList dvl=is.DVListFromFits(); | 
|---|
| [2197] | 142 |  | 
|---|
| [1181] | 143 | int_4 nSzX = dvl.GetI("NSZX"); | 
|---|
|  | 144 | int_4 nSzY = dvl.GetI("NSZY"); | 
|---|
|  | 145 | int_4 nPix = dvl.GetI("NPIX"); | 
|---|
|  | 146 | if (nPix != nbentries) | 
|---|
| [3047] | 147 | throw IOExc("longueur datablock incompatible avec nPix"); | 
|---|
| [1181] | 148 | dobj_->ReSize(nSzX, nSzY); | 
|---|
| [2197] | 149 | int_4 localMappingDone = dvl.GetI("LCMP"); | 
|---|
|  | 150 | if (localMappingDone) | 
|---|
|  | 151 | { | 
|---|
| [1181] | 152 | int_4 x0 = dvl.GetI("X0"); | 
|---|
|  | 153 | int_4 y0 = dvl.GetI("Y0"); | 
|---|
|  | 154 | double theta = dvl.GetD("THETA"); | 
|---|
|  | 155 | double phi   = dvl.GetD("PHI"); | 
|---|
|  | 156 | double angle = dvl.GetD("ANGLE"); | 
|---|
|  | 157 | dobj_->SetOrigin(theta, phi, x0, y0, angle); | 
|---|
|  | 158 | double angleX = dvl.GetD("ANGLEX"); | 
|---|
|  | 159 | double angleY = dvl.GetD("ANGLEY"); | 
|---|
|  | 160 | dobj_->SetSize(angleX, angleY); | 
|---|
| [2197] | 161 | } | 
|---|
| [1181] | 162 | // On lit les DataBlocks; | 
|---|
| [2197] | 163 |  | 
|---|
| [1181] | 164 | dobj_->DataBlock().ReSize(nPix); | 
|---|
|  | 165 | is.GetSingleColumn(dobj_->DataBlock().Data(),nPix); | 
|---|
|  | 166 |  | 
|---|
|  | 167 | // dvlist de LocalMap | 
|---|
|  | 168 | dobj_->Info()  = is.DVListFromFits(); | 
|---|
|  | 169 | } | 
|---|
|  | 170 |  | 
|---|
|  | 171 | template <class T> | 
|---|
|  | 172 | void FITS_LocalMap<T>::WriteToFits(FitsOutFile& os) | 
|---|
|  | 173 | { | 
|---|
|  | 174 | if(dobj_ == NULL) | 
|---|
|  | 175 | { | 
|---|
|  | 176 | cout << " WriteToFits:: dobj_= null " << endl; | 
|---|
|  | 177 | return; | 
|---|
|  | 178 | } | 
|---|
| [2197] | 179 | int nx, ny; | 
|---|
| [1181] | 180 |  | 
|---|
| [2197] | 181 | DVList dvl( dobj_->Info() ); | 
|---|
|  | 182 | nx = dobj_->Size_x(); | 
|---|
|  | 183 | dvl["NSZX"] = nx; | 
|---|
| [1181] | 184 | dvl.SetComment("NSZX", "number of pixels in x direction"); | 
|---|
| [2197] | 185 | ny = dobj_->Size_y(); | 
|---|
|  | 186 | dvl["NSZY"] = ny; | 
|---|
| [1181] | 187 | dvl.SetComment("NSZY", "number of pixels in y direction"); | 
|---|
|  | 188 | dvl["NPIX"] = dobj_->NbPixels(); | 
|---|
|  | 189 | dvl.SetComment("NPIX", "number of pixels in local map"); | 
|---|
|  | 190 |  | 
|---|
| [2197] | 191 | if(dobj_->LocalMap_isDone()) | 
|---|
|  | 192 | { | 
|---|
|  | 193 | dvl["LCMP"] = (int_4) 1; | 
|---|
|  | 194 | dvl.SetComment("LCMP", "local mapping 1= done, 0= not done"); | 
|---|
| [1181] | 195 | int_4 x0 = 0; | 
|---|
|  | 196 | int_4 y0 = 0; | 
|---|
|  | 197 | double theta = 0.; | 
|---|
|  | 198 | double  phi = 0.; | 
|---|
|  | 199 | double  angle = 0.; | 
|---|
|  | 200 | dobj_->Origin(theta, phi, x0, y0, angle); | 
|---|
|  | 201 | dvl["X0"]     = x0; | 
|---|
|  | 202 | dvl.SetComment("X0", "number of pixel of the origin, x direction"); | 
|---|
|  | 203 | dvl["Y0"]     = y0; | 
|---|
|  | 204 | dvl.SetComment("Y0", "number of pixel of the origin, y direction"); | 
|---|
|  | 205 | dvl["THETA"]  = theta; | 
|---|
|  | 206 | dvl.SetComment("THETA", "theta position of the map-origin"); | 
|---|
|  | 207 | dvl["PHI"]    = phi; | 
|---|
|  | 208 | dvl.SetComment("PHI", "phi position of the map origin"); | 
|---|
|  | 209 | dvl["ANGLE"]  = angle; | 
|---|
|  | 210 | dvl.SetComment("ANGLE", "angle between max x axis and sphere phi-axis"); | 
|---|
|  | 211 |  | 
|---|
|  | 212 | double angleX =0.; | 
|---|
|  | 213 | double angleY = 0.; | 
|---|
|  | 214 | dobj_->Aperture(angleX, angleY); | 
|---|
|  | 215 | dvl["ANGLEX"] = angleX; | 
|---|
|  | 216 | dvl.SetComment("ANGLEX", "sphere angle covered by map x-extension "); | 
|---|
|  | 217 | dvl["ANGLEY"] = angleY; | 
|---|
|  | 218 | dvl.SetComment("ANGLEY", "sphere angle covered by map y-extension "); | 
|---|
| [2197] | 219 | } | 
|---|
|  | 220 | else | 
|---|
|  | 221 | { | 
|---|
|  | 222 | dvl["LCMP"] = (int_4) 0; | 
|---|
|  | 223 | } | 
|---|
| [1181] | 224 | dvl["Content"]= "LocalMap"; | 
|---|
| [1300] | 225 | dvl.SetComment("Content", "name of SOPHYA object"); | 
|---|
| [2897] | 226 | dvl["SOPCLSNM"]= "SOPHYA::LocalMap<T>"; | 
|---|
|  | 227 | dvl.SetComment("SOPCLSNM", "SOPHYA class name"); | 
|---|
| [1181] | 228 | // On ecrit les dataBlocks | 
|---|
| [1194] | 229 | vector<string> Noms; | 
|---|
|  | 230 | Noms.push_back(dvl.GetS("Content")); | 
|---|
| [2897] | 231 | //  string extname("SIMULATION"); | 
|---|
|  | 232 | string extname = os.NextExtensionName(); | 
|---|
| [1181] | 233 |  | 
|---|
| [2197] | 234 | // sortie sur image fits | 
|---|
|  | 235 | // | 
|---|
|  | 236 | char type; | 
|---|
|  | 237 | if ( typeid(T) == typeid(r_8) ) type='D'; | 
|---|
| [1181] | 238 | else | 
|---|
| [2197] | 239 | if ( typeid(T) == typeid(r_4) )  type='E'; | 
|---|
| [1181] | 240 | else | 
|---|
| [2197] | 241 | if ( typeid(T) == typeid(int_4) )  type='J'; | 
|---|
|  | 242 | else | 
|---|
|  | 243 | { | 
|---|
|  | 244 | cout <<  " type du tableau= " <<  typeid(T).name() << endl; | 
|---|
|  | 245 | throw IOExc("FITS_LocalMap:: unknown type"); | 
|---|
|  | 246 | } | 
|---|
|  | 247 | int nbdim = 2; | 
|---|
|  | 248 | int* naxisn = new int[nbdim]; | 
|---|
|  | 249 | naxisn[0] = dobj_->Matrix().Size(0); | 
|---|
|  | 250 | naxisn[1] = dobj_->Matrix().Size(1); | 
|---|
|  | 251 | os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl); | 
|---|
|  | 252 | os.PutImageToFits(nx*ny, dobj_->Matrix().Data()); | 
|---|
| [1181] | 253 |  | 
|---|
| [2197] | 254 | delete [] naxisn; | 
|---|
|  | 255 | // | 
|---|
|  | 256 |  | 
|---|
|  | 257 | // sortie sur bin-table fits | 
|---|
|  | 258 | // | 
|---|
|  | 259 | //  string Type; | 
|---|
|  | 260 | //  if (typeid(T) == typeid(r_8) ) Type+='D'; | 
|---|
|  | 261 | //  else | 
|---|
|  | 262 | //   if (typeid(T) == typeid(r_4) )  Type+='E'; | 
|---|
|  | 263 | //   else | 
|---|
|  | 264 | //    { | 
|---|
|  | 265 | //    cout <<  " type de la LocalMap = " <<  typeid(T).name() << endl; | 
|---|
|  | 266 | //    throw IOExc("FITS_LocalMap:: unknown type"); | 
|---|
|  | 267 | //    } | 
|---|
|  | 268 | //  vector<int> dummy; | 
|---|
|  | 269 | //  os.makeHeaderBntblOnFits(Type, Noms, dobj_->NbPixels(), 1, &dvl, extname, dummy); | 
|---|
|  | 270 | //  os.PutColToFits(0,  dobj_->NbPixels(), dobj_->DataBlock().Data()); | 
|---|
|  | 271 | // | 
|---|
|  | 272 |  | 
|---|
| [1181] | 273 | } | 
|---|
|  | 274 |  | 
|---|
|  | 275 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 276 | #pragma define_template FITS_LocalMap<r_8> | 
|---|
|  | 277 | #pragma define_template FITS_LocalMap<r_4> | 
|---|
| [1300] | 278 | #pragma define_template FITS_LocalMap<int_4> | 
|---|
| [1181] | 279 | #endif | 
|---|
|  | 280 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| [2874] | 281 | namespace SOPHYA { | 
|---|
| [1181] | 282 | template class FITS_LocalMap<r_8>; | 
|---|
|  | 283 | template class FITS_LocalMap<r_4>; | 
|---|
| [1300] | 284 | template class FITS_LocalMap<int_4>; | 
|---|
| [2874] | 285 | } | 
|---|
| [1181] | 286 | #endif | 
|---|