| [1181] | 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 | ///////////////////////////////////////////////////////////
 | 
|---|
| [2013] | 7 |  
 | 
|---|
| [1371] | 8 | /*!
 | 
|---|
 | 9 |   \class SOPHYA::FITS_LocalMap
 | 
|---|
 | 10 |   \ingroup FitsIOServer
 | 
|---|
 | 11 |   FITS format I/O handler for SOPHYA::LocalMap objects.
 | 
|---|
 | 12 | */
 | 
|---|
 | 13 | 
 | 
|---|
| [1181] | 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 nbcols, nbentries;
 | 
|---|
 | 79 |   nbcols = is.NbColsFromFits();
 | 
|---|
 | 80 |   if (nbcols != 1) 
 | 
|---|
 | 81 |     {
 | 
|---|
 | 82 |       throw IOExc("le fichier fits n'est pas une LocalMap");
 | 
|---|
 | 83 |     }
 | 
|---|
 | 84 |   DVList dvl=is.DVListFromFits();
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |   nbentries = is.NentriesFromFits(0);
 | 
|---|
 | 87 |   int_4 nSzX = dvl.GetI("NSZX");
 | 
|---|
 | 88 |   int_4 nSzY = dvl.GetI("NSZY");
 | 
|---|
 | 89 |   int_4 nPix = dvl.GetI("NPIX");
 | 
|---|
 | 90 |   if (nPix != nbentries)
 | 
|---|
 | 91 |     {
 | 
|---|
 | 92 |       throw IOExc("longueur datablock incompatible avec nPix");
 | 
|---|
 | 93 |     }
 | 
|---|
 | 94 |   dobj_->ReSize(nSzX, nSzY); 
 | 
|---|
| [2013] | 95 |   //  int_4 localMappingDone = dvl.GetI("LCMP");
 | 
|---|
 | 96 |   // if (localMappingDone)
 | 
|---|
 | 97 |   //  {
 | 
|---|
| [1181] | 98 |       int_4 x0 = dvl.GetI("X0");
 | 
|---|
 | 99 |       int_4 y0 = dvl.GetI("Y0");
 | 
|---|
 | 100 |       double theta = dvl.GetD("THETA");
 | 
|---|
 | 101 |       double phi   = dvl.GetD("PHI");
 | 
|---|
 | 102 |       double angle = dvl.GetD("ANGLE");
 | 
|---|
 | 103 |       dobj_->SetOrigin(theta, phi, x0, y0, angle);
 | 
|---|
 | 104 |       double angleX = dvl.GetD("ANGLEX");
 | 
|---|
 | 105 |       double angleY = dvl.GetD("ANGLEY");
 | 
|---|
 | 106 |       dobj_->SetSize(angleX, angleY);
 | 
|---|
| [2013] | 107 |       //  }
 | 
|---|
| [1181] | 108 |   // On lit les DataBlocks;
 | 
|---|
 | 109 |   dobj_->DataBlock().ReSize(nPix);
 | 
|---|
 | 110 |   is.GetSingleColumn(dobj_->DataBlock().Data(),nPix);
 | 
|---|
 | 111 | 
 | 
|---|
 | 112 |   // dvlist de LocalMap
 | 
|---|
 | 113 |   dobj_->Info()  = is.DVListFromFits();
 | 
|---|
 | 114 | }
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | template <class T>
 | 
|---|
 | 117 | void FITS_LocalMap<T>::WriteToFits(FitsOutFile& os) 
 | 
|---|
 | 118 | {
 | 
|---|
 | 119 |   if(dobj_ == NULL) 
 | 
|---|
 | 120 |     { 
 | 
|---|
 | 121 |       cout << " WriteToFits:: dobj_= null " << endl;
 | 
|---|
 | 122 |       return;
 | 
|---|
 | 123 |     }
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 |   DVList dvl( dobj_->Info() );  
 | 
|---|
 | 126 |   dvl["NSZX"] = dobj_->Size_x();
 | 
|---|
 | 127 |   dvl.SetComment("NSZX", "number of pixels in x direction");
 | 
|---|
 | 128 |   dvl["NSZY"] = dobj_->Size_y();
 | 
|---|
 | 129 |   dvl.SetComment("NSZY", "number of pixels in y direction");
 | 
|---|
 | 130 |   dvl["NPIX"] = dobj_->NbPixels();
 | 
|---|
 | 131 |   dvl.SetComment("NPIX", "number of pixels in local map");
 | 
|---|
 | 132 | 
 | 
|---|
| [2013] | 133 |   // if(dobj_->LocalMap_isDone())
 | 
|---|
 | 134 |   // {
 | 
|---|
 | 135 |   //   dvl["LCMP"] = (int_4) 1;
 | 
|---|
 | 136 |   //   dvl.SetComment("LCMP", "local mapping 1= done, 0= not done");
 | 
|---|
| [1181] | 137 |       int_4 x0 = 0;
 | 
|---|
 | 138 |       int_4 y0 = 0;
 | 
|---|
 | 139 |       double theta = 0.;
 | 
|---|
 | 140 |       double  phi = 0.;
 | 
|---|
 | 141 |       double  angle = 0.;
 | 
|---|
 | 142 |       dobj_->Origin(theta, phi, x0, y0, angle);
 | 
|---|
 | 143 |       dvl["X0"]     = x0;
 | 
|---|
 | 144 |       dvl.SetComment("X0", "number of pixel of the origin, x direction");
 | 
|---|
 | 145 |       dvl["Y0"]     = y0;
 | 
|---|
 | 146 |       dvl.SetComment("Y0", "number of pixel of the origin, y direction");
 | 
|---|
 | 147 |       dvl["THETA"]  = theta;
 | 
|---|
 | 148 |       dvl.SetComment("THETA", "theta position of the map-origin");
 | 
|---|
 | 149 |       dvl["PHI"]    = phi;
 | 
|---|
 | 150 |       dvl.SetComment("PHI", "phi position of the map origin");
 | 
|---|
 | 151 |       dvl["ANGLE"]  = angle;
 | 
|---|
 | 152 |       dvl.SetComment("ANGLE", "angle between max x axis and sphere phi-axis");
 | 
|---|
 | 153 | 
 | 
|---|
 | 154 |       double angleX =0.;
 | 
|---|
 | 155 |       double angleY = 0.;
 | 
|---|
 | 156 |       dobj_->Aperture(angleX, angleY);
 | 
|---|
 | 157 |       dvl["ANGLEX"] = angleX;
 | 
|---|
 | 158 |       dvl.SetComment("ANGLEX", "sphere angle covered by map x-extension ");
 | 
|---|
 | 159 |       dvl["ANGLEY"] = angleY;
 | 
|---|
 | 160 |       dvl.SetComment("ANGLEY", "sphere angle covered by map y-extension ");
 | 
|---|
| [2013] | 161 |       // }
 | 
|---|
 | 162 |   // else
 | 
|---|
 | 163 |   //  {
 | 
|---|
 | 164 |   //    dvl["LCMP"] = (int_4) 0;
 | 
|---|
 | 165 |   //  }
 | 
|---|
| [1181] | 166 |   dvl["Content"]= "LocalMap";
 | 
|---|
| [1300] | 167 |   dvl.SetComment("Content", "name of SOPHYA object");
 | 
|---|
| [1181] | 168 |   // On ecrit les dataBlocks 
 | 
|---|
| [1194] | 169 |   vector<string> Noms;   
 | 
|---|
 | 170 |   Noms.push_back(dvl.GetS("Content"));
 | 
|---|
 | 171 |   string extname("SIMULATION");
 | 
|---|
| [1181] | 172 | 
 | 
|---|
| [1194] | 173 |   string Type;
 | 
|---|
 | 174 |   if (typeid(T) == typeid(r_8) ) Type+='D';
 | 
|---|
| [1181] | 175 |   else 
 | 
|---|
| [1194] | 176 |     if (typeid(T) == typeid(r_4) )  Type+='E';
 | 
|---|
| [1181] | 177 |     else
 | 
|---|
 | 178 |       {
 | 
|---|
 | 179 |         cout <<  " type de la LocalMap = " <<  typeid(T).name() << endl;
 | 
|---|
 | 180 |         throw IOExc("FITS_LocalMap:: unknown type");
 | 
|---|
 | 181 |       }
 | 
|---|
 | 182 |   vector<int> dummy;
 | 
|---|
| [1221] | 183 |   os.makeHeaderBntblOnFits(Type, Noms, dobj_->NbPixels(), 1, &dvl, extname, dummy);
 | 
|---|
| [1210] | 184 |   os.PutColToFits(0,  dobj_->NbPixels(), dobj_->DataBlock().Data()); 
 | 
|---|
| [1181] | 185 | 
 | 
|---|
 | 186 | }
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
 | 189 | #pragma define_template FITS_LocalMap<r_8>
 | 
|---|
 | 190 | #pragma define_template FITS_LocalMap<r_4>
 | 
|---|
| [1300] | 191 | #pragma define_template FITS_LocalMap<int_4>
 | 
|---|
| [1181] | 192 | #endif
 | 
|---|
 | 193 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
 | 194 | template class FITS_LocalMap<r_8>;
 | 
|---|
 | 195 | template class FITS_LocalMap<r_4>;
 | 
|---|
| [1300] | 196 | template class FITS_LocalMap<int_4>;
 | 
|---|
| [1181] | 197 | #endif
 | 
|---|