source: Sophya/trunk/SophyaExt/FitsIOServer/fabtwriter.h@ 4024

Last change on this file since 4024 was 4024, checked in by cmv, 14 years ago

write chat strign into bintable, cmv 02/10/2011

File size: 8.3 KB
Line 
1/*
2 --- SOPHYA software - FitsIOServer module ---
3 C. Magneville, 2001
4 (C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA
5*/
6/* Interface Fits BINARY/ASCII Table Writer cmv 26/09/2001 */
7#ifndef FABTWRITER_H_SEEN
8#define FABTWRITER_H_SEEN
9
10#include "machdefs.h"
11#include <iostream>
12#include <string.h>
13#include <string>
14
15#include "anydataobj.h"
16#include "tvector.h"
17#include "FitsIO/fitsio.h"
18
19#include <vector>
20
21namespace SOPHYA {
22
23///////////////////////////////////////////////////////////////////////////
24///////////////////////////////////////////////////////////////////////////
25//! Class for writing into a FITS file (DO NOT USE)
26class FitsWriter : public AnyDataObj {
27protected:
28 FitsWriter(string fname,int lp=0);
29 FitsWriter(const char* cfname,int lp=0);
30 FitsWriter(string fname,bool update,int lp=0);
31 FitsWriter(const char* cfname,bool update,int lp=0);
32 virtual ~FitsWriter();
33
34public:
35 void Flush(void);
36
37 //! Write a double value in Fits header.
38 void WriteKey(const char *keyname,double val,const char* comment=NULL);
39 //! Write a long value in Fits header.
40 void WriteKey(const char *keyname,long val,const char* comment=NULL);
41 //! Write a long long value in Fits header.
42 void WriteKey(const char *keyname,LONGLONG val,const char* comment=NULL);
43 //! Write a string value in Fits header.
44 void WriteKey(const char *keyname,string val,const char* comment=NULL);
45 //! Write a character string value in Fits header.
46 inline void WriteKey(const char *keyname,const char* val,const char* comment=NULL)
47 {string dum=val; WriteKey(keyname,dum,comment);}
48 //! Set debug level
49 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
50
51 //! Return the number of overflows managed by cfitsio
52 inline LONGLONG GetNOverFlow(void) {return NOverFlow;}
53
54 //! Return the c-fitsio file pointer
55 inline fitsfile * GetFitsPtr() { return FitsPtr; }
56protected:
57 struct KeyDouble {string keyname; double val; string comment;};
58 struct KeyLong {string keyname; long val; string comment;};
59 struct KeyLongLong {string keyname; LONGLONG val; string comment;};
60 struct KeyString {string keyname; string val; string comment;};
61
62 void cr_or_upd_fits(const char *cfname,bool update,int lp);
63
64 void writekeys(void);
65 void printerrorwrite(const char* type,int col,LONGLONG row,int sta);
66 void printerror(int sta) const;
67
68 string FitsFN,ExtName;
69 bool Update;
70 int HduType;
71 unsigned short DbgLevel;
72 fitsfile *FitsPtr;
73 LONGLONG NOverFlow;
74
75 vector<struct KeyDouble> DoubleKey;
76 vector<struct KeyLong> LongKey;
77 vector<struct KeyLongLong> LongLongKey;
78 vector<struct KeyString> StringKey;
79};
80
81///////////////////////////////////////////////////////////////////////////
82///////////////////////////////////////////////////////////////////////////
83//! Class for writing a FITS ASCII or BINARY table
84class FitsABTWriter : public FitsWriter {
85public:
86 FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0);
87 FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0);
88 FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0);
89 FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0);
90 virtual ~FitsABTWriter();
91
92 //! Set the FITS table extension name
93 inline void SetExtName(string extname=string("")) {ExtName = extname;}
94 //! Set the FITS table extension name
95 inline void SetExtName(const char* extname="") {ExtName = extname;}
96
97 //! Add a new column to the FITS table and return its number (see addcol).
98 inline int AddCol(string label,string tform=string("")
99 ,string tunit=string(""),int datatype=TDOUBLE)
100 {return addcol(label.c_str(),tform.c_str(),tunit.c_str(),datatype);}
101 //! Add a new column to the FITS table and return its number (see addcol).
102 inline int AddCol(const char* label,const char* tform=""
103 ,const char* tunit="",int datatype=TDOUBLE)
104 {return addcol(label,tform,tunit,datatype);}
105
106 void Write(int col,LONGLONG row,const char* val);
107 inline void Write(int col,LONGLONG row,string val)
108 {Write(col,row,val.c_str());}
109
110 void Write(int col,LONGLONG row,long nfirstel,int_1 val);
111 void Write(int col,LONGLONG row,long nfirstel,uint_1 val);
112 void Write(int col,LONGLONG row,long nfirstel,int_2 val);
113 void Write(int col,LONGLONG row,long nfirstel,uint_2 val);
114 void Write(int col,LONGLONG row,long nfirstel,int_4 val);
115 void Write(int col,LONGLONG row,long nfirstel,uint_4 val);
116 void Write(int col,LONGLONG row,long nfirstel,int_8 val);
117 void Write(int col,LONGLONG row,long nfirstel,float val);
118 void Write(int col,LONGLONG row,long nfirstel,double val);
119
120 inline void Write(int col,LONGLONG row,int_1 val) {Write(col,row,0,val);}
121 inline void Write(int col,LONGLONG row,uint_1 val) {Write(col,row,0,val);}
122 inline void Write(int col,LONGLONG row,int_2 val) {Write(col,row,0,val);}
123 inline void Write(int col,LONGLONG row,uint_2 val) {Write(col,row,0,val);}
124 inline void Write(int col,LONGLONG row,int_4 val) {Write(col,row,0,val);}
125 inline void Write(int col,LONGLONG row,uint_4 val) {Write(col,row,0,val);}
126 inline void Write(int col,LONGLONG row,int_8 val) {Write(col,row,0,val);}
127 inline void Write(int col,LONGLONG row,float val) {Write(col,row,0,val);}
128 inline void Write(int col,LONGLONG row,double val) {Write(col,row,0,val);}
129
130 LONGLONG Write(int col,LONGLONG row,TVector<uint_2>& val);
131 LONGLONG Write(int col,LONGLONG row,TVector<int_4>& val);
132 LONGLONG Write(int col,LONGLONG row,TVector<int_8>& val);
133 LONGLONG Write(int col,LONGLONG row,TVector<float>& val);
134 LONGLONG Write(int col,LONGLONG row,TVector<double>& val);
135
136 //! Return the number of created columns
137 inline int GetNbCol(void) {return (int) Label.size();}
138
139 //! Print to os
140 virtual void Print(ostream& os,int lp=1) const;
141 //! Print to stdout
142 inline void Print(int lp=1) const {Print(cout,lp);}
143
144protected:
145 int addcol(const char* label,const char* tform,const char* tunit,int datatype);
146 void createtbl(void);
147
148 bool FirstTime;
149 vector<string> Label;
150 vector<string> TForm;
151 vector<string> TUnit;
152};
153
154///////////////////////////////////////////////////////////////////////////
155///////////////////////////////////////////////////////////////////////////
156//! Class for writing a FITS Image
157class FitsImg2DWriter : public FitsWriter {
158public:
159 FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
160 FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
161 FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
162 FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
163 virtual ~FitsImg2DWriter();
164
165 void Write(TMatrix<uint_1>& data);
166 void Write(TMatrix<uint_2>& data);
167 void Write(TMatrix<int_4>& data);
168 void Write(TMatrix<float>& data);
169 void Write(TMatrix<double>& data);
170
171 //! Print to os
172 virtual void Print(ostream& os) const;
173 //! Print to stdout
174 inline void Print(void) const {Print(cout);}
175
176protected:
177 void createimg(void);
178
179 int BitPix;
180 LONGLONG Naxis[2];
181 bool FirstTime;
182};
183
184///////////////////////////////////////////////////////////////////////////
185///////////////////////////////////////////////////////////////////////////
186//! Class for writing a FITS Image
187class FitsImg3DWriter : public FitsWriter {
188public:
189 FitsImg3DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
190 FitsImg3DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
191 FitsImg3DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
192 FitsImg3DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
193 virtual ~FitsImg3DWriter();
194
195 void CreateImg(LONGLONG naxis1,LONGLONG naxis2,LONGLONG naxis3);
196
197 void Write(TArray<uint_1>& data);
198 void Write(TArray<uint_2>& data);
199 void Write(TArray<int_4>& data);
200 void Write(TArray<float>& data);
201 void Write(TArray<double>& data);
202
203 void Write(LONGLONG j,LONGLONG k,TVector<uint_1>& data);
204 void Write(LONGLONG j,LONGLONG k,TVector<uint_2>& data);
205 void Write(LONGLONG j,LONGLONG k,TVector<int_4>& data);
206 void Write(LONGLONG j,LONGLONG k,TVector<float>& data);
207 void Write(LONGLONG j,LONGLONG k,TVector<double>& data);
208
209 //! Print to os
210 virtual void Print(ostream& os) const;
211 //! Print to stdout
212 inline void Print(void) const {Print(cout);}
213
214protected:
215 void createimg(void);
216
217 int BitPix;
218 LONGLONG Naxis[3];
219 bool FirstTime;
220};
221
222} // namespace SOPHYA
223#endif /* FABTWRITER_H_SEEN */
Note: See TracBrowser for help on using the repository browser.