| 1 | /* Interface Fits BINARY/ASCII Table Writer    cmv 26/09/2001 */ | 
|---|
| 2 | #ifndef FABTWRITER_H_SEEN | 
|---|
| 3 | #define FABTWRITER_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 | #include <vector> | 
|---|
| 15 |  | 
|---|
| 16 | namespace SOPHYA { | 
|---|
| 17 |  | 
|---|
| 18 | //! Class for writing a FITS ASCII or BINARY table | 
|---|
| 19 | class FitsABTWriter : public AnyDataObj { | 
|---|
| 20 | public: | 
|---|
| 21 | FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0); | 
|---|
| 22 | FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0); | 
|---|
| 23 | virtual ~FitsABTWriter(); | 
|---|
| 24 |  | 
|---|
| 25 | void Flush(void); | 
|---|
| 26 |  | 
|---|
| 27 | //! Write a double value in Fits header. | 
|---|
| 28 | void WriteKey(const char *keyname,double val,char* comment=NULL); | 
|---|
| 29 | //! Write a long value in Fits header. | 
|---|
| 30 | void WriteKey(const char *keyname,long val,char* comment=NULL); | 
|---|
| 31 |  | 
|---|
| 32 | //! Add a new column to the FITS table and return its number (see addcol). | 
|---|
| 33 | inline int AddCol(string label,string tform=string("") | 
|---|
| 34 | ,string tunit=string(""),int datatype=TDOUBLE) | 
|---|
| 35 | {return addcol(label.c_str(),tform.c_str(),tunit.c_str(),datatype);} | 
|---|
| 36 | //! Add a new column to the FITS table and return its number (see addcol). | 
|---|
| 37 | inline int AddCol(const char* label,const char* tform="" | 
|---|
| 38 | ,const char* tunit="",int datatype=TDOUBLE) | 
|---|
| 39 | {return addcol(label,tform,tunit,datatype);} | 
|---|
| 40 |  | 
|---|
| 41 | //! Set the FITS table extension name | 
|---|
| 42 | inline void SetExtName(string extname=string("")) {ExtName = extname;} | 
|---|
| 43 | //! Set the FITS table extension name | 
|---|
| 44 | inline void SetExtName(char* extname="") {ExtName = extname;} | 
|---|
| 45 | //! Set debug level | 
|---|
| 46 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} | 
|---|
| 47 |  | 
|---|
| 48 | void Write(int col,long row,uint_1 val); | 
|---|
| 49 | void Write(int col,long row,int_2 val); | 
|---|
| 50 | void Write(int col,long row,uint_2 val); | 
|---|
| 51 | void Write(int col,long row,int_4 val); | 
|---|
| 52 | void Write(int col,long row,uint_4 val); | 
|---|
| 53 | void Write(int col,long row,int_8 val); | 
|---|
| 54 | void Write(int col,long row,float val); | 
|---|
| 55 | void Write(int col,long row,double val); | 
|---|
| 56 | long Write(int col,long row,TVector<uint_2>& val); | 
|---|
| 57 | long Write(int col,long row,TVector<int_4>& val); | 
|---|
| 58 | long Write(int col,long row,TVector<int_8>& val); | 
|---|
| 59 | long Write(int col,long row,TVector<float>& val); | 
|---|
| 60 | long Write(int col,long row,TVector<double>& val); | 
|---|
| 61 | //! Return the number of overflows managed by cfitsio | 
|---|
| 62 | inline unsigned long GetNOverFlow(void) {return NOverFlow;} | 
|---|
| 63 |  | 
|---|
| 64 | //! Return the number of created columns | 
|---|
| 65 | inline int GetNbCol(void) {return (int) Label.size();} | 
|---|
| 66 |  | 
|---|
| 67 | //! Print to os | 
|---|
| 68 | virtual void   Print(ostream& os,int lp=1) const; | 
|---|
| 69 | //! Print to stdout | 
|---|
| 70 | inline  void   Print(int lp=1) const {Print(cout,lp);} | 
|---|
| 71 |  | 
|---|
| 72 | protected: | 
|---|
| 73 | struct KeyDouble {string keyname; double val; string comment;}; | 
|---|
| 74 | struct KeyLong   {string keyname; long   val; string comment;}; | 
|---|
| 75 |  | 
|---|
| 76 | void createfits(const char *cfname,int hdutype,int lp); | 
|---|
| 77 | int addcol(const char* label,const char* tform | 
|---|
| 78 | ,const char* tunit,int datatype); | 
|---|
| 79 | void createtbl(void); | 
|---|
| 80 | void writekeys(void); | 
|---|
| 81 | void printerrorwrite(const char* type,int col,long row,int sta); | 
|---|
| 82 | void printerror(int sta) const; | 
|---|
| 83 |  | 
|---|
| 84 | string FitsFN,ExtName; | 
|---|
| 85 | int HduType; | 
|---|
| 86 | unsigned short DbgLevel; | 
|---|
| 87 | fitsfile *FitsPtr; | 
|---|
| 88 | bool FirstTime; | 
|---|
| 89 | vector<string> Label; | 
|---|
| 90 | vector<string> TForm; | 
|---|
| 91 | vector<string> TUnit; | 
|---|
| 92 | unsigned long NOverFlow; | 
|---|
| 93 |  | 
|---|
| 94 | vector<struct KeyDouble> DoubleKey; | 
|---|
| 95 | vector<struct KeyLong>   LongKey; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | } // namespace SOPHYA | 
|---|
| 99 | #endif    /* FABTWRITER_H_SEEN */ | 
|---|