[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 |
|
---|
[3128] | 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);
|
---|
[2453] | 49 | static void printerror(int sta);
|
---|
| 50 |
|
---|
[2449] | 51 | protected:
|
---|
| 52 | void Init(const char *cfname);
|
---|
| 53 | void Delete(void);
|
---|
| 54 |
|
---|
| 55 | string FitsFN;
|
---|
[2456] | 56 | int NHdu, IHdu, HduType;
|
---|
[2449] | 57 | fitsfile *FitsPtr;
|
---|
[2456] | 58 | bool HasBeenPos;
|
---|
[2449] | 59 | };
|
---|
| 60 |
|
---|
| 61 | ///////////////////////////////////////////////////////////////////
|
---|
[1654] | 62 | //! Class for reading a column in a FITS ASCII or BINARY table
|
---|
[2449] | 63 | class FitsABTColRd : public AnyDataObj {
|
---|
[1654] | 64 | public:
|
---|
[2449] | 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();
|
---|
[1654] | 72 |
|
---|
| 73 | void ChangeBuffer(long blen=100,long bsens=1);
|
---|
| 74 |
|
---|
[3128] | 75 | double ReadKey(char *keyname);
|
---|
| 76 | long ReadKeyL(char *keyname);
|
---|
| 77 | LONGLONG ReadKeyLL(char *keyname);
|
---|
| 78 | string ReadKeyS(char *keyname);
|
---|
[1814] | 79 |
|
---|
[3128] | 80 | double Read(LONGLONG n,bool usebuffer=true);
|
---|
[2170] | 81 |
|
---|
[3128] | 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);
|
---|
[1654] | 87 |
|
---|
[1659] | 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 |
|
---|
[3128] | 95 | LONGLONG FirstRow(double val1,double val2,LONGLONG rowstart=-1);
|
---|
| 96 | LONGLONG LastRow(double val1,double val2,LONGLONG rowstart=-1);
|
---|
[1659] | 97 |
|
---|
[1654] | 98 | //! Set debug level
|
---|
[2456] | 99 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
[1654] | 100 | //! Set null value to be return when reading null data (0=return the data)
|
---|
[2456] | 101 | inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
|
---|
[1654] | 102 | //! Get the FITS file name
|
---|
[2456] | 103 | inline string FileName(void) const
|
---|
| 104 | {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
|
---|
[2449] | 105 | //! Get the pointer to FitsOpenFile
|
---|
[2456] | 106 | inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
|
---|
[1673] | 107 | //! Get the FITS file pointer (cfistio pointer)
|
---|
[3114] | 108 | inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
|
---|
[1654] | 109 | //! Get the number of HDU in the FITS file
|
---|
[2456] | 110 | inline int NHDU(void) const
|
---|
| 111 | {if(FitsOF) return FitsOF->NHDU(); else return 0;}
|
---|
[1654] | 112 | //! Get the number of the HDU read
|
---|
[2456] | 113 | inline int HDU(void) const
|
---|
| 114 | {if(FitsOF) return FitsOF->HDU(); else return 0;}
|
---|
[1654] | 115 | //! Get the HDU type
|
---|
[2456] | 116 | inline int HDUType(void) const
|
---|
| 117 | {if(FitsOF) return FitsOF->HDUType(); else return 0;}
|
---|
[1654] | 118 | //! Get the number of rows in the FITS HDU to be read
|
---|
[3128] | 119 | inline LONGLONG GetNbLine(void) const {return NBline;}
|
---|
[1654] | 120 | //! Get the number of columns in the FITS HDU to be read
|
---|
[2456] | 121 | inline int GetNbCol(void) const {return NBcol;}
|
---|
[1654] | 122 | //! Get the columns number that is read
|
---|
[2456] | 123 | inline int GetColNum(void) const {return ColNum;}
|
---|
[1654] | 124 | //! Get the columns label that is read
|
---|
[2456] | 125 | inline string GetColLabel(void) const {return ColLabel;}
|
---|
[1654] | 126 | //! Get the columns type code that is read
|
---|
[2456] | 127 | inline int GetColTypeCode(void) const {return ColTypeCode;}
|
---|
[1654] | 128 | //! Get the columns fits tunit that is read
|
---|
[2456] | 129 | inline string GetColTUnit(void) const {return ColTUnit;}
|
---|
[1654] | 130 | //! Get the columns fits tform that is read
|
---|
[2456] | 131 | inline string GetColTForm(void) const {return ColTForm;}
|
---|
[1657] | 132 | //! Get the read requested buffer length
|
---|
[2456] | 133 | inline long GetBLen(void) const {return BuffLen;}
|
---|
[1654] | 134 | //! Get the read buffer direction
|
---|
[2456] | 135 | inline long GetBSens(void) const {return BuffSens;}
|
---|
[1654] | 136 | //! Print to os
|
---|
[2456] | 137 | virtual void Print(ostream& os,int lp=1) const;
|
---|
[1654] | 138 | //! Print to stdout
|
---|
[2456] | 139 | inline void Print(int lp=1) const {Print(cout,lp);}
|
---|
[1657] | 140 | //! Get the read effective buffer length
|
---|
[2456] | 141 | inline long GetNBuffer(void) const {return NBuffer;}
|
---|
[1654] | 142 | //! Get the read bufferpointer
|
---|
| 143 | inline double* GetBuffer(void) {return Buffer;}
|
---|
| 144 |
|
---|
| 145 | protected:
|
---|
[2449] | 146 | void Init(FitsOpenFile* fof,const char *collabel,int colnum
|
---|
[1654] | 147 | ,int ihdu,long blen,long bsens,int lp);
|
---|
| 148 | void Delete(void);
|
---|
| 149 |
|
---|
[2456] | 150 | string ColLabel,ColTUnit,ColTForm;
|
---|
| 151 | int ColNum,ColTypeCode,NBcol;
|
---|
[3128] | 152 | LONGLONG NBline;
|
---|
[1654] | 153 |
|
---|
[1657] | 154 | double NulVal;
|
---|
| 155 | unsigned short DbgLevel;
|
---|
[1654] | 156 | long BuffLen, BuffSens;
|
---|
| 157 |
|
---|
[3128] | 158 | LONGLONG NFitsRead;
|
---|
[2449] | 159 | FitsOpenFile* FitsOF;
|
---|
[3128] | 160 | LONGLONG LineDeb, LineFin;
|
---|
[1654] | 161 | double *Buffer;
|
---|
| 162 | long NBuffer;
|
---|
| 163 | };
|
---|
| 164 |
|
---|
[2449] | 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 |
|
---|
[2453] | 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 |
|
---|
[3128] | 192 | double ReadKey(char *keyname);
|
---|
| 193 | long ReadKeyL(char *keyname);
|
---|
| 194 | LONGLONG ReadKeyLL(char *keyname);
|
---|
| 195 | string ReadKeyS(char *keyname);
|
---|
[2453] | 196 |
|
---|
[3128] | 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);
|
---|
[3188] | 202 | double Read(LONGLONG numcol, LONGLONG numrow);
|
---|
[2453] | 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
|
---|
[2456] | 209 | inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
|
---|
| 210 | //! Get the FITS file pointer (cfistio pointer)
|
---|
[3114] | 211 | inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
|
---|
[2456] | 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;}
|
---|
[2453] | 215 | //! Get the number of the HDU read
|
---|
[2456] | 216 | inline int HDU(void) const
|
---|
| 217 | {if(FitsOF) return FitsOF->HDU(); else return 0;}
|
---|
[2453] | 218 | //! Get the HDU type
|
---|
[2456] | 219 | inline int HDUType(void) const
|
---|
| 220 | {if(FitsOF) return FitsOF->HDUType(); else return 0;}
|
---|
[2453] | 221 | //! Get NAXIS1
|
---|
[3128] | 222 | inline LONGLONG Naxis1(void) const {return Naxis[0];}
|
---|
[2453] | 223 | //! Get NAXIS2
|
---|
[3128] | 224 | inline LONGLONG Naxis2(void) const {return Naxis[1];}
|
---|
[2453] | 225 |
|
---|
| 226 | protected:
|
---|
| 227 | void Init(FitsOpenFile* fof,int ihdu,int lp);
|
---|
| 228 |
|
---|
[3128] | 229 | LONGLONG Naxis[2];
|
---|
[2453] | 230 | double NulVal;
|
---|
| 231 | unsigned short DbgLevel;
|
---|
| 232 |
|
---|
| 233 | FitsOpenFile* FitsOF;
|
---|
| 234 | };
|
---|
[2591] | 235 |
|
---|
[2791] | 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 |
|
---|
[3114] | 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 |
|
---|
[3128] | 257 | double ReadKey(char *keyname);
|
---|
| 258 | long ReadKeyL(char *keyname);
|
---|
| 259 | LONGLONG ReadKeyLL(char *keyname);
|
---|
| 260 | string ReadKeyS(char *keyname);
|
---|
[3114] | 261 |
|
---|
[3128] | 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);
|
---|
[3188] | 267 | double Read(LONGLONG i, LONGLONG j, LONGLONG k);
|
---|
[3114] | 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
|
---|
[3128] | 287 | inline LONGLONG Naxis1(void) const {return Naxis[0];}
|
---|
[3114] | 288 | //! Get NAXIS2
|
---|
[3128] | 289 | inline LONGLONG Naxis2(void) const {return Naxis[1];}
|
---|
[3114] | 290 | //! Get NAXIS3
|
---|
[3128] | 291 | inline LONGLONG Naxis3(void) const {return Naxis[2];}
|
---|
[3114] | 292 |
|
---|
| 293 | protected:
|
---|
| 294 | void Init(FitsOpenFile* fof,int ihdu,int lp);
|
---|
| 295 |
|
---|
[3128] | 296 | LONGLONG Naxis[3];
|
---|
[3114] | 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 |
|
---|
[2591] | 314 | } // namespace SOPHYA
|
---|
| 315 | #endif /* FABTCOLREAD_H_SEEN */
|
---|