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

Last change on this file since 2683 was 2493, checked in by cmv, 22 years ago

add int_2 in writer cmv 6/1/04

File size: 5.5 KB
Line 
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
16namespace SOPHYA {
17
18///////////////////////////////////////////////////////////////////////////
19///////////////////////////////////////////////////////////////////////////
20//! Class for writing into a FITS file (DO NOT USE)
21class FitsWriter : public AnyDataObj {
22protected:
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
29public:
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
47protected:
48 struct KeyDouble {string keyname; double val; string comment;};
49 struct KeyLong {string keyname; long val; string comment;};
50 struct KeyString {string keyname; string val; string comment;};
51
52 void cr_or_upd_fits(const char *cfname,bool update,int lp);
53
54 void writekeys(void);
55 void printerrorwrite(const char* type,int col,long row,int sta);
56 void printerror(int sta) const;
57
58 string FitsFN,ExtName;
59 bool Update;
60 int HduType;
61 unsigned short DbgLevel;
62 fitsfile *FitsPtr;
63 unsigned long NOverFlow;
64
65 vector<struct KeyDouble> DoubleKey;
66 vector<struct KeyLong> LongKey;
67 vector<struct KeyString> StringKey;
68};
69
70///////////////////////////////////////////////////////////////////////////
71///////////////////////////////////////////////////////////////////////////
72//! Class for writing a FITS ASCII or BINARY table
73class FitsABTWriter : public FitsWriter {
74public:
75 FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0);
76 FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0);
77 FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0);
78 FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0);
79 virtual ~FitsABTWriter();
80
81 //! Set the FITS table extension name
82 inline void SetExtName(string extname=string("")) {ExtName = extname;}
83 //! Set the FITS table extension name
84 inline void SetExtName(char* extname="") {ExtName = extname;}
85
86 //! Add a new column to the FITS table and return its number (see addcol).
87 inline int AddCol(string label,string tform=string("")
88 ,string tunit=string(""),int datatype=TDOUBLE)
89 {return addcol(label.c_str(),tform.c_str(),tunit.c_str(),datatype);}
90 //! Add a new column to the FITS table and return its number (see addcol).
91 inline int AddCol(const char* label,const char* tform=""
92 ,const char* tunit="",int datatype=TDOUBLE)
93 {return addcol(label,tform,tunit,datatype);}
94
95 void Write(int col,long row,int_1 val);
96 void Write(int col,long row,uint_1 val);
97 void Write(int col,long row,int_2 val);
98 void Write(int col,long row,uint_2 val);
99 void Write(int col,long row,int_4 val);
100 void Write(int col,long row,uint_4 val);
101 void Write(int col,long row,int_8 val);
102 void Write(int col,long row,float val);
103 void Write(int col,long row,double val);
104 long Write(int col,long row,TVector<uint_2>& val);
105 long Write(int col,long row,TVector<int_4>& val);
106 long Write(int col,long row,TVector<int_8>& val);
107 long Write(int col,long row,TVector<float>& val);
108 long Write(int col,long row,TVector<double>& val);
109
110 //! Return the number of created columns
111 inline int GetNbCol(void) {return (int) Label.size();}
112
113 //! Print to os
114 virtual void Print(ostream& os,int lp=1) const;
115 //! Print to stdout
116 inline void Print(int lp=1) const {Print(cout,lp);}
117
118protected:
119 int addcol(const char* label,const char* tform,const char* tunit,int datatype);
120 void createtbl(void);
121
122 bool FirstTime;
123 vector<string> Label;
124 vector<string> TForm;
125 vector<string> TUnit;
126};
127
128///////////////////////////////////////////////////////////////////////////
129///////////////////////////////////////////////////////////////////////////
130//! Class for writing a FITS Image
131class FitsImg2DWriter : public FitsWriter {
132public:
133 FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
134 FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
135 FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
136 FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
137 virtual ~FitsImg2DWriter();
138
139 void Write(TMatrix<uint_2>& data);
140 void Write(TMatrix<int_4>& data);
141 void Write(TMatrix<float>& data);
142 void Write(TMatrix<double>& data);
143
144 //! Print to os
145 virtual void Print(ostream& os) const;
146 //! Print to stdout
147 inline void Print(void) const {Print(cout);}
148
149protected:
150 void createimg(void);
151
152 int BitPix;
153 long Naxis[2];
154 bool FirstTime;
155};
156
157} // namespace SOPHYA
158#endif /* FABTWRITER_H_SEEN */
Note: See TracBrowser for help on using the repository browser.