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