[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 | {
|
---|
| 83 | if (is.CurrentHDUType() != BINARY_TBL ) return 0;
|
---|
| 84 | string key;
|
---|
| 85 | key = "Content";
|
---|
| 86 | string clsnm = is.KeyValue(key);
|
---|
| 87 | if (clsnm != "LocalMap") return 0;
|
---|
| 88 |
|
---|
| 89 | vector<string> colnames;
|
---|
| 90 | vector<int> coltypes;
|
---|
| 91 | vector<long> repcnt;
|
---|
| 92 | vector<long> width;
|
---|
| 93 | long ncols = is.GetColInfo(colnames, coltypes, repcnt, width);
|
---|
| 94 | if (ncols < 1) return 0;
|
---|
[2898] | 95 | T x = 0;
|
---|
[2897] | 96 | if (coltypes[0] == FitsTypes::DataType(x)) return 2 ;
|
---|
| 97 | else return 1;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | template <class T>
|
---|
| 101 | FitsHandlerInterface* FITS_LocalMap<T>::Clone()
|
---|
| 102 | {
|
---|
| 103 | return new FITS_LocalMap<T>() ;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | template <class T>
|
---|
[1181] | 107 | void FITS_LocalMap<T>::ReadFromFits(FitsInFile& is)
|
---|
| 108 | {
|
---|
| 109 | if(dobj_ == NULL)
|
---|
| 110 | {
|
---|
| 111 | dobj_= new LocalMap<T>;
|
---|
| 112 | ownobj_= true;
|
---|
| 113 | }
|
---|
[2197] | 114 | int nbentries;
|
---|
| 115 |
|
---|
| 116 | // lecture sur bin-table
|
---|
| 117 | //
|
---|
| 118 | // if (!is.IsFitsTable())
|
---|
| 119 | // {
|
---|
| 120 | // throw PException("ReadFromFits: the fits file seems not to be a bintable");
|
---|
| 121 | // }
|
---|
| 122 | // int nbcols;
|
---|
| 123 | // nbcols = is.NbColsFromFits();
|
---|
| 124 | // if (nbcols != 1)
|
---|
| 125 | // {
|
---|
| 126 | // throw IOExc("le fichier fits n'est pas une LocalMap");
|
---|
| 127 | // }
|
---|
| 128 | // nbentries = is.NentriesFromFits(0);
|
---|
| 129 | //
|
---|
| 130 |
|
---|
| 131 | // lecture sur image fits
|
---|
| 132 | //
|
---|
| 133 | if (!is.IsFitsImage())
|
---|
[1181] | 134 | {
|
---|
[2197] | 135 | throw PException("ReadFromFits: the fits file seems not to be an image");
|
---|
[1181] | 136 | }
|
---|
[2197] | 137 | int dimension = is.nbDimOfImage();
|
---|
| 138 | if (dimension != 2 )
|
---|
| 139 | {
|
---|
| 140 | cout << " WARNING::ReadFromFits: the fits image seems not to be a matrix" << endl;
|
---|
| 141 | }
|
---|
| 142 | nbentries = is.nbOfImageData();
|
---|
| 143 | //
|
---|
| 144 |
|
---|
[1181] | 145 | DVList dvl=is.DVListFromFits();
|
---|
[2197] | 146 |
|
---|
[1181] | 147 | int_4 nSzX = dvl.GetI("NSZX");
|
---|
| 148 | int_4 nSzY = dvl.GetI("NSZY");
|
---|
| 149 | int_4 nPix = dvl.GetI("NPIX");
|
---|
| 150 | if (nPix != nbentries)
|
---|
| 151 | {
|
---|
| 152 | throw IOExc("longueur datablock incompatible avec nPix");
|
---|
| 153 | }
|
---|
| 154 | dobj_->ReSize(nSzX, nSzY);
|
---|
[2197] | 155 | int_4 localMappingDone = dvl.GetI("LCMP");
|
---|
| 156 | if (localMappingDone)
|
---|
| 157 | {
|
---|
[1181] | 158 | int_4 x0 = dvl.GetI("X0");
|
---|
| 159 | int_4 y0 = dvl.GetI("Y0");
|
---|
| 160 | double theta = dvl.GetD("THETA");
|
---|
| 161 | double phi = dvl.GetD("PHI");
|
---|
| 162 | double angle = dvl.GetD("ANGLE");
|
---|
| 163 | dobj_->SetOrigin(theta, phi, x0, y0, angle);
|
---|
| 164 | double angleX = dvl.GetD("ANGLEX");
|
---|
| 165 | double angleY = dvl.GetD("ANGLEY");
|
---|
| 166 | dobj_->SetSize(angleX, angleY);
|
---|
[2197] | 167 | }
|
---|
[1181] | 168 | // On lit les DataBlocks;
|
---|
[2197] | 169 |
|
---|
[1181] | 170 | dobj_->DataBlock().ReSize(nPix);
|
---|
| 171 | is.GetSingleColumn(dobj_->DataBlock().Data(),nPix);
|
---|
| 172 |
|
---|
| 173 | // dvlist de LocalMap
|
---|
| 174 | dobj_->Info() = is.DVListFromFits();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | template <class T>
|
---|
| 178 | void FITS_LocalMap<T>::WriteToFits(FitsOutFile& os)
|
---|
| 179 | {
|
---|
| 180 | if(dobj_ == NULL)
|
---|
| 181 | {
|
---|
| 182 | cout << " WriteToFits:: dobj_= null " << endl;
|
---|
| 183 | return;
|
---|
| 184 | }
|
---|
[2197] | 185 | int nx, ny;
|
---|
[1181] | 186 |
|
---|
[2197] | 187 | DVList dvl( dobj_->Info() );
|
---|
| 188 | nx = dobj_->Size_x();
|
---|
| 189 | dvl["NSZX"] = nx;
|
---|
[1181] | 190 | dvl.SetComment("NSZX", "number of pixels in x direction");
|
---|
[2197] | 191 | ny = dobj_->Size_y();
|
---|
| 192 | dvl["NSZY"] = ny;
|
---|
[1181] | 193 | dvl.SetComment("NSZY", "number of pixels in y direction");
|
---|
| 194 | dvl["NPIX"] = dobj_->NbPixels();
|
---|
| 195 | dvl.SetComment("NPIX", "number of pixels in local map");
|
---|
| 196 |
|
---|
[2197] | 197 | if(dobj_->LocalMap_isDone())
|
---|
| 198 | {
|
---|
| 199 | dvl["LCMP"] = (int_4) 1;
|
---|
| 200 | dvl.SetComment("LCMP", "local mapping 1= done, 0= not done");
|
---|
[1181] | 201 | int_4 x0 = 0;
|
---|
| 202 | int_4 y0 = 0;
|
---|
| 203 | double theta = 0.;
|
---|
| 204 | double phi = 0.;
|
---|
| 205 | double angle = 0.;
|
---|
| 206 | dobj_->Origin(theta, phi, x0, y0, angle);
|
---|
| 207 | dvl["X0"] = x0;
|
---|
| 208 | dvl.SetComment("X0", "number of pixel of the origin, x direction");
|
---|
| 209 | dvl["Y0"] = y0;
|
---|
| 210 | dvl.SetComment("Y0", "number of pixel of the origin, y direction");
|
---|
| 211 | dvl["THETA"] = theta;
|
---|
| 212 | dvl.SetComment("THETA", "theta position of the map-origin");
|
---|
| 213 | dvl["PHI"] = phi;
|
---|
| 214 | dvl.SetComment("PHI", "phi position of the map origin");
|
---|
| 215 | dvl["ANGLE"] = angle;
|
---|
| 216 | dvl.SetComment("ANGLE", "angle between max x axis and sphere phi-axis");
|
---|
| 217 |
|
---|
| 218 | double angleX =0.;
|
---|
| 219 | double angleY = 0.;
|
---|
| 220 | dobj_->Aperture(angleX, angleY);
|
---|
| 221 | dvl["ANGLEX"] = angleX;
|
---|
| 222 | dvl.SetComment("ANGLEX", "sphere angle covered by map x-extension ");
|
---|
| 223 | dvl["ANGLEY"] = angleY;
|
---|
| 224 | dvl.SetComment("ANGLEY", "sphere angle covered by map y-extension ");
|
---|
[2197] | 225 | }
|
---|
| 226 | else
|
---|
| 227 | {
|
---|
| 228 | dvl["LCMP"] = (int_4) 0;
|
---|
| 229 | }
|
---|
[1181] | 230 | dvl["Content"]= "LocalMap";
|
---|
[1300] | 231 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
[2897] | 232 | dvl["SOPCLSNM"]= "SOPHYA::LocalMap<T>";
|
---|
| 233 | dvl.SetComment("SOPCLSNM", "SOPHYA class name");
|
---|
[1181] | 234 | // On ecrit les dataBlocks
|
---|
[1194] | 235 | vector<string> Noms;
|
---|
| 236 | Noms.push_back(dvl.GetS("Content"));
|
---|
[2897] | 237 | // string extname("SIMULATION");
|
---|
| 238 | string extname = os.NextExtensionName();
|
---|
[1181] | 239 |
|
---|
[2197] | 240 | // sortie sur image fits
|
---|
| 241 | //
|
---|
| 242 | char type;
|
---|
| 243 | if ( typeid(T) == typeid(r_8) ) type='D';
|
---|
[1181] | 244 | else
|
---|
[2197] | 245 | if ( typeid(T) == typeid(r_4) ) type='E';
|
---|
[1181] | 246 | else
|
---|
[2197] | 247 | if ( typeid(T) == typeid(int_4) ) type='J';
|
---|
| 248 | else
|
---|
| 249 | {
|
---|
| 250 | cout << " type du tableau= " << typeid(T).name() << endl;
|
---|
| 251 | throw IOExc("FITS_LocalMap:: unknown type");
|
---|
| 252 | }
|
---|
| 253 | int nbdim = 2;
|
---|
| 254 | int* naxisn = new int[nbdim];
|
---|
| 255 | naxisn[0] = dobj_->Matrix().Size(0);
|
---|
| 256 | naxisn[1] = dobj_->Matrix().Size(1);
|
---|
| 257 | os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
|
---|
| 258 | os.PutImageToFits(nx*ny, dobj_->Matrix().Data());
|
---|
[1181] | 259 |
|
---|
[2197] | 260 | delete [] naxisn;
|
---|
| 261 | //
|
---|
| 262 |
|
---|
| 263 | // sortie sur bin-table fits
|
---|
| 264 | //
|
---|
| 265 | // string Type;
|
---|
| 266 | // if (typeid(T) == typeid(r_8) ) Type+='D';
|
---|
| 267 | // else
|
---|
| 268 | // if (typeid(T) == typeid(r_4) ) Type+='E';
|
---|
| 269 | // else
|
---|
| 270 | // {
|
---|
| 271 | // cout << " type de la LocalMap = " << typeid(T).name() << endl;
|
---|
| 272 | // throw IOExc("FITS_LocalMap:: unknown type");
|
---|
| 273 | // }
|
---|
| 274 | // vector<int> dummy;
|
---|
| 275 | // os.makeHeaderBntblOnFits(Type, Noms, dobj_->NbPixels(), 1, &dvl, extname, dummy);
|
---|
| 276 | // os.PutColToFits(0, dobj_->NbPixels(), dobj_->DataBlock().Data());
|
---|
| 277 | //
|
---|
| 278 |
|
---|
[1181] | 279 | }
|
---|
| 280 |
|
---|
| 281 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 282 | #pragma define_template FITS_LocalMap<r_8>
|
---|
| 283 | #pragma define_template FITS_LocalMap<r_4>
|
---|
[1300] | 284 | #pragma define_template FITS_LocalMap<int_4>
|
---|
[1181] | 285 | #endif
|
---|
| 286 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2874] | 287 | namespace SOPHYA {
|
---|
[1181] | 288 | template class FITS_LocalMap<r_8>;
|
---|
| 289 | template class FITS_LocalMap<r_4>;
|
---|
[1300] | 290 | template class FITS_LocalMap<int_4>;
|
---|
[2874] | 291 | }
|
---|
[1181] | 292 | #endif
|
---|