| 1 | /*    
 | 
|---|
| 2 |    --- SOPHYA software - FitsIOServer module ---
 | 
|---|
| 3 |    C. Magneville, 2001 
 | 
|---|
| 4 |    (C) UPS+LAL IN2P3/CNRS     (C) DAPNIA-SPP/CEA 
 | 
|---|
| 5 | */
 | 
|---|
| 6 | /* Interface Fits BINARY/ASCII Table Column Reader    cmv 26/09/2001 */
 | 
|---|
| 7 | #ifndef FABTCOLREAD_H_SEEN
 | 
|---|
| 8 | #define FABTCOLREAD_H_SEEN
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "machdefs.h"
 | 
|---|
| 11 | #include <iostream>
 | 
|---|
| 12 | #include <string.h>
 | 
|---|
| 13 | #include <string>
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "anydataobj.h"
 | 
|---|
| 16 | #include "tvector.h"
 | 
|---|
| 17 | #include "FitsIO/fitsio.h"
 | 
|---|
| 18 | 
 | 
|---|
| 19 | namespace SOPHYA {
 | 
|---|
| 20 | 
 | 
|---|
| 21 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 22 | //! Class for opening a FITS file for reading
 | 
|---|
| 23 | class FitsOpenFile : public AnyDataObj {
 | 
|---|
| 24 | public:
 | 
|---|
| 25 |   FitsOpenFile(string fname);
 | 
|---|
| 26 |   FitsOpenFile(const char *cfname);
 | 
|---|
| 27 |   FitsOpenFile();
 | 
|---|
| 28 |   FitsOpenFile(FitsOpenFile& fof);
 | 
|---|
| 29 |   virtual ~FitsOpenFile();
 | 
|---|
| 30 | 
 | 
|---|
| 31 |   inline string FileName() const {return FitsFN;}
 | 
|---|
| 32 |   //! Get the number of the HDU read
 | 
|---|
| 33 |   inline int HDU(void) const {return IHdu;}
 | 
|---|
| 34 |   //! Get the number of the HDU type
 | 
|---|
| 35 |   inline int HDUType(void) const {return HduType;}
 | 
|---|
| 36 |   //! Get the number of HDU in file
 | 
|---|
| 37 |   inline int NHDU() const {return NHdu;}
 | 
|---|
| 38 |   //! Get the CFISTIO fits file pointer
 | 
|---|
| 39 |   inline fitsfile* GetFitsPtr() const {return FitsPtr;}
 | 
|---|
| 40 |   //! Set the positionning status of the file
 | 
|---|
| 41 |   inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;}
 | 
|---|
| 42 |   //! Get the positionning status of the file
 | 
|---|
| 43 |   inline bool GetPosStatus(void) const {return HasBeenPos;}
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   int MoveToHDU(int ihdu);
 | 
|---|
| 46 |   int MoveToFirst(int hdutype,int ihdudeb=1);
 | 
|---|
| 47 |   int MoveToLast(int hdutype,int ihdudeb=1);
 | 
|---|
| 48 |   void Print(void);
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   static double   ReadKey(fitsfile *fitsptr,char *keyname);
 | 
|---|
| 51 |   static long     ReadKeyL(fitsfile *fitsptr,char *keyname);
 | 
|---|
| 52 |   static LONGLONG ReadKeyLL(fitsfile *fitsptr,char *keyname);
 | 
|---|
| 53 |   static string   ReadKeyS(fitsfile *fitsptr,char *keyname);
 | 
|---|
| 54 |   static void   printerror(int sta);
 | 
|---|
| 55 | 
 | 
|---|
| 56 | protected:
 | 
|---|
| 57 |   void Init(const char *cfname);
 | 
|---|
| 58 |   void Delete(void);
 | 
|---|
| 59 | 
 | 
|---|
| 60 |   string FitsFN;
 | 
|---|
| 61 |   int NHdu, IHdu, HduType;
 | 
|---|
| 62 |   fitsfile *FitsPtr;
 | 
|---|
| 63 |   bool HasBeenPos;
 | 
|---|
| 64 | };
 | 
|---|
| 65 | 
 | 
|---|
| 66 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 67 | //! Class for reading a column in a FITS ASCII or BINARY table
 | 
|---|
| 68 | class FitsABTColRd : public AnyDataObj {
 | 
|---|
| 69 | public:
 | 
|---|
| 70 |   FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
 | 
|---|
| 71 |               ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 72 |   FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
 | 
|---|
| 73 |               ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 74 |   FitsABTColRd(FitsABTColRd& fbt);
 | 
|---|
| 75 |   FitsABTColRd();
 | 
|---|
| 76 |   virtual ~FitsABTColRd();
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   void ChangeBuffer(long blen=100,long bsens=1);
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   double    ReadKey(char *keyname);
 | 
|---|
| 81 |   long      ReadKeyL(char *keyname);
 | 
|---|
| 82 |   LONGLONG  ReadKeyLL(char *keyname);
 | 
|---|
| 83 |   string    ReadKeyS(char *keyname);
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   double Read(LONGLONG n,bool usebuffer=true);
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<uint_2>& data);
 | 
|---|
| 88 |   LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_4>& data);
 | 
|---|
| 89 |   LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_8>& data);
 | 
|---|
| 90 |   LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<float>& data);
 | 
|---|
| 91 |   LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<double>& data);
 | 
|---|
| 92 | 
 | 
|---|
| 93 |   //! return the value of the first row
 | 
|---|
| 94 |   double ReadFirstRow(bool usebuffer=false)
 | 
|---|
| 95 |                      {return Read(0,usebuffer);}
 | 
|---|
| 96 |   //! return the value of the last row
 | 
|---|
| 97 |   double ReadLastRow(bool usebuffer=false)
 | 
|---|
| 98 |                     {return Read(NBline-1,usebuffer);}
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   LONGLONG FirstRow(double val1,double val2,LONGLONG rowstart=-1);
 | 
|---|
| 101 |   LONGLONG LastRow(double val1,double val2,LONGLONG rowstart=-1);
 | 
|---|
| 102 | 
 | 
|---|
| 103 |   //! Set debug level
 | 
|---|
| 104 |   inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
 | 
|---|
| 105 |   //! Set null value to be return when reading null data (0=return the data)
 | 
|---|
| 106 |   inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
 | 
|---|
| 107 |   //! Get the FITS file name
 | 
|---|
| 108 |   inline string FileName(void) const
 | 
|---|
| 109 |          {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
 | 
|---|
| 110 |   //! Get the pointer to FitsOpenFile
 | 
|---|
| 111 |   inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
 | 
|---|
| 112 |   //! Get the FITS file pointer (cfistio pointer)
 | 
|---|
| 113 |   inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
 | 
|---|
| 114 |   //! Get the number of HDU in the FITS file
 | 
|---|
| 115 |   inline int NHDU(void) const
 | 
|---|
| 116 |          {if(FitsOF) return FitsOF->NHDU(); else return 0;}
 | 
|---|
| 117 |   //! Get the number of the HDU read
 | 
|---|
| 118 |   inline int HDU(void) const
 | 
|---|
| 119 |          {if(FitsOF) return FitsOF->HDU(); else return 0;}
 | 
|---|
| 120 |   //! Get the HDU type
 | 
|---|
| 121 |   inline int HDUType(void) const
 | 
|---|
| 122 |          {if(FitsOF) return FitsOF->HDUType(); else return 0;}
 | 
|---|
| 123 |   //! Get the number of rows in the FITS HDU to be read
 | 
|---|
| 124 |   inline LONGLONG GetNbLine(void) const {return NBline;}
 | 
|---|
| 125 |   //! Get the number of columns in the FITS HDU to be read
 | 
|---|
| 126 |   inline int GetNbCol(void) const {return NBcol;}
 | 
|---|
| 127 |   //! Get the columns number that is read
 | 
|---|
| 128 |   inline int GetColNum(void) const {return ColNum;}
 | 
|---|
| 129 |   //! Get the columns label that is read
 | 
|---|
| 130 |   inline string GetColLabel(void) const {return ColLabel;}
 | 
|---|
| 131 |   //! Get the columns type code that is read
 | 
|---|
| 132 |   inline int GetColTypeCode(void) const {return ColTypeCode;}
 | 
|---|
| 133 |   //! Get the columns fits tunit that is read
 | 
|---|
| 134 |   inline string GetColTUnit(void) const {return ColTUnit;}
 | 
|---|
| 135 |   //! Get the columns fits tform that is read
 | 
|---|
| 136 |   inline string GetColTForm(void) const {return ColTForm;}
 | 
|---|
| 137 |   //! Get the read requested buffer length
 | 
|---|
| 138 |   inline long GetBLen(void) const {return BuffLen;}
 | 
|---|
| 139 |   //! Get the read buffer direction
 | 
|---|
| 140 |   inline long GetBSens(void) const {return BuffSens;}
 | 
|---|
| 141 |   //! Print to os
 | 
|---|
| 142 |   virtual void Print(ostream& os,int lp=1) const;
 | 
|---|
| 143 |   //! Print to stdout
 | 
|---|
| 144 |   inline  void Print(int lp=1) const {Print(cout,lp);}
 | 
|---|
| 145 |   //! Get the read effective buffer length
 | 
|---|
| 146 |   inline long GetNBuffer(void) const {return NBuffer;}
 | 
|---|
| 147 |   //! Get the read bufferpointer
 | 
|---|
| 148 |   inline double* GetBuffer(void) {return Buffer;}
 | 
|---|
| 149 | 
 | 
|---|
| 150 | protected:
 | 
|---|
| 151 |   void Init(FitsOpenFile* fof,const char *collabel,int colnum
 | 
|---|
| 152 |            ,int ihdu,long blen,long bsens,int lp);
 | 
|---|
| 153 |   void Delete(void);
 | 
|---|
| 154 | 
 | 
|---|
| 155 |   string ColLabel,ColTUnit,ColTForm;
 | 
|---|
| 156 |   int ColNum,ColTypeCode,NBcol;
 | 
|---|
| 157 |   LONGLONG NBline;
 | 
|---|
| 158 | 
 | 
|---|
| 159 |   double NulVal;
 | 
|---|
| 160 |   unsigned short DbgLevel;
 | 
|---|
| 161 |   long BuffLen, BuffSens;
 | 
|---|
| 162 | 
 | 
|---|
| 163 |   LONGLONG NFitsRead;
 | 
|---|
| 164 |   FitsOpenFile* FitsOF;
 | 
|---|
| 165 |   LONGLONG LineDeb, LineFin;
 | 
|---|
| 166 |   double *Buffer;
 | 
|---|
| 167 |   long NBuffer;
 | 
|---|
| 168 | };
 | 
|---|
| 169 | 
 | 
|---|
| 170 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 171 | //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
 | 
|---|
| 172 | class FitsABTColRead : public FitsABTColRd {
 | 
|---|
| 173 | public:
 | 
|---|
| 174 |   FitsABTColRead(string fname,string collabel,int ihdu=0
 | 
|---|
| 175 |                 ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 176 |   FitsABTColRead(string fname,int colnum,int ihdu=0
 | 
|---|
| 177 |                 ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 178 |   FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
 | 
|---|
| 179 |                 ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 180 |   FitsABTColRead(const char *cfname,int colnum,int ihdu=0
 | 
|---|
| 181 |                 ,long blen=100,long bsens=1,int lp=0);
 | 
|---|
| 182 |   FitsABTColRead(FitsABTColRead& fbt);
 | 
|---|
| 183 |   FitsABTColRead();
 | 
|---|
| 184 |   virtual ~FitsABTColRead();
 | 
|---|
| 185 | };
 | 
|---|
| 186 | 
 | 
|---|
| 187 | 
 | 
|---|
| 188 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 189 | //! Class for reading a 2D image from a FITS file
 | 
|---|
| 190 | class FitsImg2DRd : public AnyDataObj {
 | 
|---|
| 191 | public:
 | 
|---|
| 192 |   FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
 | 
|---|
| 193 |   FitsImg2DRd(FitsImg2DRd& fbt);
 | 
|---|
| 194 |   FitsImg2DRd();
 | 
|---|
| 195 |   virtual ~FitsImg2DRd();
 | 
|---|
| 196 | 
 | 
|---|
| 197 |   double   ReadKey(char *keyname);
 | 
|---|
| 198 |   long     ReadKeyL(char *keyname);
 | 
|---|
| 199 |   LONGLONG ReadKeyLL(char *keyname);
 | 
|---|
| 200 |   string   ReadKeyS(char *keyname);
 | 
|---|
| 201 | 
 | 
|---|
| 202 |   LONGLONG Read(TMatrix<uint_2>& data);
 | 
|---|
| 203 |   LONGLONG Read(TMatrix<int_4>& data);
 | 
|---|
| 204 |   LONGLONG Read(TMatrix<int_8>& data);
 | 
|---|
| 205 |   LONGLONG Read(TMatrix<float>& data);
 | 
|---|
| 206 |   LONGLONG Read(TMatrix<double>& data);
 | 
|---|
| 207 |   double   Read(LONGLONG numcol, LONGLONG numrow);
 | 
|---|
| 208 | 
 | 
|---|
| 209 |   //! Set debug level
 | 
|---|
| 210 |   inline void    SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
 | 
|---|
| 211 |   //! Set null value to be return when reading null data (0=return the data)
 | 
|---|
| 212 |   inline void    SetNulVal(double nulval=0.) {NulVal = nulval;}
 | 
|---|
| 213 |   //! Get the pointer to FitsOpenFile
 | 
|---|
| 214 |   inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
 | 
|---|
| 215 |   //! Get the FITS file pointer (cfistio pointer)
 | 
|---|
| 216 |   inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
 | 
|---|
| 217 |   //! Get the number of HDU in the FITS file
 | 
|---|
| 218 |   inline int NHDU(void) const
 | 
|---|
| 219 |          {if(FitsOF) return FitsOF->NHDU(); else return 0;}
 | 
|---|
| 220 |   //! Get the number of the HDU read
 | 
|---|
| 221 |   inline int HDU(void) const
 | 
|---|
| 222 |          {if(FitsOF) return FitsOF->HDU(); else return 0;}
 | 
|---|
| 223 |   //! Get the HDU type
 | 
|---|
| 224 |   inline int HDUType(void) const
 | 
|---|
| 225 |          {if(FitsOF) return FitsOF->HDUType(); else return 0;}
 | 
|---|
| 226 |   //! Get NAXIS1
 | 
|---|
| 227 |   inline LONGLONG Naxis1(void) const {return Naxis[0];}
 | 
|---|
| 228 |   //! Get NAXIS2
 | 
|---|
| 229 |   inline LONGLONG Naxis2(void) const {return Naxis[1];}
 | 
|---|
| 230 | 
 | 
|---|
| 231 | protected:
 | 
|---|
| 232 |   void Init(FitsOpenFile* fof,int ihdu,int lp);
 | 
|---|
| 233 | 
 | 
|---|
| 234 |   LONGLONG Naxis[2];
 | 
|---|
| 235 |   double NulVal;
 | 
|---|
| 236 |   unsigned short DbgLevel;
 | 
|---|
| 237 | 
 | 
|---|
| 238 |   FitsOpenFile* FitsOF;
 | 
|---|
| 239 | };
 | 
|---|
| 240 | 
 | 
|---|
| 241 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 242 | //! Class for reading a 2D image from a FITS file
 | 
|---|
| 243 | class FitsImg2DRead : public FitsImg2DRd {
 | 
|---|
| 244 | public:
 | 
|---|
| 245 |   FitsImg2DRead(string fname,int ihdu=0,int lp=0);
 | 
|---|
| 246 |   FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0);
 | 
|---|
| 247 |   FitsImg2DRead(FitsImg2DRead& fbt);
 | 
|---|
| 248 |   FitsImg2DRead();
 | 
|---|
| 249 |   virtual ~FitsImg2DRead();
 | 
|---|
| 250 | };
 | 
|---|
| 251 | 
 | 
|---|
| 252 | 
 | 
|---|
| 253 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 254 | //! Class for reading a 3D image from a FITS file
 | 
|---|
| 255 | class FitsImg3DRd : public AnyDataObj {
 | 
|---|
| 256 | public:
 | 
|---|
| 257 |   FitsImg3DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
 | 
|---|
| 258 |   FitsImg3DRd(FitsImg3DRd& fbt);
 | 
|---|
| 259 |   FitsImg3DRd();
 | 
|---|
| 260 |   virtual ~FitsImg3DRd();
 | 
|---|
| 261 | 
 | 
|---|
| 262 |   double   ReadKey(char *keyname);
 | 
|---|
| 263 |   long     ReadKeyL(char *keyname);
 | 
|---|
| 264 |   LONGLONG ReadKeyLL(char *keyname);
 | 
|---|
| 265 |   string   ReadKeyS(char *keyname);
 | 
|---|
| 266 | 
 | 
|---|
| 267 |   LONGLONG Read(TArray<uint_2>& data);
 | 
|---|
| 268 |   LONGLONG Read(TArray<int_4>& data);
 | 
|---|
| 269 |   LONGLONG Read(TArray<int_8>& data);
 | 
|---|
| 270 |   LONGLONG Read(TArray<float>& data);
 | 
|---|
| 271 |   LONGLONG Read(TArray<double>& data);
 | 
|---|
| 272 |   double   Read(LONGLONG i, LONGLONG j, LONGLONG k);
 | 
|---|
| 273 | 
 | 
|---|
| 274 |   //! Set debug level
 | 
|---|
| 275 |   inline void    SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
 | 
|---|
| 276 |   //! Set null value to be return when reading null data (0=return the data)
 | 
|---|
| 277 |   inline void    SetNulVal(double nulval=0.) {NulVal = nulval;}
 | 
|---|
| 278 |   //! Get the pointer to FitsOpenFile
 | 
|---|
| 279 |   inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
 | 
|---|
| 280 |   //! Get the FITS file pointer (cfistio pointer)
 | 
|---|
| 281 |   inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
 | 
|---|
| 282 |   //! Get the number of HDU in the FITS file
 | 
|---|
| 283 |   inline int NHDU(void) const
 | 
|---|
| 284 |          {if(FitsOF) return FitsOF->NHDU(); else return 0;}
 | 
|---|
| 285 |   //! Get the number of the HDU read
 | 
|---|
| 286 |   inline int HDU(void) const
 | 
|---|
| 287 |          {if(FitsOF) return FitsOF->HDU(); else return 0;}
 | 
|---|
| 288 |   //! Get the HDU type
 | 
|---|
| 289 |   inline int HDUType(void) const
 | 
|---|
| 290 |          {if(FitsOF) return FitsOF->HDUType(); else return 0;}
 | 
|---|
| 291 |   //! Get NAXIS1
 | 
|---|
| 292 |   inline LONGLONG Naxis1(void) const {return Naxis[0];}
 | 
|---|
| 293 |   //! Get NAXIS2
 | 
|---|
| 294 |   inline LONGLONG Naxis2(void) const {return Naxis[1];}
 | 
|---|
| 295 |   //! Get NAXIS3
 | 
|---|
| 296 |   inline LONGLONG Naxis3(void) const {return Naxis[2];}
 | 
|---|
| 297 | 
 | 
|---|
| 298 | protected:
 | 
|---|
| 299 |   void Init(FitsOpenFile* fof,int ihdu,int lp);
 | 
|---|
| 300 | 
 | 
|---|
| 301 |   LONGLONG Naxis[3];
 | 
|---|
| 302 |   double NulVal;
 | 
|---|
| 303 |   unsigned short DbgLevel;
 | 
|---|
| 304 | 
 | 
|---|
| 305 |   FitsOpenFile* FitsOF;
 | 
|---|
| 306 | };
 | 
|---|
| 307 | 
 | 
|---|
| 308 | ///////////////////////////////////////////////////////////////////
 | 
|---|
| 309 | //! Class for reading a 3D image from a FITS file
 | 
|---|
| 310 | class FitsImg3DRead : public FitsImg3DRd {
 | 
|---|
| 311 | public:
 | 
|---|
| 312 |   FitsImg3DRead(string fname,int ihdu=0,int lp=0);
 | 
|---|
| 313 |   FitsImg3DRead(const char *cfname,int ihdu=0,int lp=0);
 | 
|---|
| 314 |   FitsImg3DRead(FitsImg3DRead& fbt);
 | 
|---|
| 315 |   FitsImg3DRead();
 | 
|---|
| 316 |   virtual ~FitsImg3DRead();
 | 
|---|
| 317 | };
 | 
|---|
| 318 | 
 | 
|---|
| 319 | } // namespace SOPHYA
 | 
|---|
| 320 | #endif    /* FABTCOLREAD_H_SEEN */
 | 
|---|