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