/* --- SOPHYA software - FitsIOServer module --- C. Magneville, 2001 (C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA */ /* Interface Fits BINARY/ASCII Table Column Reader cmv 26/09/2001 */ #ifndef FABTCOLREAD_H_SEEN #define FABTCOLREAD_H_SEEN #include "machdefs.h" #include #include #include #include "anydataobj.h" #include "tvector.h" #include "FitsIO/fitsio.h" namespace SOPHYA { /////////////////////////////////////////////////////////////////// //! Class for opening a FITS file for reading class FitsOpenFile : public AnyDataObj { public: FitsOpenFile(string fname); FitsOpenFile(const char *cfname); FitsOpenFile(); FitsOpenFile(FitsOpenFile& fof); virtual ~FitsOpenFile(); inline string FileName() const {return FitsFN;} //! Get the number of the HDU read inline int HDU(void) const {return IHdu;} //! Get the number of the HDU type inline int HDUType(void) const {return HduType;} //! Get the number of HDU in file inline int NHDU() const {return NHdu;} //! Get the CFISTIO fits file pointer inline fitsfile* GetFitsPtr() const {return FitsPtr;} //! Set the positionning status of the file inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;} //! Get the positionning status of the file inline bool GetPosStatus(void) const {return HasBeenPos;} int MoveToHDU(int ihdu); int MoveToFirst(int hdutype,int ihdudeb=1); int MoveToLast(int hdutype,int ihdudeb=1); void Print(void); static double ReadKey(fitsfile *fitsptr,const char *keyname); static long ReadKeyL(fitsfile *fitsptr,const char *keyname); static LONGLONG ReadKeyLL(fitsfile *fitsptr,const char *keyname); static string ReadKeyS(fitsfile *fitsptr,const char *keyname); static void printerror(int sta); protected: void Init(const char *cfname); void Delete(void); string FitsFN; int NHdu, IHdu, HduType; fitsfile *FitsPtr; bool HasBeenPos; }; /////////////////////////////////////////////////////////////////// //! Class for reading a column in a FITS ASCII or BINARY table class FitsABTColRd : public AnyDataObj { public: FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0,int lp=0); FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0,int lp=0); FitsABTColRd(FitsABTColRd& fbt); FitsABTColRd(); virtual ~FitsABTColRd(); double ReadKey(const char *keyname); long ReadKeyL(const char *keyname); LONGLONG ReadKeyLL(const char *keyname); string ReadKeyS(const char *keyname); double Read(LONGLONG n,long nfirstel=0); int_8 ReadLL(LONGLONG n,long nfirstel=0); complex ReadComplex(LONGLONG n,long nfirstel=0); char* ReadInStr(LONGLONG n,long nfirstel=0); LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector& data); LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector& data); LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector& data); LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector& data); LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector& data); //! return the value of the first row double ReadFirstRow(long nfirstel) {return Read(0,nfirstel);} double ReadFirstRow(void) {return Read(0);} //! return the value of the last row double ReadLastRow(long nfirstel) {return Read(NBline-1,nfirstel);} double ReadLastRow(void) {return Read(NBline-1);} LONGLONG FirstRow(long nfirstel,double val1,double val2,LONGLONG rowstart=-1); inline LONGLONG FirstRow(double val1,double val2,LONGLONG rowstart=-1) {return FirstRow(0,val1,val2,rowstart);} LONGLONG LastRow(long nfirstel,double val1,double val2,LONGLONG rowstart=-1); inline LONGLONG LastRow(double val1,double val2,LONGLONG rowstart=-1) {return LastRow(0,val1,val2,rowstart);} //! Set debug level inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} //! Set null value to be return when reading null data (0=return the data) inline void SetNulVal(double nulval=0.) {NulVal = nulval;} //! Get the FITS file name inline string FileName(void) const {if(FitsOF) return FitsOF->FileName(); else return (string)"";} //! Get the pointer to FitsOpenFile inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} //! Get the FITS file pointer (cfistio pointer) inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();} //! Get the number of HDU in the FITS file inline int NHDU(void) const {if(FitsOF) return FitsOF->NHDU(); else return 0;} //! Get the number of the HDU read inline int HDU(void) const {if(FitsOF) return FitsOF->HDU(); else return 0;} //! Get the HDU type inline int HDUType(void) const {if(FitsOF) return FitsOF->HDUType(); else return 0;} //! Get the number of rows in the FITS HDU to be read inline LONGLONG GetNbLine(void) const {return NBline;} //! Get the number of columns in the FITS HDU to be read inline int GetNbCol(void) const {return NBcol;} //! Get the columns number that is read inline int GetColNum(void) const {return ColNum;} //! Get the columns label that is read inline string GetColLabel(void) const {return ColLabel;} //! Get the columns type code that is read inline int GetColTypeCode(void) const {return ColTypeCode;} //! Get the columns fits tunit that is read inline string GetColTUnit(void) const {return ColTUnit;} //! Get the columns fits tform that is read inline string GetColTForm(void) const {return ColTForm;} //! Get the columns fits repeat that is read inline long GetColRepeat(void) const {return ColRepeat;} //! Print to os virtual void Print(ostream& os,int lp=1) const; //! Print to stdout inline void Print(int lp=1) const {Print(cout,lp);} protected: void Init(FitsOpenFile* fof,const char *collabel,int colnum,int ihdu,int lp); void Delete(void); string ColLabel,ColTUnit,ColTForm; int ColNum,ColTypeCode,ColDispWidth,NBcol; long ColRepeat; LONGLONG NBline; char *StrBuff; double NulVal; unsigned short DbgLevel; LONGLONG NFitsRead; FitsOpenFile* FitsOF; }; /////////////////////////////////////////////////////////////////// //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening class FitsABTColRead : public FitsABTColRd { public: FitsABTColRead(string fname,string collabel,int ihdu=0,int lp=0); FitsABTColRead(string fname,int colnum,int ihdu=0,int lp=0); FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0,int lp=0); FitsABTColRead(const char *cfname,int colnum,int ihdu=0,int lp=0); FitsABTColRead(FitsABTColRead& fbt); FitsABTColRead(); virtual ~FitsABTColRead(); }; /////////////////////////////////////////////////////////////////// //! Class for reading ALL the columns in a FITS ASCII or BINARY table class FitsABTColRd1F : public AnyDataObj { public: FitsABTColRd1F(FitsOpenFile* fof,int ihdu=0,int lp=0); virtual ~FitsABTColRd1F(); double ReadKey(const char *keyname); long ReadKeyL(const char *keyname); LONGLONG ReadKeyLL(const char *keyname); string ReadKeyS(const char *keyname); double Read(int ColNum,LONGLONG n,long nfirstel=0); int_8 ReadLL(int ColNum,LONGLONG n,long nfirstel=0); complex ReadComplex(int ColNum,LONGLONG n,long nfirstel=0); char* ReadInStr(int ColNum,LONGLONG n,long nfirstel=0); int GetColNum(const char *colname); //! Set debug level inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} //! Set null value to be return when reading null data (0=return the data) inline void SetNulVal(double nulval=0.) {NulVal = nulval;} //! Get the FITS file name inline string FileName(void) const {if(FitsOF) return FitsOF->FileName(); else return (string)"";} //! Get the pointer to FitsOpenFile inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} //! Get the FITS file pointer (cfistio pointer) inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();} //! Get the number of HDU in the FITS file inline int NHDU(void) const {if(FitsOF) return FitsOF->NHDU(); else return 0;} //! Get the number of the HDU read inline int HDU(void) const {if(FitsOF) return FitsOF->HDU(); else return 0;} //! Get the HDU type inline int HDUType(void) const {if(FitsOF) return FitsOF->HDUType(); else return 0;} //! Get the number of rows in the FITS HDU to be read inline LONGLONG GetNbLine(void) const {return NBline;} //! Get the number of columns in the FITS HDU to be read inline int GetNbCol(void) const {return NBcol;} //! Get the columns label that is read inline string GetColLabel(int ColNum) const {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColLabel[ColNum];} //! Get the columns type code that is read inline int GetColTypeCode(int ColNum) const {if(ColNum<0 || ColNum>=NBcol) return -999; else return ColTypeCode[ColNum];} //! Get the columns fits tunit that is read inline string GetColTUnit(int ColNum) const {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColTUnit[ColNum];} //! Get the columns fits tform that is read inline string GetColTForm(int ColNum) const {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColTForm[ColNum];} //! Get the columns fits repeat that is read inline long GetColRepeat(int ColNum) const {if(ColNum<0 || ColNum>=NBcol) return -999; else return ColRepeat[ColNum];} //! Print to os virtual void Print(ostream& os,int lp=1) const; //! Print to stdout inline void Print(int lp=1) const {Print(cout,lp);} protected: void Init(FitsOpenFile* fof,int ihdu,int lp); void Delete(void); vector ColLabel,ColTUnit,ColTForm; vector ColTypeCode, ColDispWidth; vector ColRepeat; int NBcol; LONGLONG NBline; vector StrBuff; double NulVal; unsigned short DbgLevel; FitsOpenFile* FitsOF; }; /////////////////////////////////////////////////////////////////// //! Class for reading ALL the columns in a FITS ASCII or BINARY table with fits file opening class FitsABTColRead1F : public FitsABTColRd1F { public: FitsABTColRead1F(string fname,int ihdu=0,int lp=0); FitsABTColRead1F(const char *cfname,int ihdu=0,int lp=0); virtual ~FitsABTColRead1F(); }; /////////////////////////////////////////////////////////////////// //! Class for reading a 2D image from a FITS file class FitsImg2DRd : public AnyDataObj { public: FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0); FitsImg2DRd(FitsImg2DRd& fbt); FitsImg2DRd(); virtual ~FitsImg2DRd(); double ReadKey(const char *keyname); long ReadKeyL(const char *keyname); LONGLONG ReadKeyLL(const char *keyname); string ReadKeyS(const char *keyname); LONGLONG Read(TMatrix& data); LONGLONG Read(TMatrix& data); LONGLONG Read(TMatrix& data); LONGLONG Read(TMatrix& data); LONGLONG Read(TMatrix& data); double Read(LONGLONG numcol, LONGLONG numrow); //! Set debug level inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} //! Set null value to be return when reading null data (0=return the data) inline void SetNulVal(double nulval=0.) {NulVal = nulval;} //! Get the pointer to FitsOpenFile inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} //! Get the FITS file pointer (cfistio pointer) inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();} //! Get the number of HDU in the FITS file inline int NHDU(void) const {if(FitsOF) return FitsOF->NHDU(); else return 0;} //! Get the number of the HDU read inline int HDU(void) const {if(FitsOF) return FitsOF->HDU(); else return 0;} //! Get the HDU type inline int HDUType(void) const {if(FitsOF) return FitsOF->HDUType(); else return 0;} //! Get NAXIS1 inline LONGLONG Naxis1(void) const {return Naxis[0];} //! Get NAXIS2 inline LONGLONG Naxis2(void) const {return Naxis[1];} protected: void Init(FitsOpenFile* fof,int ihdu,int lp); LONGLONG Naxis[2]; double NulVal; unsigned short DbgLevel; FitsOpenFile* FitsOF; }; /////////////////////////////////////////////////////////////////// //! Class for reading a 2D image from a FITS file class FitsImg2DRead : public FitsImg2DRd { public: FitsImg2DRead(string fname,int ihdu=0,int lp=0); FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0); FitsImg2DRead(FitsImg2DRead& fbt); FitsImg2DRead(); virtual ~FitsImg2DRead(); }; /////////////////////////////////////////////////////////////////// //! Class for reading a 3D image from a FITS file class FitsImg3DRd : public AnyDataObj { public: FitsImg3DRd(FitsOpenFile* fof,int ihdu=0,int lp=0); FitsImg3DRd(FitsImg3DRd& fbt); FitsImg3DRd(); virtual ~FitsImg3DRd(); double ReadKey(const char *keyname); long ReadKeyL(const char *keyname); LONGLONG ReadKeyLL(const char *keyname); string ReadKeyS(const char *keyname); LONGLONG Read(TArray& data); LONGLONG Read(TArray& data); LONGLONG Read(TArray& data); LONGLONG Read(TArray& data); LONGLONG Read(TArray& data); LONGLONG Read(LONGLONG j, LONGLONG k, TVector& data); LONGLONG Read(LONGLONG j, LONGLONG k, TVector& data); LONGLONG Read(LONGLONG j, LONGLONG k, TVector& data); double Read(LONGLONG i, LONGLONG j, LONGLONG k); //! Set debug level inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} //! Set null value to be return when reading null data (0=return the data) inline void SetNulVal(double nulval=0.) {NulVal = nulval;} //! Get the pointer to FitsOpenFile inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;} //! Get the FITS file pointer (cfistio pointer) inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();} //! Get the number of HDU in the FITS file inline int NHDU(void) const {if(FitsOF) return FitsOF->NHDU(); else return 0;} //! Get the number of the HDU read inline int HDU(void) const {if(FitsOF) return FitsOF->HDU(); else return 0;} //! Get the HDU type inline int HDUType(void) const {if(FitsOF) return FitsOF->HDUType(); else return 0;} //! Get NAXIS1 inline LONGLONG Naxis1(void) const {return Naxis[0];} //! Get NAXIS2 inline LONGLONG Naxis2(void) const {return Naxis[1];} //! Get NAXIS3 inline LONGLONG Naxis3(void) const {return Naxis[2];} protected: void Init(FitsOpenFile* fof,int ihdu,int lp); LONGLONG Naxis[3]; double NulVal; unsigned short DbgLevel; FitsOpenFile* FitsOF; }; /////////////////////////////////////////////////////////////////// //! Class for reading a 3D image from a FITS file class FitsImg3DRead : public FitsImg3DRd { public: FitsImg3DRead(string fname,int ihdu=0,int lp=0); FitsImg3DRead(const char *cfname,int ihdu=0,int lp=0); FitsImg3DRead(FitsImg3DRead& fbt); FitsImg3DRead(); virtual ~FitsImg3DRead(); }; } // namespace SOPHYA #endif /* FABTCOLREAD_H_SEEN */