| 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 | ///////////////////////////////////////////////////////////////////////////
 | 
|---|
| 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 | 
 | 
|---|
| 29 | public:
 | 
|---|
| 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);
 | 
|---|
| 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);}
 | 
|---|
| 41 |   //! Set debug level
 | 
|---|
| 42 |   inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   //! Return the number of overflows managed by cfitsio
 | 
|---|
| 45 |   inline unsigned long GetNOverFlow(void) {return NOverFlow;}
 | 
|---|
| 46 | 
 | 
|---|
| 47 |   //! Return the c-fitsio file pointer
 | 
|---|
| 48 |   inline fitsfile * GetFitsPtr() { return FitsPtr; }
 | 
|---|
| 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 | 
 | 
|---|
| 88 |   //! Add a new column to the FITS table and return its number (see addcol).
 | 
|---|
| 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);}
 | 
|---|
| 92 |   //! Add a new column to the FITS table and return its number (see addcol).
 | 
|---|
| 93 |   inline int AddCol(const char* label,const char* tform=""
 | 
|---|
| 94 |                    ,const char* tunit="",int datatype=TDOUBLE)
 | 
|---|
| 95 |      {return addcol(label,tform,tunit,datatype);}
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   void Write(int col,long row,int_1 val);
 | 
|---|
| 98 |   void Write(int col,long row,uint_1 val);
 | 
|---|
| 99 |   void Write(int col,long row,int_2 val);
 | 
|---|
| 100 |   void Write(int col,long row,uint_2 val);
 | 
|---|
| 101 |   void Write(int col,long row,int_4 val);
 | 
|---|
| 102 |   void Write(int col,long row,uint_4 val);
 | 
|---|
| 103 |   void Write(int col,long row,int_8 val);
 | 
|---|
| 104 |   void Write(int col,long row,float val);
 | 
|---|
| 105 |   void Write(int col,long row,double val);
 | 
|---|
| 106 |   long Write(int col,long row,TVector<uint_2>& val);
 | 
|---|
| 107 |   long Write(int col,long row,TVector<int_4>& val);
 | 
|---|
| 108 |   long Write(int col,long row,TVector<int_8>& val);
 | 
|---|
| 109 |   long Write(int col,long row,TVector<float>& val);
 | 
|---|
| 110 |   long Write(int col,long row,TVector<double>& val);
 | 
|---|
| 111 | 
 | 
|---|
| 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 | 
 | 
|---|
| 120 | protected:
 | 
|---|
| 121 |   int addcol(const char* label,const char* tform,const char* tunit,int datatype);
 | 
|---|
| 122 |   void createtbl(void);
 | 
|---|
| 123 | 
 | 
|---|
| 124 |   bool FirstTime;
 | 
|---|
| 125 |   vector<string> Label;
 | 
|---|
| 126 |   vector<string> TForm;
 | 
|---|
| 127 |   vector<string> TUnit;
 | 
|---|
| 128 | };
 | 
|---|
| 129 | 
 | 
|---|
| 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;
 | 
|---|
| 157 | };
 | 
|---|
| 158 | 
 | 
|---|
| 159 | } // namespace SOPHYA
 | 
|---|
| 160 | #endif    /* FABTWRITER_H_SEEN */
 | 
|---|