| [1654] | 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" | 
|---|
| [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 | #include <vector> | 
|---|
|  | 15 |  | 
|---|
|  | 16 | namespace SOPHYA { | 
|---|
|  | 17 |  | 
|---|
| [2453] | 18 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 19 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 20 | //! Class for writing into a FITS file (DO NOT USE) | 
|---|
|  | 21 | class FitsWriter : public AnyDataObj { | 
|---|
|  | 22 | protected: | 
|---|
|  | 23 | FitsWriter(string fname,int lp=0); | 
|---|
|  | 24 | FitsWriter(const char* cfname,int lp=0); | 
|---|
|  | 25 | FitsWriter(string fname,bool update,int lp=0); | 
|---|
|  | 26 | FitsWriter(const char* cfname,bool update,int lp=0); | 
|---|
|  | 27 | virtual ~FitsWriter(); | 
|---|
|  | 28 |  | 
|---|
| [1654] | 29 | public: | 
|---|
| [1814] | 30 | void Flush(void); | 
|---|
|  | 31 |  | 
|---|
|  | 32 | //! Write a double value in Fits header. | 
|---|
|  | 33 | void WriteKey(const char *keyname,double val,char* comment=NULL); | 
|---|
|  | 34 | //! Write a long value in Fits header. | 
|---|
|  | 35 | void WriteKey(const char *keyname,long val,char* comment=NULL); | 
|---|
| [2450] | 36 | //! Write a string value in Fits header. | 
|---|
|  | 37 | void WriteKey(const char *keyname,string val,char* comment=NULL); | 
|---|
|  | 38 | //! Write a character string value in Fits header. | 
|---|
|  | 39 | inline void WriteKey(const char *keyname,char* val,char* comment=NULL) | 
|---|
|  | 40 | {string dum=val; WriteKey(keyname,dum,comment);} | 
|---|
| [2453] | 41 | //! Set debug level | 
|---|
|  | 42 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} | 
|---|
| [1814] | 43 |  | 
|---|
| [2453] | 44 | //! Return the number of overflows managed by cfitsio | 
|---|
|  | 45 | inline unsigned long GetNOverFlow(void) {return NOverFlow;} | 
|---|
|  | 46 |  | 
|---|
| [2782] | 47 | //! Return the c-fitsio file pointer | 
|---|
|  | 48 | inline fitsfile * GetFitsPtr() { return FitsPtr; } | 
|---|
| [2453] | 49 | protected: | 
|---|
|  | 50 | struct KeyDouble {string keyname; double val; string comment;}; | 
|---|
|  | 51 | struct KeyLong   {string keyname; long   val; string comment;}; | 
|---|
|  | 52 | struct KeyString {string keyname; string val; string comment;}; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | void cr_or_upd_fits(const char *cfname,bool update,int lp); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | void writekeys(void); | 
|---|
|  | 57 | void printerrorwrite(const char* type,int col,long row,int sta); | 
|---|
|  | 58 | void printerror(int sta) const; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | string FitsFN,ExtName; | 
|---|
|  | 61 | bool Update; | 
|---|
|  | 62 | int HduType; | 
|---|
|  | 63 | unsigned short DbgLevel; | 
|---|
|  | 64 | fitsfile *FitsPtr; | 
|---|
|  | 65 | unsigned long NOverFlow; | 
|---|
|  | 66 |  | 
|---|
|  | 67 | vector<struct KeyDouble> DoubleKey; | 
|---|
|  | 68 | vector<struct KeyLong>   LongKey; | 
|---|
|  | 69 | vector<struct KeyString> StringKey; | 
|---|
|  | 70 | }; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 73 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 74 | //! Class for writing a FITS ASCII or BINARY table | 
|---|
|  | 75 | class FitsABTWriter : public FitsWriter { | 
|---|
|  | 76 | public: | 
|---|
|  | 77 | FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0); | 
|---|
|  | 78 | FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0); | 
|---|
|  | 79 | FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0); | 
|---|
|  | 80 | FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0); | 
|---|
|  | 81 | virtual ~FitsABTWriter(); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | //! Set the FITS table extension name | 
|---|
|  | 84 | inline void SetExtName(string extname=string("")) {ExtName = extname;} | 
|---|
|  | 85 | //! Set the FITS table extension name | 
|---|
|  | 86 | inline void SetExtName(char* extname="") {ExtName = extname;} | 
|---|
|  | 87 |  | 
|---|
| [1654] | 88 | //! Add a new column to the FITS table and return its number (see addcol). | 
|---|
| [1660] | 89 | inline int AddCol(string label,string tform=string("") | 
|---|
|  | 90 | ,string tunit=string(""),int datatype=TDOUBLE) | 
|---|
|  | 91 | {return addcol(label.c_str(),tform.c_str(),tunit.c_str(),datatype);} | 
|---|
| [1654] | 92 | //! Add a new column to the FITS table and return its number (see addcol). | 
|---|
| [1660] | 93 | inline int AddCol(const char* label,const char* tform="" | 
|---|
|  | 94 | ,const char* tunit="",int datatype=TDOUBLE) | 
|---|
|  | 95 | {return addcol(label,tform,tunit,datatype);} | 
|---|
| [1654] | 96 |  | 
|---|
| [2493] | 97 | void Write(int col,long row,int_1 val); | 
|---|
| [2174] | 98 | void Write(int col,long row,uint_1 val); | 
|---|
| [2170] | 99 | void Write(int col,long row,int_2 val); | 
|---|
|  | 100 | void Write(int col,long row,uint_2 val); | 
|---|
| [1657] | 101 | void Write(int col,long row,int_4 val); | 
|---|
| [2173] | 102 | void Write(int col,long row,uint_4 val); | 
|---|
| [2169] | 103 | void Write(int col,long row,int_8 val); | 
|---|
| [1657] | 104 | void Write(int col,long row,float val); | 
|---|
| [1654] | 105 | void Write(int col,long row,double val); | 
|---|
| [2170] | 106 | long Write(int col,long row,TVector<uint_2>& val); | 
|---|
| [1657] | 107 | long Write(int col,long row,TVector<int_4>& val); | 
|---|
| [2169] | 108 | long Write(int col,long row,TVector<int_8>& val); | 
|---|
| [1657] | 109 | long Write(int col,long row,TVector<float>& val); | 
|---|
|  | 110 | long Write(int col,long row,TVector<double>& val); | 
|---|
| [1654] | 111 |  | 
|---|
| [1673] | 112 | //! Return the number of created columns | 
|---|
|  | 113 | inline int GetNbCol(void) {return (int) Label.size();} | 
|---|
|  | 114 |  | 
|---|
|  | 115 | //! Print to os | 
|---|
|  | 116 | virtual void   Print(ostream& os,int lp=1) const; | 
|---|
|  | 117 | //! Print to stdout | 
|---|
|  | 118 | inline  void   Print(int lp=1) const {Print(cout,lp);} | 
|---|
|  | 119 |  | 
|---|
| [1654] | 120 | protected: | 
|---|
| [2453] | 121 | int addcol(const char* label,const char* tform,const char* tunit,int datatype); | 
|---|
| [1654] | 122 | void createtbl(void); | 
|---|
|  | 123 |  | 
|---|
|  | 124 | bool FirstTime; | 
|---|
|  | 125 | vector<string> Label; | 
|---|
|  | 126 | vector<string> TForm; | 
|---|
|  | 127 | vector<string> TUnit; | 
|---|
| [2453] | 128 | }; | 
|---|
| [1814] | 129 |  | 
|---|
| [2453] | 130 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 131 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 132 | //! Class for writing a FITS Image | 
|---|
|  | 133 | class FitsImg2DWriter : public FitsWriter { | 
|---|
|  | 134 | public: | 
|---|
|  | 135 | FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0); | 
|---|
|  | 136 | FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0); | 
|---|
|  | 137 | FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0); | 
|---|
|  | 138 | FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0); | 
|---|
|  | 139 | virtual ~FitsImg2DWriter(); | 
|---|
|  | 140 |  | 
|---|
|  | 141 | void Write(TMatrix<uint_2>& data); | 
|---|
|  | 142 | void Write(TMatrix<int_4>& data); | 
|---|
|  | 143 | void Write(TMatrix<float>& data); | 
|---|
|  | 144 | void Write(TMatrix<double>& data); | 
|---|
|  | 145 |  | 
|---|
|  | 146 | //! Print to os | 
|---|
|  | 147 | virtual void   Print(ostream& os) const; | 
|---|
|  | 148 | //! Print to stdout | 
|---|
|  | 149 | inline  void   Print(void) const {Print(cout);} | 
|---|
|  | 150 |  | 
|---|
|  | 151 | protected: | 
|---|
|  | 152 | void createimg(void); | 
|---|
|  | 153 |  | 
|---|
|  | 154 | int BitPix; | 
|---|
|  | 155 | long Naxis[2]; | 
|---|
|  | 156 | bool FirstTime; | 
|---|
| [1654] | 157 | }; | 
|---|
|  | 158 |  | 
|---|
|  | 159 | } // namespace SOPHYA | 
|---|
|  | 160 | #endif    /* FABTWRITER_H_SEEN */ | 
|---|