[3493] | 1 | /*
|
---|
| 2 | --- SOPHYA software - FitsIOServer module ---
|
---|
| 3 | C. Magneville, 2001
|
---|
| 4 | (C) UPS+LAL IN2P3/CNRS (C) DAPNIA-SPP/CEA
|
---|
| 5 | */
|
---|
[1654] | 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"
|
---|
[2322] | 11 | #include <iostream>
|
---|
[1654] | 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 |
|
---|
| 21 | namespace SOPHYA {
|
---|
| 22 |
|
---|
[2453] | 23 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 24 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 25 | //! Class for writing into a FITS file (DO NOT USE)
|
---|
| 26 | class FitsWriter : public AnyDataObj {
|
---|
| 27 | protected:
|
---|
| 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 |
|
---|
[1654] | 34 | public:
|
---|
[1814] | 35 | void Flush(void);
|
---|
| 36 |
|
---|
| 37 | //! Write a double value in Fits header.
|
---|
[3572] | 38 | void WriteKey(const char *keyname,double val,const char* comment=NULL);
|
---|
[1814] | 39 | //! Write a long value in Fits header.
|
---|
[3572] | 40 | void WriteKey(const char *keyname,long val,const char* comment=NULL);
|
---|
[3128] | 41 | //! Write a long long value in Fits header.
|
---|
[3572] | 42 | void WriteKey(const char *keyname,LONGLONG val,const char* comment=NULL);
|
---|
[2450] | 43 | //! Write a string value in Fits header.
|
---|
[3572] | 44 | void WriteKey(const char *keyname,string val,const char* comment=NULL);
|
---|
[2450] | 45 | //! Write a character string value in Fits header.
|
---|
[3572] | 46 | inline void WriteKey(const char *keyname,const char* val,const char* comment=NULL)
|
---|
[2450] | 47 | {string dum=val; WriteKey(keyname,dum,comment);}
|
---|
[2453] | 48 | //! Set debug level
|
---|
| 49 | inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
|
---|
[1814] | 50 |
|
---|
[2453] | 51 | //! Return the number of overflows managed by cfitsio
|
---|
[3128] | 52 | inline LONGLONG GetNOverFlow(void) {return NOverFlow;}
|
---|
[2453] | 53 |
|
---|
[2782] | 54 | //! Return the c-fitsio file pointer
|
---|
| 55 | inline fitsfile * GetFitsPtr() { return FitsPtr; }
|
---|
[2453] | 56 | protected:
|
---|
[3128] | 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;};
|
---|
[2453] | 61 |
|
---|
| 62 | void cr_or_upd_fits(const char *cfname,bool update,int lp);
|
---|
| 63 |
|
---|
| 64 | void writekeys(void);
|
---|
[3128] | 65 | void printerrorwrite(const char* type,int col,LONGLONG row,int sta);
|
---|
[2453] | 66 | void printerror(int sta) const;
|
---|
| 67 |
|
---|
| 68 | string FitsFN,ExtName;
|
---|
| 69 | bool Update;
|
---|
| 70 | int HduType;
|
---|
| 71 | unsigned short DbgLevel;
|
---|
| 72 | fitsfile *FitsPtr;
|
---|
[3128] | 73 | LONGLONG NOverFlow;
|
---|
[2453] | 74 |
|
---|
[3128] | 75 | vector<struct KeyDouble> DoubleKey;
|
---|
| 76 | vector<struct KeyLong> LongKey;
|
---|
| 77 | vector<struct KeyLongLong> LongLongKey;
|
---|
| 78 | vector<struct KeyString> StringKey;
|
---|
[2453] | 79 | };
|
---|
| 80 |
|
---|
| 81 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 82 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 83 | //! Class for writing a FITS ASCII or BINARY table
|
---|
| 84 | class FitsABTWriter : public FitsWriter {
|
---|
| 85 | public:
|
---|
| 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
|
---|
[3572] | 95 | inline void SetExtName(const char* extname="") {ExtName = extname;}
|
---|
[2453] | 96 |
|
---|
[1654] | 97 | //! Add a new column to the FITS table and return its number (see addcol).
|
---|
[1660] | 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);}
|
---|
[1654] | 101 | //! Add a new column to the FITS table and return its number (see addcol).
|
---|
[1660] | 102 | inline int AddCol(const char* label,const char* tform=""
|
---|
| 103 | ,const char* tunit="",int datatype=TDOUBLE)
|
---|
| 104 | {return addcol(label,tform,tunit,datatype);}
|
---|
[1654] | 105 |
|
---|
[4025] | 106 | void Write(int col,LONGLONG row,long nfirstel,const char* val);
|
---|
| 107 | inline void Write(int col,LONGLONG row,const char* val)
|
---|
| 108 | {Write(col,row,0,val);}
|
---|
| 109 | inline void Write(int col,LONGLONG row,long nfirstel,string val)
|
---|
| 110 | {Write(col,row,nfirstel,val.c_str());}
|
---|
[4024] | 111 | inline void Write(int col,LONGLONG row,string val)
|
---|
[4025] | 112 | {Write(col,row,0,val.c_str());}
|
---|
[4024] | 113 |
|
---|
[4023] | 114 | void Write(int col,LONGLONG row,long nfirstel,int_1 val);
|
---|
| 115 | void Write(int col,LONGLONG row,long nfirstel,uint_1 val);
|
---|
| 116 | void Write(int col,LONGLONG row,long nfirstel,int_2 val);
|
---|
| 117 | void Write(int col,LONGLONG row,long nfirstel,uint_2 val);
|
---|
| 118 | void Write(int col,LONGLONG row,long nfirstel,int_4 val);
|
---|
| 119 | void Write(int col,LONGLONG row,long nfirstel,uint_4 val);
|
---|
| 120 | void Write(int col,LONGLONG row,long nfirstel,int_8 val);
|
---|
| 121 | void Write(int col,LONGLONG row,long nfirstel,float val);
|
---|
| 122 | void Write(int col,LONGLONG row,long nfirstel,double val);
|
---|
[4025] | 123 | void Write(int col,LONGLONG row,long nfirstel,complex<r_4> val);
|
---|
| 124 | void Write(int col,LONGLONG row,long nfirstel,complex<r_8> val);
|
---|
[4023] | 125 |
|
---|
| 126 | inline void Write(int col,LONGLONG row,int_1 val) {Write(col,row,0,val);}
|
---|
| 127 | inline void Write(int col,LONGLONG row,uint_1 val) {Write(col,row,0,val);}
|
---|
| 128 | inline void Write(int col,LONGLONG row,int_2 val) {Write(col,row,0,val);}
|
---|
| 129 | inline void Write(int col,LONGLONG row,uint_2 val) {Write(col,row,0,val);}
|
---|
| 130 | inline void Write(int col,LONGLONG row,int_4 val) {Write(col,row,0,val);}
|
---|
| 131 | inline void Write(int col,LONGLONG row,uint_4 val) {Write(col,row,0,val);}
|
---|
| 132 | inline void Write(int col,LONGLONG row,int_8 val) {Write(col,row,0,val);}
|
---|
| 133 | inline void Write(int col,LONGLONG row,float val) {Write(col,row,0,val);}
|
---|
| 134 | inline void Write(int col,LONGLONG row,double val) {Write(col,row,0,val);}
|
---|
[4025] | 135 | inline void Write(int col,LONGLONG row,complex<r_4> val) {Write(col,row,0,val);}
|
---|
| 136 | inline void Write(int col,LONGLONG row,complex<r_8> val) {Write(col,row,0,val);}
|
---|
[4023] | 137 |
|
---|
[3128] | 138 | LONGLONG Write(int col,LONGLONG row,TVector<uint_2>& val);
|
---|
| 139 | LONGLONG Write(int col,LONGLONG row,TVector<int_4>& val);
|
---|
| 140 | LONGLONG Write(int col,LONGLONG row,TVector<int_8>& val);
|
---|
| 141 | LONGLONG Write(int col,LONGLONG row,TVector<float>& val);
|
---|
| 142 | LONGLONG Write(int col,LONGLONG row,TVector<double>& val);
|
---|
[1654] | 143 |
|
---|
[1673] | 144 | //! Return the number of created columns
|
---|
| 145 | inline int GetNbCol(void) {return (int) Label.size();}
|
---|
| 146 |
|
---|
| 147 | //! Print to os
|
---|
| 148 | virtual void Print(ostream& os,int lp=1) const;
|
---|
| 149 | //! Print to stdout
|
---|
| 150 | inline void Print(int lp=1) const {Print(cout,lp);}
|
---|
| 151 |
|
---|
[1654] | 152 | protected:
|
---|
[2453] | 153 | int addcol(const char* label,const char* tform,const char* tunit,int datatype);
|
---|
[1654] | 154 | void createtbl(void);
|
---|
| 155 |
|
---|
| 156 | bool FirstTime;
|
---|
| 157 | vector<string> Label;
|
---|
| 158 | vector<string> TForm;
|
---|
| 159 | vector<string> TUnit;
|
---|
[2453] | 160 | };
|
---|
[1814] | 161 |
|
---|
[2453] | 162 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 163 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 164 | //! Class for writing a FITS Image
|
---|
| 165 | class FitsImg2DWriter : public FitsWriter {
|
---|
| 166 | public:
|
---|
| 167 | FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 168 | FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 169 | FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 170 | FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 171 | virtual ~FitsImg2DWriter();
|
---|
| 172 |
|
---|
[3668] | 173 | void Write(TMatrix<uint_1>& data);
|
---|
[2453] | 174 | void Write(TMatrix<uint_2>& data);
|
---|
| 175 | void Write(TMatrix<int_4>& data);
|
---|
| 176 | void Write(TMatrix<float>& data);
|
---|
| 177 | void Write(TMatrix<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;
|
---|
[3128] | 188 | LONGLONG Naxis[2];
|
---|
[2453] | 189 | bool FirstTime;
|
---|
[1654] | 190 | };
|
---|
| 191 |
|
---|
[3114] | 192 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 193 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 194 | //! Class for writing a FITS Image
|
---|
| 195 | class FitsImg3DWriter : public FitsWriter {
|
---|
| 196 | public:
|
---|
| 197 | FitsImg3DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 198 | FitsImg3DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 199 | FitsImg3DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 200 | FitsImg3DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0);
|
---|
| 201 | virtual ~FitsImg3DWriter();
|
---|
| 202 |
|
---|
[3668] | 203 | void CreateImg(LONGLONG naxis1,LONGLONG naxis2,LONGLONG naxis3);
|
---|
| 204 |
|
---|
| 205 | void Write(TArray<uint_1>& data);
|
---|
[3114] | 206 | void Write(TArray<uint_2>& data);
|
---|
| 207 | void Write(TArray<int_4>& data);
|
---|
| 208 | void Write(TArray<float>& data);
|
---|
| 209 | void Write(TArray<double>& data);
|
---|
| 210 |
|
---|
[3668] | 211 | void Write(LONGLONG j,LONGLONG k,TVector<uint_1>& data);
|
---|
| 212 | void Write(LONGLONG j,LONGLONG k,TVector<uint_2>& data);
|
---|
| 213 | void Write(LONGLONG j,LONGLONG k,TVector<int_4>& data);
|
---|
| 214 | void Write(LONGLONG j,LONGLONG k,TVector<float>& data);
|
---|
| 215 | void Write(LONGLONG j,LONGLONG k,TVector<double>& data);
|
---|
| 216 |
|
---|
[3114] | 217 | //! Print to os
|
---|
| 218 | virtual void Print(ostream& os) const;
|
---|
| 219 | //! Print to stdout
|
---|
| 220 | inline void Print(void) const {Print(cout);}
|
---|
| 221 |
|
---|
| 222 | protected:
|
---|
| 223 | void createimg(void);
|
---|
| 224 |
|
---|
| 225 | int BitPix;
|
---|
[3128] | 226 | LONGLONG Naxis[3];
|
---|
[3114] | 227 | bool FirstTime;
|
---|
| 228 | };
|
---|
| 229 |
|
---|
[1654] | 230 | } // namespace SOPHYA
|
---|
| 231 | #endif /* FABTWRITER_H_SEEN */
|
---|