[1654] | 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"
|
---|
[2322] | 6 | #include <iostream>
|
---|
[1654] | 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 |
|
---|
[2449] | 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 GetFileName() {return FitsFN;}
|
---|
| 27 | inline int GetNHdu() {return NHdu;}
|
---|
| 28 | inline fitsfile* GetFitsPtr() {return FitsPtr;}
|
---|
| 29 |
|
---|
[2453] | 30 | static double ReadKey(fitsfile *fitsptr,char *keyname);
|
---|
| 31 | static long ReadKeyL(fitsfile *fitsptr,char *keyname);
|
---|
| 32 | static string ReadKeyS(fitsfile *fitsptr,char *keyname);
|
---|
| 33 | static void printerror(int sta);
|
---|
| 34 |
|
---|
[2449] | 35 | protected:
|
---|
| 36 | void Init(const char *cfname);
|
---|
| 37 | void Delete(void);
|
---|
| 38 |
|
---|
| 39 | string FitsFN;
|
---|
| 40 | int NHdu;
|
---|
| 41 | fitsfile *FitsPtr;
|
---|
| 42 | };
|
---|
| 43 |
|
---|
| 44 | ///////////////////////////////////////////////////////////////////
|
---|
[1654] | 45 | //! Class for reading a column in a FITS ASCII or BINARY table
|
---|
[2449] | 46 | class FitsABTColRd : public AnyDataObj {
|
---|
[1654] | 47 | public:
|
---|
[2449] | 48 | FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
|
---|
| 49 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 50 | FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
|
---|
| 51 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 52 | FitsABTColRd(FitsABTColRd& fbt);
|
---|
| 53 | FitsABTColRd();
|
---|
| 54 | virtual ~FitsABTColRd();
|
---|
[1654] | 55 |
|
---|
| 56 | void ChangeBuffer(long blen=100,long bsens=1);
|
---|
| 57 |
|
---|
[1814] | 58 | double ReadKey(char *keyname);
|
---|
[2451] | 59 | long ReadKeyL(char *keyname);
|
---|
| 60 | string ReadKeyS(char *keyname);
|
---|
[1814] | 61 |
|
---|
[1659] | 62 | double Read(long n,bool usebuffer=true);
|
---|
[2170] | 63 |
|
---|
| 64 | long Read(long n1,long n2,TVector<uint_2>& data);
|
---|
[1659] | 65 | long Read(long n1,long n2,TVector<int_4>& data);
|
---|
[2169] | 66 | long Read(long n1,long n2,TVector<int_8>& data);
|
---|
[2170] | 67 | long Read(long n1,long n2,TVector<float>& data);
|
---|
| 68 | long Read(long n1,long n2,TVector<double>& data);
|
---|
[1654] | 69 |
|
---|
[1659] | 70 | //! return the value of the first row
|
---|
| 71 | double ReadFirstRow(bool usebuffer=false)
|
---|
| 72 | {return Read(0,usebuffer);}
|
---|
| 73 | //! return the value of the last row
|
---|
| 74 | double ReadLastRow(bool usebuffer=false)
|
---|
| 75 | {return Read(NBline-1,usebuffer);}
|
---|
| 76 |
|
---|
| 77 | long FirstRow(double val1,double val2,long rowstart=-1);
|
---|
| 78 | long LastRow(double val1,double val2,long rowstart=-1);
|
---|
| 79 |
|
---|
[1654] | 80 | //! Set debug level
|
---|
[1657] | 81 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
[1654] | 82 | //! Set null value to be return when reading null data (0=return the data)
|
---|
[1657] | 83 | inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
|
---|
[1654] | 84 | //! Get the FITS file name
|
---|
| 85 | inline string GetFileName(void) {return FitsFN;}
|
---|
[2449] | 86 | //! Get the pointer to FitsOpenFile
|
---|
| 87 | inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
|
---|
[1673] | 88 | //! Get the FITS file pointer (cfistio pointer)
|
---|
| 89 | inline fitsfile* GetFitsPointer(void) {return FitsPtr;}
|
---|
[1654] | 90 | //! Get the number of HDU in the FITS file
|
---|
| 91 | inline int GetNHDU(void) {return NHdu;}
|
---|
| 92 | //! Get the number of the HDU read
|
---|
| 93 | inline int GetHDU(void) {return IHdu;}
|
---|
| 94 | //! Get the HDU type
|
---|
| 95 | inline int GetHDUType(void) {return HduType;}
|
---|
| 96 | //! Get the number of rows in the FITS HDU to be read
|
---|
| 97 | inline long GetNbLine(void) {return NBline;}
|
---|
| 98 | //! Get the number of columns in the FITS HDU to be read
|
---|
| 99 | inline int GetNbCol(void) {return NBcol;}
|
---|
| 100 | //! Get the columns number that is read
|
---|
| 101 | inline int GetColNum(void) {return ColNum;}
|
---|
| 102 | //! Get the columns label that is read
|
---|
| 103 | inline string GetColLabel(void) {return ColLabel;}
|
---|
| 104 | //! Get the columns type code that is read
|
---|
| 105 | inline int GetColTypeCode(void) {return ColTypeCode;}
|
---|
| 106 | //! Get the columns fits tunit that is read
|
---|
| 107 | inline string GetColTUnit(void) {return ColTUnit;}
|
---|
| 108 | //! Get the columns fits tform that is read
|
---|
| 109 | inline string GetColTForm(void) {return ColTForm;}
|
---|
[1657] | 110 | //! Get the read requested buffer length
|
---|
[1654] | 111 | inline long GetBLen(void) {return BuffLen;}
|
---|
| 112 | //! Get the read buffer direction
|
---|
| 113 | inline long GetBSens(void) {return BuffSens;}
|
---|
| 114 | //! Print to os
|
---|
| 115 | virtual void Print(ostream& os,int lp=1) const;
|
---|
| 116 | //! Print to stdout
|
---|
| 117 | inline void Print(int lp=1) const {Print(cout,lp);}
|
---|
[1657] | 118 | //! Get the read effective buffer length
|
---|
| 119 | inline long GetNBuffer(void) {return NBuffer;}
|
---|
[1654] | 120 | //! Get the read bufferpointer
|
---|
| 121 | inline double* GetBuffer(void) {return Buffer;}
|
---|
| 122 |
|
---|
| 123 | protected:
|
---|
[2449] | 124 | void Init(FitsOpenFile* fof,const char *collabel,int colnum
|
---|
[1654] | 125 | ,int ihdu,long blen,long bsens,int lp);
|
---|
| 126 | void Delete(void);
|
---|
| 127 |
|
---|
| 128 | string FitsFN,ColLabel,ColTUnit,ColTForm;
|
---|
| 129 | int ColNum,ColTypeCode,IHdu,NHdu,HduType,NBcol;
|
---|
| 130 | long NBline;
|
---|
| 131 |
|
---|
[1657] | 132 | double NulVal;
|
---|
| 133 | unsigned short DbgLevel;
|
---|
[1654] | 134 | long BuffLen, BuffSens;
|
---|
| 135 |
|
---|
[1657] | 136 | unsigned long NFitsRead;
|
---|
[2449] | 137 | FitsOpenFile* FitsOF;
|
---|
| 138 | fitsfile* FitsPtr;
|
---|
[1654] | 139 | long LineDeb, LineFin;
|
---|
| 140 | double *Buffer;
|
---|
| 141 | long NBuffer;
|
---|
| 142 | };
|
---|
| 143 |
|
---|
[2449] | 144 | ///////////////////////////////////////////////////////////////////
|
---|
| 145 | //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
|
---|
| 146 | class FitsABTColRead : public FitsABTColRd {
|
---|
| 147 | public:
|
---|
| 148 | FitsABTColRead(string fname,string collabel,int ihdu=0
|
---|
| 149 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 150 | FitsABTColRead(string fname,int colnum,int ihdu=0
|
---|
| 151 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 152 | FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
|
---|
| 153 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 154 | FitsABTColRead(const char *cfname,int colnum,int ihdu=0
|
---|
| 155 | ,long blen=100,long bsens=1,int lp=0);
|
---|
| 156 | FitsABTColRead(FitsABTColRead& fbt);
|
---|
| 157 | FitsABTColRead();
|
---|
| 158 | virtual ~FitsABTColRead();
|
---|
| 159 | };
|
---|
| 160 |
|
---|
[1654] | 161 | } // namespace SOPHYA
|
---|
| 162 | #endif /* FABTCOLREAD_H_SEEN */
|
---|
[2453] | 163 |
|
---|
| 164 | ///////////////////////////////////////////////////////////////////
|
---|
| 165 | //! Class for reading a 2D image from a FITS file
|
---|
| 166 | class FitsImg2DRd : public AnyDataObj {
|
---|
| 167 | public:
|
---|
| 168 | FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
|
---|
| 169 | FitsImg2DRd(FitsImg2DRd& fbt);
|
---|
| 170 | FitsImg2DRd();
|
---|
| 171 | virtual ~FitsImg2DRd();
|
---|
| 172 |
|
---|
| 173 | double ReadKey(char *keyname);
|
---|
| 174 | long ReadKeyL(char *keyname);
|
---|
| 175 | string ReadKeyS(char *keyname);
|
---|
| 176 |
|
---|
| 177 | long Read(TMatrix<uint_2>& data);
|
---|
| 178 | long Read(TMatrix<int_4>& data);
|
---|
| 179 | long Read(TMatrix<int_8>& data);
|
---|
| 180 | long Read(TMatrix<float>& data);
|
---|
| 181 | long Read(TMatrix<double>& data);
|
---|
| 182 |
|
---|
| 183 | //! Set debug level
|
---|
| 184 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
| 185 | //! Set null value to be return when reading null data (0=return the data)
|
---|
| 186 | inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
|
---|
| 187 | //! Get the pointer to FitsOpenFile
|
---|
| 188 | inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
|
---|
| 189 | //! Get the number of the HDU read
|
---|
| 190 | inline int GetHDU(void) {return IHdu;}
|
---|
| 191 | //! Get the HDU type
|
---|
| 192 | inline int GetHDUType(void) {return HduType;}
|
---|
| 193 | //! Get NAXIS1
|
---|
| 194 | inline long GetNaxis1(void) {return Naxis[0];}
|
---|
| 195 | //! Get NAXIS2
|
---|
| 196 | inline long GetNaxis2(void) {return Naxis[1];}
|
---|
| 197 |
|
---|
| 198 | protected:
|
---|
| 199 | void Init(FitsOpenFile* fof,int ihdu,int lp);
|
---|
| 200 |
|
---|
| 201 | string FitsFN;
|
---|
| 202 | int IHdu,NHdu,HduType;
|
---|
| 203 | long Naxis[2];
|
---|
| 204 |
|
---|
| 205 | double NulVal;
|
---|
| 206 | unsigned short DbgLevel;
|
---|
| 207 |
|
---|
| 208 | FitsOpenFile* FitsOF;
|
---|
| 209 | fitsfile* FitsPtr;
|
---|
| 210 | };
|
---|