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 long long value in Fits header.
|
---|
37 | void WriteKey(const char *keyname,LONGLONG val,char* comment=NULL);
|
---|
38 | //! Write a string value in Fits header.
|
---|
39 | void WriteKey(const char *keyname,string val,char* comment=NULL);
|
---|
40 | //! Write a character string value in Fits header.
|
---|
41 | inline void WriteKey(const char *keyname,char* val,char* comment=NULL)
|
---|
42 | {string dum=val; WriteKey(keyname,dum,comment);}
|
---|
43 | //! Set debug level
|
---|
44 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
45 |
|
---|
46 | //! Return the number of overflows managed by cfitsio
|
---|
47 | inline LONGLONG GetNOverFlow(void) {return NOverFlow;}
|
---|
48 |
|
---|
49 | //! Return the c-fitsio file pointer
|
---|
50 | inline fitsfile * GetFitsPtr() { return FitsPtr; }
|
---|
51 | protected:
|
---|
52 | struct KeyDouble {string keyname; double val; string comment;};
|
---|
53 | struct KeyLong {string keyname; long val; string comment;};
|
---|
54 | struct KeyLongLong {string keyname; LONGLONG val; string comment;};
|
---|
55 | struct KeyString {string keyname; string val; string comment;};
|
---|
56 |
|
---|
57 | void cr_or_upd_fits(const char *cfname,bool update,int lp);
|
---|
58 |
|
---|
59 | void writekeys(void);
|
---|
60 | void printerrorwrite(const char* type,int col,LONGLONG row,int sta);
|
---|
61 | void printerror(int sta) const;
|
---|
62 |
|
---|
63 | string FitsFN,ExtName;
|
---|
64 | bool Update;
|
---|
65 | int HduType;
|
---|
66 | unsigned short DbgLevel;
|
---|
67 | fitsfile *FitsPtr;
|
---|
68 | LONGLONG NOverFlow;
|
---|
69 |
|
---|
70 | vector<struct KeyDouble> DoubleKey;
|
---|
71 | vector<struct KeyLong> LongKey;
|
---|
72 | vector<struct KeyLongLong> LongLongKey;
|
---|
73 | vector<struct KeyString> StringKey;
|
---|
74 | };
|
---|
75 |
|
---|
76 | ///////////////////////////////////////////////////////////////////////////
|
---|
77 | ///////////////////////////////////////////////////////////////////////////
|
---|
78 | //! Class for writing a FITS ASCII or BINARY table
|
---|
79 | class FitsABTWriter : public FitsWriter {
|
---|
80 | public:
|
---|
81 | FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0);
|
---|
82 | FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0);
|
---|
83 | FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0);
|
---|
84 | FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0);
|
---|
85 | virtual ~FitsABTWriter();
|
---|
86 |
|
---|
87 | //! Set the FITS table extension name
|
---|
88 | inline void SetExtName(string extname=string("")) {ExtName = extname;}
|
---|
89 | //! Set the FITS table extension name
|
---|
90 | inline void SetExtName(char* extname="") {ExtName = extname;}
|
---|
91 |
|
---|
92 | //! Add a new column to the FITS table and return its number (see addcol).
|
---|
93 | inline int AddCol(string label,string tform=string("")
|
---|
94 | ,string tunit=string(""),int datatype=TDOUBLE)
|
---|
95 | {return addcol(label.c_str(),tform.c_str(),tunit.c_str(),datatype);}
|
---|
96 | //! Add a new column to the FITS table and return its number (see addcol).
|
---|
97 | inline int AddCol(const char* label,const char* tform=""
|
---|
98 | ,const char* tunit="",int datatype=TDOUBLE)
|
---|
99 | {return addcol(label,tform,tunit,datatype);}
|
---|
100 |
|
---|
101 | void Write(int col,LONGLONG row,int_1 val);
|
---|
102 | void Write(int col,LONGLONG row,uint_1 val);
|
---|
103 | void Write(int col,LONGLONG row,int_2 val);
|
---|
104 | void Write(int col,LONGLONG row,uint_2 val);
|
---|
105 | void Write(int col,LONGLONG row,int_4 val);
|
---|
106 | void Write(int col,LONGLONG row,uint_4 val);
|
---|
107 | void Write(int col,LONGLONG row,int_8 val);
|
---|
108 | void Write(int col,LONGLONG row,float val);
|
---|
109 | void Write(int col,LONGLONG row,double val);
|
---|
110 | LONGLONG Write(int col,LONGLONG row,TVector<uint_2>& val);
|
---|
111 | LONGLONG Write(int col,LONGLONG row,TVector<int_4>& val);
|
---|
112 | LONGLONG Write(int col,LONGLONG row,TVector<int_8>& val);
|
---|
113 | LONGLONG Write(int col,LONGLONG row,TVector<float>& val);
|
---|
114 | LONGLONG Write(int col,LONGLONG row,TVector<double>& val);
|
---|
115 |
|
---|
116 | //! Return the number of created columns
|
---|
117 | inline int GetNbCol(void) {return (int) Label.size();}
|
---|
118 |
|
---|
119 | //! Print to os
|
---|
120 | virtual void Print(ostream& os,int lp=1) const;
|
---|
121 | //! Print to stdout
|
---|
122 | inline void Print(int lp=1) const {Print(cout,lp);}
|
---|
123 |
|
---|
124 | protected:
|
---|
125 | int addcol(const char* label,const char* tform,const char* tunit,int datatype);
|
---|
126 | void createtbl(void);
|
---|
127 |
|
---|
128 | bool FirstTime;
|
---|
129 | vector<string> Label;
|
---|
130 | vector<string> TForm;
|
---|
131 | vector<string> TUnit;
|
---|
132 | };
|
---|
133 |
|
---|
134 | ///////////////////////////////////////////////////////////////////////////
|
---|
135 | ///////////////////////////////////////////////////////////////////////////
|
---|
136 | //! Class for writing a FITS Image
|
---|
137 | class FitsImg2DWriter : public FitsWriter {
|
---|
138 | public:
|
---|
139 | FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
140 | FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
141 | FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
142 | FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
143 | virtual ~FitsImg2DWriter();
|
---|
144 |
|
---|
145 | void Write(TMatrix<uint_2>& data);
|
---|
146 | void Write(TMatrix<int_4>& data);
|
---|
147 | void Write(TMatrix<float>& data);
|
---|
148 | void Write(TMatrix<double>& data);
|
---|
149 |
|
---|
150 | //! Print to os
|
---|
151 | virtual void Print(ostream& os) const;
|
---|
152 | //! Print to stdout
|
---|
153 | inline void Print(void) const {Print(cout);}
|
---|
154 |
|
---|
155 | protected:
|
---|
156 | void createimg(void);
|
---|
157 |
|
---|
158 | int BitPix;
|
---|
159 | LONGLONG Naxis[2];
|
---|
160 | bool FirstTime;
|
---|
161 | };
|
---|
162 |
|
---|
163 | ///////////////////////////////////////////////////////////////////////////
|
---|
164 | ///////////////////////////////////////////////////////////////////////////
|
---|
165 | //! Class for writing a FITS Image
|
---|
166 | class FitsImg3DWriter : public FitsWriter {
|
---|
167 | public:
|
---|
168 | FitsImg3DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
169 | FitsImg3DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
170 | FitsImg3DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
171 | FitsImg3DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
172 | virtual ~FitsImg3DWriter();
|
---|
173 |
|
---|
174 | void Write(TArray<uint_2>& data);
|
---|
175 | void Write(TArray<int_4>& data);
|
---|
176 | void Write(TArray<float>& data);
|
---|
177 | void Write(TArray<double>& data);
|
---|
178 |
|
---|
179 | //! Print to os
|
---|
180 | virtual void Print(ostream& os) const;
|
---|
181 | //! Print to stdout
|
---|
182 | inline void Print(void) const {Print(cout);}
|
---|
183 |
|
---|
184 | protected:
|
---|
185 | void createimg(void);
|
---|
186 |
|
---|
187 | int BitPix;
|
---|
188 | LONGLONG Naxis[3];
|
---|
189 | bool FirstTime;
|
---|
190 | };
|
---|
191 |
|
---|
192 | } // namespace SOPHYA
|
---|
193 | #endif /* FABTWRITER_H_SEEN */
|
---|