| 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 string ReadKeyS(fitsfile *fitsptr,char *keyname); | 
|---|
| 48 | static void   printerror(int sta); | 
|---|
| 49 |  | 
|---|
| 50 | protected: | 
|---|
| 51 | void Init(const char *cfname); | 
|---|
| 52 | void Delete(void); | 
|---|
| 53 |  | 
|---|
| 54 | string FitsFN; | 
|---|
| 55 | int NHdu, IHdu, HduType; | 
|---|
| 56 | fitsfile *FitsPtr; | 
|---|
| 57 | bool HasBeenPos; | 
|---|
| 58 | }; | 
|---|
| 59 |  | 
|---|
| 60 | /////////////////////////////////////////////////////////////////// | 
|---|
| 61 | //! Class for reading a column in a FITS ASCII or BINARY table | 
|---|
| 62 | class FitsABTColRd : public AnyDataObj { | 
|---|
| 63 | public: | 
|---|
| 64 | FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0 | 
|---|
| 65 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 66 | FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0 | 
|---|
| 67 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 68 | FitsABTColRd(FitsABTColRd& fbt); | 
|---|
| 69 | FitsABTColRd(); | 
|---|
| 70 | virtual ~FitsABTColRd(); | 
|---|
| 71 |  | 
|---|
| 72 | void ChangeBuffer(long blen=100,long bsens=1); | 
|---|
| 73 |  | 
|---|
| 74 | double ReadKey(char *keyname); | 
|---|
| 75 | long   ReadKeyL(char *keyname); | 
|---|
| 76 | string ReadKeyS(char *keyname); | 
|---|
| 77 |  | 
|---|
| 78 | double Read(long n,bool usebuffer=true); | 
|---|
| 79 |  | 
|---|
| 80 | long Read(long n1,long n2,TVector<uint_2>& data); | 
|---|
| 81 | long Read(long n1,long n2,TVector<int_4>& data); | 
|---|
| 82 | long Read(long n1,long n2,TVector<int_8>& data); | 
|---|
| 83 | long Read(long n1,long n2,TVector<float>& data); | 
|---|
| 84 | long Read(long n1,long n2,TVector<double>& data); | 
|---|
| 85 |  | 
|---|
| 86 | //! return the value of the first row | 
|---|
| 87 | double ReadFirstRow(bool usebuffer=false) | 
|---|
| 88 | {return Read(0,usebuffer);} | 
|---|
| 89 | //! return the value of the last row | 
|---|
| 90 | double ReadLastRow(bool usebuffer=false) | 
|---|
| 91 | {return Read(NBline-1,usebuffer);} | 
|---|
| 92 |  | 
|---|
| 93 | long FirstRow(double val1,double val2,long rowstart=-1); | 
|---|
| 94 | long LastRow(double val1,double val2,long rowstart=-1); | 
|---|
| 95 |  | 
|---|
| 96 | //! Set debug level | 
|---|
| 97 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} | 
|---|
| 98 | //! Set null value to be return when reading null data (0=return the data) | 
|---|
| 99 | inline void SetNulVal(double nulval=0.) {NulVal = nulval;} | 
|---|
| 100 | //! Get the FITS file name | 
|---|
| 101 | inline string FileName(void) const | 
|---|
| 102 | {if(FitsOF) return FitsOF->FileName(); else return (string)"";} | 
|---|
| 103 | //! Get the pointer to FitsOpenFile | 
|---|
| 104 | inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} | 
|---|
| 105 | //! Get the FITS file pointer (cfistio pointer) | 
|---|
| 106 | inline fitsfile* GetFitsPtr(void) const {return FitsPtr;} | 
|---|
| 107 | //! Get the number of HDU in the FITS file | 
|---|
| 108 | inline int NHDU(void) const | 
|---|
| 109 | {if(FitsOF) return FitsOF->NHDU(); else return 0;} | 
|---|
| 110 | //! Get the number of the HDU read | 
|---|
| 111 | inline int HDU(void) const | 
|---|
| 112 | {if(FitsOF) return FitsOF->HDU(); else return 0;} | 
|---|
| 113 | //! Get the HDU type | 
|---|
| 114 | inline int HDUType(void) const | 
|---|
| 115 | {if(FitsOF) return FitsOF->HDUType(); else return 0;} | 
|---|
| 116 | //! Get the number of rows in the FITS HDU to be read | 
|---|
| 117 | inline long GetNbLine(void) const {return NBline;} | 
|---|
| 118 | //! Get the number of columns in the FITS HDU to be read | 
|---|
| 119 | inline int GetNbCol(void) const {return NBcol;} | 
|---|
| 120 | //! Get the columns number that is read | 
|---|
| 121 | inline int GetColNum(void) const {return ColNum;} | 
|---|
| 122 | //! Get the columns label that is read | 
|---|
| 123 | inline string GetColLabel(void) const {return ColLabel;} | 
|---|
| 124 | //! Get the columns type code that is read | 
|---|
| 125 | inline int GetColTypeCode(void) const {return ColTypeCode;} | 
|---|
| 126 | //! Get the columns fits tunit that is read | 
|---|
| 127 | inline string GetColTUnit(void) const {return ColTUnit;} | 
|---|
| 128 | //! Get the columns fits tform that is read | 
|---|
| 129 | inline string GetColTForm(void) const {return ColTForm;} | 
|---|
| 130 | //! Get the read requested buffer length | 
|---|
| 131 | inline long GetBLen(void) const {return BuffLen;} | 
|---|
| 132 | //! Get the read buffer direction | 
|---|
| 133 | inline long GetBSens(void) const {return BuffSens;} | 
|---|
| 134 | //! Print to os | 
|---|
| 135 | virtual void Print(ostream& os,int lp=1) const; | 
|---|
| 136 | //! Print to stdout | 
|---|
| 137 | inline  void Print(int lp=1) const {Print(cout,lp);} | 
|---|
| 138 | //! Get the read effective buffer length | 
|---|
| 139 | inline long GetNBuffer(void) const {return NBuffer;} | 
|---|
| 140 | //! Get the read bufferpointer | 
|---|
| 141 | inline double* GetBuffer(void) {return Buffer;} | 
|---|
| 142 |  | 
|---|
| 143 | protected: | 
|---|
| 144 | void Init(FitsOpenFile* fof,const char *collabel,int colnum | 
|---|
| 145 | ,int ihdu,long blen,long bsens,int lp); | 
|---|
| 146 | void Delete(void); | 
|---|
| 147 |  | 
|---|
| 148 | string ColLabel,ColTUnit,ColTForm; | 
|---|
| 149 | int ColNum,ColTypeCode,NBcol; | 
|---|
| 150 | long NBline; | 
|---|
| 151 |  | 
|---|
| 152 | double NulVal; | 
|---|
| 153 | unsigned short DbgLevel; | 
|---|
| 154 | long BuffLen, BuffSens; | 
|---|
| 155 |  | 
|---|
| 156 | unsigned long NFitsRead; | 
|---|
| 157 | FitsOpenFile* FitsOF; | 
|---|
| 158 | fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout! | 
|---|
| 159 | long LineDeb, LineFin; | 
|---|
| 160 | double *Buffer; | 
|---|
| 161 | long NBuffer; | 
|---|
| 162 | }; | 
|---|
| 163 |  | 
|---|
| 164 | /////////////////////////////////////////////////////////////////// | 
|---|
| 165 | //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening | 
|---|
| 166 | class FitsABTColRead : public FitsABTColRd { | 
|---|
| 167 | public: | 
|---|
| 168 | FitsABTColRead(string fname,string collabel,int ihdu=0 | 
|---|
| 169 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 170 | FitsABTColRead(string fname,int colnum,int ihdu=0 | 
|---|
| 171 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 172 | FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0 | 
|---|
| 173 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 174 | FitsABTColRead(const char *cfname,int colnum,int ihdu=0 | 
|---|
| 175 | ,long blen=100,long bsens=1,int lp=0); | 
|---|
| 176 | FitsABTColRead(FitsABTColRead& fbt); | 
|---|
| 177 | FitsABTColRead(); | 
|---|
| 178 | virtual ~FitsABTColRead(); | 
|---|
| 179 | }; | 
|---|
| 180 |  | 
|---|
| 181 |  | 
|---|
| 182 | /////////////////////////////////////////////////////////////////// | 
|---|
| 183 | //! Class for reading a 2D image from a FITS file | 
|---|
| 184 | class FitsImg2DRd : public AnyDataObj { | 
|---|
| 185 | public: | 
|---|
| 186 | FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0); | 
|---|
| 187 | FitsImg2DRd(FitsImg2DRd& fbt); | 
|---|
| 188 | FitsImg2DRd(); | 
|---|
| 189 | virtual ~FitsImg2DRd(); | 
|---|
| 190 |  | 
|---|
| 191 | double ReadKey(char *keyname); | 
|---|
| 192 | long   ReadKeyL(char *keyname); | 
|---|
| 193 | string ReadKeyS(char *keyname); | 
|---|
| 194 |  | 
|---|
| 195 | long Read(TMatrix<uint_2>& data); | 
|---|
| 196 | long Read(TMatrix<int_4>& data); | 
|---|
| 197 | long Read(TMatrix<int_8>& data); | 
|---|
| 198 | long Read(TMatrix<float>& data); | 
|---|
| 199 | long Read(TMatrix<double>& data); | 
|---|
| 200 |  | 
|---|
| 201 | //! Set debug level | 
|---|
| 202 | inline void    SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} | 
|---|
| 203 | //! Set null value to be return when reading null data (0=return the data) | 
|---|
| 204 | inline void    SetNulVal(double nulval=0.) {NulVal = nulval;} | 
|---|
| 205 | //! Get the pointer to FitsOpenFile | 
|---|
| 206 | inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} | 
|---|
| 207 | //! Get the FITS file pointer (cfistio pointer) | 
|---|
| 208 | inline fitsfile* GetFitsPtr(void) const {return FitsPtr;} | 
|---|
| 209 | //! Get the number of HDU in the FITS file | 
|---|
| 210 | inline int NHDU(void) const | 
|---|
| 211 | {if(FitsOF) return FitsOF->NHDU(); else return 0;} | 
|---|
| 212 | //! Get the number of the HDU read | 
|---|
| 213 | inline int HDU(void) const | 
|---|
| 214 | {if(FitsOF) return FitsOF->HDU(); else return 0;} | 
|---|
| 215 | //! Get the HDU type | 
|---|
| 216 | inline int HDUType(void) const | 
|---|
| 217 | {if(FitsOF) return FitsOF->HDUType(); else return 0;} | 
|---|
| 218 | //! Get NAXIS1 | 
|---|
| 219 | inline long Naxis1(void) const {return Naxis[0];} | 
|---|
| 220 | //! Get NAXIS2 | 
|---|
| 221 | inline long Naxis2(void) const {return Naxis[1];} | 
|---|
| 222 |  | 
|---|
| 223 | protected: | 
|---|
| 224 | void Init(FitsOpenFile* fof,int ihdu,int lp); | 
|---|
| 225 |  | 
|---|
| 226 | long Naxis[2]; | 
|---|
| 227 | double NulVal; | 
|---|
| 228 | unsigned short DbgLevel; | 
|---|
| 229 |  | 
|---|
| 230 | FitsOpenFile* FitsOF; | 
|---|
| 231 | fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout! | 
|---|
| 232 | }; | 
|---|
| 233 |  | 
|---|
| 234 | /////////////////////////////////////////////////////////////////// | 
|---|
| 235 | //! Class for reading a 2D image from a FITS file | 
|---|
| 236 | class FitsImg2DRead : public FitsImg2DRd { | 
|---|
| 237 | public: | 
|---|
| 238 | FitsImg2DRead(string fname,int ihdu=0,int lp=0); | 
|---|
| 239 | FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0); | 
|---|
| 240 | FitsImg2DRead(FitsImg2DRead& fbt); | 
|---|
| 241 | FitsImg2DRead(); | 
|---|
| 242 | virtual ~FitsImg2DRead(); | 
|---|
| 243 | }; | 
|---|
| 244 |  | 
|---|
| 245 | } // namespace SOPHYA | 
|---|
| 246 | #endif    /* FABTCOLREAD_H_SEEN */ | 
|---|