[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 |
|
---|
[2456] | 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;}
|
---|
[2449] | 39 |
|
---|
[2456] | 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 |
|
---|
[2453] | 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 |
|
---|
[2449] | 50 | protected:
|
---|
| 51 | void Init(const char *cfname);
|
---|
| 52 | void Delete(void);
|
---|
| 53 |
|
---|
| 54 | string FitsFN;
|
---|
[2456] | 55 | int NHdu, IHdu, HduType;
|
---|
[2449] | 56 | fitsfile *FitsPtr;
|
---|
[2456] | 57 | bool HasBeenPos;
|
---|
[2449] | 58 | };
|
---|
| 59 |
|
---|
| 60 | ///////////////////////////////////////////////////////////////////
|
---|
[1654] | 61 | //! Class for reading a column in a FITS ASCII or BINARY table
|
---|
[2449] | 62 | class FitsABTColRd : public AnyDataObj {
|
---|
[1654] | 63 | public:
|
---|
[2449] | 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();
|
---|
[1654] | 71 |
|
---|
| 72 | void ChangeBuffer(long blen=100,long bsens=1);
|
---|
| 73 |
|
---|
[1814] | 74 | double ReadKey(char *keyname);
|
---|
[2451] | 75 | long ReadKeyL(char *keyname);
|
---|
| 76 | string ReadKeyS(char *keyname);
|
---|
[1814] | 77 |
|
---|
[1659] | 78 | double Read(long n,bool usebuffer=true);
|
---|
[2170] | 79 |
|
---|
[2456] | 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);
|
---|
[1654] | 85 |
|
---|
[1659] | 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 |
|
---|
[1654] | 96 | //! Set debug level
|
---|
[2456] | 97 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
[1654] | 98 | //! Set null value to be return when reading null data (0=return the data)
|
---|
[2456] | 99 | inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
|
---|
[1654] | 100 | //! Get the FITS file name
|
---|
[2456] | 101 | inline string FileName(void) const
|
---|
| 102 | {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
|
---|
[2449] | 103 | //! Get the pointer to FitsOpenFile
|
---|
[2456] | 104 | inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
|
---|
[1673] | 105 | //! Get the FITS file pointer (cfistio pointer)
|
---|
[2456] | 106 | inline fitsfile* GetFitsPtr(void) const {return FitsPtr;}
|
---|
[1654] | 107 | //! Get the number of HDU in the FITS file
|
---|
[2456] | 108 | inline int NHDU(void) const
|
---|
| 109 | {if(FitsOF) return FitsOF->NHDU(); else return 0;}
|
---|
[1654] | 110 | //! Get the number of the HDU read
|
---|
[2456] | 111 | inline int HDU(void) const
|
---|
| 112 | {if(FitsOF) return FitsOF->HDU(); else return 0;}
|
---|
[1654] | 113 | //! Get the HDU type
|
---|
[2456] | 114 | inline int HDUType(void) const
|
---|
| 115 | {if(FitsOF) return FitsOF->HDUType(); else return 0;}
|
---|
[1654] | 116 | //! Get the number of rows in the FITS HDU to be read
|
---|
[2456] | 117 | inline long GetNbLine(void) const {return NBline;}
|
---|
[1654] | 118 | //! Get the number of columns in the FITS HDU to be read
|
---|
[2456] | 119 | inline int GetNbCol(void) const {return NBcol;}
|
---|
[1654] | 120 | //! Get the columns number that is read
|
---|
[2456] | 121 | inline int GetColNum(void) const {return ColNum;}
|
---|
[1654] | 122 | //! Get the columns label that is read
|
---|
[2456] | 123 | inline string GetColLabel(void) const {return ColLabel;}
|
---|
[1654] | 124 | //! Get the columns type code that is read
|
---|
[2456] | 125 | inline int GetColTypeCode(void) const {return ColTypeCode;}
|
---|
[1654] | 126 | //! Get the columns fits tunit that is read
|
---|
[2456] | 127 | inline string GetColTUnit(void) const {return ColTUnit;}
|
---|
[1654] | 128 | //! Get the columns fits tform that is read
|
---|
[2456] | 129 | inline string GetColTForm(void) const {return ColTForm;}
|
---|
[1657] | 130 | //! Get the read requested buffer length
|
---|
[2456] | 131 | inline long GetBLen(void) const {return BuffLen;}
|
---|
[1654] | 132 | //! Get the read buffer direction
|
---|
[2456] | 133 | inline long GetBSens(void) const {return BuffSens;}
|
---|
[1654] | 134 | //! Print to os
|
---|
[2456] | 135 | virtual void Print(ostream& os,int lp=1) const;
|
---|
[1654] | 136 | //! Print to stdout
|
---|
[2456] | 137 | inline void Print(int lp=1) const {Print(cout,lp);}
|
---|
[1657] | 138 | //! Get the read effective buffer length
|
---|
[2456] | 139 | inline long GetNBuffer(void) const {return NBuffer;}
|
---|
[1654] | 140 | //! Get the read bufferpointer
|
---|
| 141 | inline double* GetBuffer(void) {return Buffer;}
|
---|
| 142 |
|
---|
| 143 | protected:
|
---|
[2449] | 144 | void Init(FitsOpenFile* fof,const char *collabel,int colnum
|
---|
[1654] | 145 | ,int ihdu,long blen,long bsens,int lp);
|
---|
| 146 | void Delete(void);
|
---|
| 147 |
|
---|
[2456] | 148 | string ColLabel,ColTUnit,ColTForm;
|
---|
| 149 | int ColNum,ColTypeCode,NBcol;
|
---|
[1654] | 150 | long NBline;
|
---|
| 151 |
|
---|
[1657] | 152 | double NulVal;
|
---|
| 153 | unsigned short DbgLevel;
|
---|
[1654] | 154 | long BuffLen, BuffSens;
|
---|
| 155 |
|
---|
[1657] | 156 | unsigned long NFitsRead;
|
---|
[2449] | 157 | FitsOpenFile* FitsOF;
|
---|
[2456] | 158 | fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
|
---|
[1654] | 159 | long LineDeb, LineFin;
|
---|
| 160 | double *Buffer;
|
---|
| 161 | long NBuffer;
|
---|
| 162 | };
|
---|
| 163 |
|
---|
[2449] | 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 |
|
---|
[2453] | 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 |
|
---|
[2456] | 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);
|
---|
[2453] | 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
|
---|
[2456] | 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;}
|
---|
[2453] | 212 | //! Get the number of the HDU read
|
---|
[2456] | 213 | inline int HDU(void) const
|
---|
| 214 | {if(FitsOF) return FitsOF->HDU(); else return 0;}
|
---|
[2453] | 215 | //! Get the HDU type
|
---|
[2456] | 216 | inline int HDUType(void) const
|
---|
| 217 | {if(FitsOF) return FitsOF->HDUType(); else return 0;}
|
---|
[2453] | 218 | //! Get NAXIS1
|
---|
[2456] | 219 | inline long Naxis1(void) const {return Naxis[0];}
|
---|
[2453] | 220 | //! Get NAXIS2
|
---|
[2456] | 221 | inline long Naxis2(void) const {return Naxis[1];}
|
---|
[2453] | 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;
|
---|
[2456] | 231 | fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
|
---|
[2453] | 232 | };
|
---|
[2591] | 233 |
|
---|
| 234 | } // namespace SOPHYA
|
---|
| 235 | #endif /* FABTCOLREAD_H_SEEN */
|
---|