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