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

Last change on this file since 3123 was 3114, checked in by cmv, 19 years ago

1-/ intro des reader et writer pour tableaux 3D
2-/ j enleve la variable redondante FitsPtr :

si travail OK c est une modif mineure
mais ca peut conduire a de gros PB si qquechose a ete oublie
ATTENTION ATTENTION MODIF .... cmv 13/12/2006

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