source: Sophya/trunk/SophyaExt/FitsIOServer/fabtcolread.h@ 3167

Last change on this file since 3167 was 3128, checked in by cmv, 19 years ago

gestion gros fichiers FITS dans fabtcolread et fabtwriter cmv 11/01/2007

File size: 10.8 KB
Line 
1/* Interface Fits BINARY/ASCII Table Column Reader cmv 26/09/2001 */
2#ifndef FABTCOLREAD_H_SEEN
3#define FABTCOLREAD_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
14namespace SOPHYA {
15
16///////////////////////////////////////////////////////////////////
17//! Class for opening a FITS file for reading
18class FitsOpenFile : public AnyDataObj {
19public:
20 FitsOpenFile(string fname);
21 FitsOpenFile(const char *cfname);
22 FitsOpenFile();
23 FitsOpenFile(FitsOpenFile& fof);
24 virtual ~FitsOpenFile();
25
26 inline string FileName() const {return FitsFN;}
27 //! Get the number of the HDU read
28 inline int HDU(void) const {return IHdu;}
29 //! Get the number of the HDU type
30 inline int HDUType(void) const {return HduType;}
31 //! Get the number of HDU in file
32 inline int NHDU() const {return NHdu;}
33 //! Get the CFISTIO fits file pointer
34 inline fitsfile* GetFitsPtr() const {return FitsPtr;}
35 //! Set the positionning status of the file
36 inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;}
37 //! Get the positionning status of the file
38 inline bool GetPosStatus(void) const {return HasBeenPos;}
39
40 int MoveToHDU(int ihdu);
41 int MoveToFirst(int hdutype,int ihdudeb=1);
42 int MoveToLast(int hdutype,int ihdudeb=1);
43 void Print(void);
44
45 static double ReadKey(fitsfile *fitsptr,char *keyname);
46 static long ReadKeyL(fitsfile *fitsptr,char *keyname);
47 static LONGLONG ReadKeyLL(fitsfile *fitsptr,char *keyname);
48 static string ReadKeyS(fitsfile *fitsptr,char *keyname);
49 static void printerror(int sta);
50
51protected:
52 void Init(const char *cfname);
53 void Delete(void);
54
55 string FitsFN;
56 int NHdu, IHdu, HduType;
57 fitsfile *FitsPtr;
58 bool HasBeenPos;
59};
60
61///////////////////////////////////////////////////////////////////
62//! Class for reading a column in a FITS ASCII or BINARY table
63class FitsABTColRd : public AnyDataObj {
64public:
65 FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
66 ,long blen=100,long bsens=1,int lp=0);
67 FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
68 ,long blen=100,long bsens=1,int lp=0);
69 FitsABTColRd(FitsABTColRd& fbt);
70 FitsABTColRd();
71 virtual ~FitsABTColRd();
72
73 void ChangeBuffer(long blen=100,long bsens=1);
74
75 double ReadKey(char *keyname);
76 long ReadKeyL(char *keyname);
77 LONGLONG ReadKeyLL(char *keyname);
78 string ReadKeyS(char *keyname);
79
80 double Read(LONGLONG n,bool usebuffer=true);
81
82 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<uint_2>& data);
83 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_4>& data);
84 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_8>& data);
85 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<float>& data);
86 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<double>& data);
87
88 //! return the value of the first row
89 double ReadFirstRow(bool usebuffer=false)
90 {return Read(0,usebuffer);}
91 //! return the value of the last row
92 double ReadLastRow(bool usebuffer=false)
93 {return Read(NBline-1,usebuffer);}
94
95 LONGLONG FirstRow(double val1,double val2,LONGLONG rowstart=-1);
96 LONGLONG LastRow(double val1,double val2,LONGLONG rowstart=-1);
97
98 //! Set debug level
99 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
100 //! Set null value to be return when reading null data (0=return the data)
101 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
102 //! Get the FITS file name
103 inline string FileName(void) const
104 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
105 //! Get the pointer to FitsOpenFile
106 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
107 //! Get the FITS file pointer (cfistio pointer)
108 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
109 //! Get the number of HDU in the FITS file
110 inline int NHDU(void) const
111 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
112 //! Get the number of the HDU read
113 inline int HDU(void) const
114 {if(FitsOF) return FitsOF->HDU(); else return 0;}
115 //! Get the HDU type
116 inline int HDUType(void) const
117 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
118 //! Get the number of rows in the FITS HDU to be read
119 inline LONGLONG GetNbLine(void) const {return NBline;}
120 //! Get the number of columns in the FITS HDU to be read
121 inline int GetNbCol(void) const {return NBcol;}
122 //! Get the columns number that is read
123 inline int GetColNum(void) const {return ColNum;}
124 //! Get the columns label that is read
125 inline string GetColLabel(void) const {return ColLabel;}
126 //! Get the columns type code that is read
127 inline int GetColTypeCode(void) const {return ColTypeCode;}
128 //! Get the columns fits tunit that is read
129 inline string GetColTUnit(void) const {return ColTUnit;}
130 //! Get the columns fits tform that is read
131 inline string GetColTForm(void) const {return ColTForm;}
132 //! Get the read requested buffer length
133 inline long GetBLen(void) const {return BuffLen;}
134 //! Get the read buffer direction
135 inline long GetBSens(void) const {return BuffSens;}
136 //! Print to os
137 virtual void Print(ostream& os,int lp=1) const;
138 //! Print to stdout
139 inline void Print(int lp=1) const {Print(cout,lp);}
140 //! Get the read effective buffer length
141 inline long GetNBuffer(void) const {return NBuffer;}
142 //! Get the read bufferpointer
143 inline double* GetBuffer(void) {return Buffer;}
144
145protected:
146 void Init(FitsOpenFile* fof,const char *collabel,int colnum
147 ,int ihdu,long blen,long bsens,int lp);
148 void Delete(void);
149
150 string ColLabel,ColTUnit,ColTForm;
151 int ColNum,ColTypeCode,NBcol;
152 LONGLONG NBline;
153
154 double NulVal;
155 unsigned short DbgLevel;
156 long BuffLen, BuffSens;
157
158 LONGLONG NFitsRead;
159 FitsOpenFile* FitsOF;
160 LONGLONG LineDeb, LineFin;
161 double *Buffer;
162 long NBuffer;
163};
164
165///////////////////////////////////////////////////////////////////
166//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
167class FitsABTColRead : public FitsABTColRd {
168public:
169 FitsABTColRead(string fname,string collabel,int ihdu=0
170 ,long blen=100,long bsens=1,int lp=0);
171 FitsABTColRead(string fname,int colnum,int ihdu=0
172 ,long blen=100,long bsens=1,int lp=0);
173 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
174 ,long blen=100,long bsens=1,int lp=0);
175 FitsABTColRead(const char *cfname,int colnum,int ihdu=0
176 ,long blen=100,long bsens=1,int lp=0);
177 FitsABTColRead(FitsABTColRead& fbt);
178 FitsABTColRead();
179 virtual ~FitsABTColRead();
180};
181
182
183///////////////////////////////////////////////////////////////////
184//! Class for reading a 2D image from a FITS file
185class FitsImg2DRd : public AnyDataObj {
186public:
187 FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
188 FitsImg2DRd(FitsImg2DRd& fbt);
189 FitsImg2DRd();
190 virtual ~FitsImg2DRd();
191
192 double ReadKey(char *keyname);
193 long ReadKeyL(char *keyname);
194 LONGLONG ReadKeyLL(char *keyname);
195 string ReadKeyS(char *keyname);
196
197 LONGLONG Read(TMatrix<uint_2>& data);
198 LONGLONG Read(TMatrix<int_4>& data);
199 LONGLONG Read(TMatrix<int_8>& data);
200 LONGLONG Read(TMatrix<float>& data);
201 LONGLONG Read(TMatrix<double>& data);
202
203 //! Set debug level
204 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
205 //! Set null value to be return when reading null data (0=return the data)
206 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
207 //! Get the pointer to FitsOpenFile
208 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
209 //! Get the FITS file pointer (cfistio pointer)
210 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
211 //! Get the number of HDU in the FITS file
212 inline int NHDU(void) const
213 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
214 //! Get the number of the HDU read
215 inline int HDU(void) const
216 {if(FitsOF) return FitsOF->HDU(); else return 0;}
217 //! Get the HDU type
218 inline int HDUType(void) const
219 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
220 //! Get NAXIS1
221 inline LONGLONG Naxis1(void) const {return Naxis[0];}
222 //! Get NAXIS2
223 inline LONGLONG Naxis2(void) const {return Naxis[1];}
224
225protected:
226 void Init(FitsOpenFile* fof,int ihdu,int lp);
227
228 LONGLONG Naxis[2];
229 double NulVal;
230 unsigned short DbgLevel;
231
232 FitsOpenFile* FitsOF;
233};
234
235///////////////////////////////////////////////////////////////////
236//! Class for reading a 2D image from a FITS file
237class FitsImg2DRead : public FitsImg2DRd {
238public:
239 FitsImg2DRead(string fname,int ihdu=0,int lp=0);
240 FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0);
241 FitsImg2DRead(FitsImg2DRead& fbt);
242 FitsImg2DRead();
243 virtual ~FitsImg2DRead();
244};
245
246
247///////////////////////////////////////////////////////////////////
248//! Class for reading a 3D image from a FITS file
249class FitsImg3DRd : public AnyDataObj {
250public:
251 FitsImg3DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
252 FitsImg3DRd(FitsImg3DRd& fbt);
253 FitsImg3DRd();
254 virtual ~FitsImg3DRd();
255
256 double ReadKey(char *keyname);
257 long ReadKeyL(char *keyname);
258 LONGLONG ReadKeyLL(char *keyname);
259 string ReadKeyS(char *keyname);
260
261 LONGLONG Read(TArray<uint_2>& data);
262 LONGLONG Read(TArray<int_4>& data);
263 LONGLONG Read(TArray<int_8>& data);
264 LONGLONG Read(TArray<float>& data);
265 LONGLONG Read(TArray<double>& data);
266
267 //! Set debug level
268 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
269 //! Set null value to be return when reading null data (0=return the data)
270 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
271 //! Get the pointer to FitsOpenFile
272 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
273 //! Get the FITS file pointer (cfistio pointer)
274 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
275 //! Get the number of HDU in the FITS file
276 inline int NHDU(void) const
277 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
278 //! Get the number of the HDU read
279 inline int HDU(void) const
280 {if(FitsOF) return FitsOF->HDU(); else return 0;}
281 //! Get the HDU type
282 inline int HDUType(void) const
283 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
284 //! Get NAXIS1
285 inline LONGLONG Naxis1(void) const {return Naxis[0];}
286 //! Get NAXIS2
287 inline LONGLONG Naxis2(void) const {return Naxis[1];}
288 //! Get NAXIS3
289 inline LONGLONG Naxis3(void) const {return Naxis[2];}
290
291protected:
292 void Init(FitsOpenFile* fof,int ihdu,int lp);
293
294 LONGLONG Naxis[3];
295 double NulVal;
296 unsigned short DbgLevel;
297
298 FitsOpenFile* FitsOF;
299};
300
301///////////////////////////////////////////////////////////////////
302//! Class for reading a 3D image from a FITS file
303class FitsImg3DRead : public FitsImg3DRd {
304public:
305 FitsImg3DRead(string fname,int ihdu=0,int lp=0);
306 FitsImg3DRead(const char *cfname,int ihdu=0,int lp=0);
307 FitsImg3DRead(FitsImg3DRead& fbt);
308 FitsImg3DRead();
309 virtual ~FitsImg3DRead();
310};
311
312} // namespace SOPHYA
313#endif /* FABTCOLREAD_H_SEEN */
Note: See TracBrowser for help on using the repository browser.