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

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

bintable avec elements vecteur, cmv 02/10/2011

File size: 16.2 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 Column Reader cmv 26/09/2001 */
7#ifndef FABTCOLREAD_H_SEEN
8#define FABTCOLREAD_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
19namespace SOPHYA {
20
21///////////////////////////////////////////////////////////////////
22//! Class for opening a FITS file for reading
23class FitsOpenFile : public AnyDataObj {
24public:
25 FitsOpenFile(string fname);
26 FitsOpenFile(const char *cfname);
27 FitsOpenFile();
28 FitsOpenFile(FitsOpenFile& fof);
29 virtual ~FitsOpenFile();
30
31 inline string FileName() const {return FitsFN;}
32 //! Get the number of the HDU read
33 inline int HDU(void) const {return IHdu;}
34 //! Get the number of the HDU type
35 inline int HDUType(void) const {return HduType;}
36 //! Get the number of HDU in file
37 inline int NHDU() const {return NHdu;}
38 //! Get the CFISTIO fits file pointer
39 inline fitsfile* GetFitsPtr() const {return FitsPtr;}
40 //! Set the positionning status of the file
41 inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;}
42 //! Get the positionning status of the file
43 inline bool GetPosStatus(void) const {return HasBeenPos;}
44
45 int MoveToHDU(int ihdu);
46 int MoveToFirst(int hdutype,int ihdudeb=1);
47 int MoveToLast(int hdutype,int ihdudeb=1);
48 void Print(void);
49
50 static double ReadKey(fitsfile *fitsptr,const char *keyname);
51 static long ReadKeyL(fitsfile *fitsptr,const char *keyname);
52 static LONGLONG ReadKeyLL(fitsfile *fitsptr,const char *keyname);
53 static string ReadKeyS(fitsfile *fitsptr,const char *keyname);
54 static void printerror(int sta);
55
56protected:
57 void Init(const char *cfname);
58 void Delete(void);
59
60 string FitsFN;
61 int NHdu, IHdu, HduType;
62 fitsfile *FitsPtr;
63 bool HasBeenPos;
64};
65
66///////////////////////////////////////////////////////////////////
67//! Class for reading a column in a FITS ASCII or BINARY table
68class FitsABTColRd : public AnyDataObj {
69public:
70 FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
71 ,long blen=100,long bsens=1,int lp=0);
72 FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
73 ,long blen=100,long bsens=1,int lp=0);
74 FitsABTColRd(FitsABTColRd& fbt);
75 FitsABTColRd();
76 virtual ~FitsABTColRd();
77
78 void ChangeBuffer(long blen=100,long bsens=1);
79
80 double ReadKey(const char *keyname);
81 long ReadKeyL(const char *keyname);
82 LONGLONG ReadKeyLL(const char *keyname);
83 string ReadKeyS(const char *keyname);
84
85 double Read(LONGLONG n,long nfirstel,bool usebuffer=true);
86 inline double Read(LONGLONG n,bool usebuffer=true) {return Read(n,0,usebuffer);}
87
88 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<uint_2>& data);
89 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_4>& data);
90 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<int_8>& data);
91 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<float>& data);
92 LONGLONG Read(LONGLONG n1,LONGLONG n2,TVector<double>& data);
93
94 //! return the value of the first row
95 double ReadFirstRow(long nfirstel,bool usebuffer=false) {return Read(0,nfirstel,usebuffer);}
96 double ReadFirstRow(bool usebuffer=false) {return Read(0,usebuffer);}
97 //! return the value of the last row
98 double ReadLastRow(long nfirstel,bool usebuffer=false) {return Read(NBline-1,nfirstel,usebuffer);}
99 double ReadLastRow(bool usebuffer=false) {return Read(NBline-1,usebuffer);}
100
101 LONGLONG FirstRow(long nfirstel,double val1,double val2,LONGLONG rowstart=-1);
102 inline LONGLONG FirstRow(double val1,double val2,LONGLONG rowstart=-1)
103 {return FirstRow(0,val1,val2,rowstart);}
104 LONGLONG LastRow(long nfirstel,double val1,double val2,LONGLONG rowstart=-1);
105 inline LONGLONG LastRow(double val1,double val2,LONGLONG rowstart=-1)
106 {return LastRow(0,val1,val2,rowstart);}
107
108 //! Set debug level
109 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
110 //! Set null value to be return when reading null data (0=return the data)
111 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
112 //! Get the FITS file name
113 inline string FileName(void) const
114 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
115 //! Get the pointer to FitsOpenFile
116 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
117 //! Get the FITS file pointer (cfistio pointer)
118 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
119 //! Get the number of HDU in the FITS file
120 inline int NHDU(void) const
121 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
122 //! Get the number of the HDU read
123 inline int HDU(void) const
124 {if(FitsOF) return FitsOF->HDU(); else return 0;}
125 //! Get the HDU type
126 inline int HDUType(void) const
127 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
128 //! Get the number of rows in the FITS HDU to be read
129 inline LONGLONG GetNbLine(void) const {return NBline;}
130 //! Get the number of columns in the FITS HDU to be read
131 inline int GetNbCol(void) const {return NBcol;}
132 //! Get the columns number that is read
133 inline int GetColNum(void) const {return ColNum;}
134 //! Get the columns label that is read
135 inline string GetColLabel(void) const {return ColLabel;}
136 //! Get the columns type code that is read
137 inline int GetColTypeCode(void) const {return ColTypeCode;}
138 //! Get the columns fits tunit that is read
139 inline string GetColTUnit(void) const {return ColTUnit;}
140 //! Get the columns fits tform that is read
141 inline string GetColTForm(void) const {return ColTForm;}
142 //! Get the columns fits repeat that is read
143 inline long GetColRepeat(void) const {return ColRepeat;}
144 //! Get the read requested buffer length
145 inline long GetBLen(void) const {return BuffLen;}
146 //! Get the read buffer direction
147 inline long GetBSens(void) const {return BuffSens;}
148 //! Print to os
149 virtual void Print(ostream& os,int lp=1) const;
150 //! Print to stdout
151 inline void Print(int lp=1) const {Print(cout,lp);}
152 //! Get the read effective buffer length
153 inline long GetNBuffer(void) const {return NBuffer;}
154 //! Get the read bufferpointer
155 inline double* GetBuffer(void) {return Buffer;}
156
157protected:
158 void Init(FitsOpenFile* fof,const char *collabel,int colnum
159 ,int ihdu,long blen,long bsens,int lp);
160 void Delete(void);
161
162 string ColLabel,ColTUnit,ColTForm;
163 int ColNum,ColTypeCode,NBcol;
164 long ColRepeat;
165 LONGLONG NBline;
166
167 double NulVal;
168 unsigned short DbgLevel;
169 long BuffLen, BuffSens;
170
171 LONGLONG NFitsRead;
172 FitsOpenFile* FitsOF;
173 LONGLONG LineDeb, LineFin;
174 double *Buffer;
175 long NBuffer;
176};
177
178///////////////////////////////////////////////////////////////////
179//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
180class FitsABTColRead : public FitsABTColRd {
181public:
182 FitsABTColRead(string fname,string collabel,int ihdu=0
183 ,long blen=100,long bsens=1,int lp=0);
184 FitsABTColRead(string fname,int colnum,int ihdu=0
185 ,long blen=100,long bsens=1,int lp=0);
186 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
187 ,long blen=100,long bsens=1,int lp=0);
188 FitsABTColRead(const char *cfname,int colnum,int ihdu=0
189 ,long blen=100,long bsens=1,int lp=0);
190 FitsABTColRead(FitsABTColRead& fbt);
191 FitsABTColRead();
192 virtual ~FitsABTColRead();
193};
194
195
196///////////////////////////////////////////////////////////////////
197//! Class for reading ALL the columns in a FITS ASCII or BINARY table
198class FitsABTColRd1F : public AnyDataObj {
199public:
200 FitsABTColRd1F(FitsOpenFile* fof,int ihdu=0
201 ,long blen=100,long bsens=1,int lp=0);
202 virtual ~FitsABTColRd1F();
203
204 void ChangeBuffer(long blen=100,long bsens=1);
205
206 double ReadKey(const char *keyname);
207 long ReadKeyL(const char *keyname);
208 LONGLONG ReadKeyLL(const char *keyname);
209 string ReadKeyS(const char *keyname);
210
211 double Read(int ColNum,LONGLONG n,long nfirstel,bool usebuffer=true);
212 inline double Read(int ColNum,LONGLONG n,bool usebuffer=true) {return Read(ColNum,n,0,usebuffer);}
213 int GetColNum(const char *colname);
214
215 //! Set debug level
216 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
217 //! Set null value to be return when reading null data (0=return the data)
218 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
219 //! Get the FITS file name
220 inline string FileName(void) const
221 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
222 //! Get the pointer to FitsOpenFile
223 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
224 //! Get the FITS file pointer (cfistio pointer)
225 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
226 //! Get the number of HDU in the FITS file
227 inline int NHDU(void) const
228 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
229 //! Get the number of the HDU read
230 inline int HDU(void) const
231 {if(FitsOF) return FitsOF->HDU(); else return 0;}
232 //! Get the HDU type
233 inline int HDUType(void) const
234 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
235 //! Get the number of rows in the FITS HDU to be read
236 inline LONGLONG GetNbLine(void) const {return NBline;}
237 //! Get the number of columns in the FITS HDU to be read
238 inline int GetNbCol(void) const {return NBcol;}
239 //! Get the columns label that is read
240 inline string GetColLabel(int ColNum) const
241 {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColLabel[ColNum];}
242 //! Get the columns type code that is read
243 inline int GetColTypeCode(int ColNum) const
244 {if(ColNum<0 || ColNum>=NBcol) return -999; else return ColTypeCode[ColNum];}
245 //! Get the columns fits tunit that is read
246 inline string GetColTUnit(int ColNum) const
247 {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColTUnit[ColNum];}
248 //! Get the columns fits tform that is read
249 inline string GetColTForm(int ColNum) const
250 {if(ColNum<0 || ColNum>=NBcol) return string(""); else return ColTForm[ColNum];}
251 //! Get the columns fits repeat that is read
252 inline long GetColRepeat(int ColNum) const
253 {if(ColNum<0 || ColNum>=NBcol) return -999; else return ColRepeat[ColNum];}
254 //! Get the read requested buffer length
255 inline long GetBLen(void) const {return BuffLen;}
256 //! Get the read buffer direction
257 inline long GetBSens(void) const {return BuffSens;}
258 //! Print to os
259 virtual void Print(ostream& os,int lp=1) const;
260 //! Print to stdout
261 inline void Print(int lp=1) const {Print(cout,lp);}
262 //! Get the read effective buffer length
263 inline long GetNBuffer(void) const {return NBuffer;}
264 //! Get the read bufferpointer
265 inline double* GetBuffer(int ColNum)
266 {if(ColNum<0 || ColNum>=NBcol) return NULL; else return Buffer[ColNum];}
267
268protected:
269 void Init(FitsOpenFile* fof,int ihdu,long blen,long bsens,int lp);
270 void Delete(void);
271
272 vector<string> ColLabel,ColTUnit,ColTForm;
273 vector<int> ColTypeCode;
274 vector<long> ColRepeat;
275 int NBcol;
276 LONGLONG NBline;
277
278 double NulVal;
279 unsigned short DbgLevel;
280 long BuffLen, BuffSens;
281
282 FitsOpenFile* FitsOF;
283 vector<LONGLONG> LineDeb, LineFin;
284 double **Buffer;
285 long NBuffer;
286};
287
288
289///////////////////////////////////////////////////////////////////
290//! Class for reading ALL the columns in a FITS ASCII or BINARY table with fits file opening
291class FitsABTColRead1F : public FitsABTColRd1F {
292public:
293 FitsABTColRead1F(string fname,int ihdu=0
294 ,long blen=100,long bsens=1,int lp=0);
295 FitsABTColRead1F(const char *cfname,int ihdu=0
296 ,long blen=100,long bsens=1,int lp=0);
297 virtual ~FitsABTColRead1F();
298};
299
300///////////////////////////////////////////////////////////////////
301//! Class for reading a 2D image from a FITS file
302class FitsImg2DRd : public AnyDataObj {
303public:
304 FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
305 FitsImg2DRd(FitsImg2DRd& fbt);
306 FitsImg2DRd();
307 virtual ~FitsImg2DRd();
308
309 double ReadKey(const char *keyname);
310 long ReadKeyL(const char *keyname);
311 LONGLONG ReadKeyLL(const char *keyname);
312 string ReadKeyS(const char *keyname);
313
314 LONGLONG Read(TMatrix<uint_2>& data);
315 LONGLONG Read(TMatrix<int_4>& data);
316 LONGLONG Read(TMatrix<int_8>& data);
317 LONGLONG Read(TMatrix<float>& data);
318 LONGLONG Read(TMatrix<double>& data);
319 double Read(LONGLONG numcol, LONGLONG numrow);
320
321 //! Set debug level
322 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
323 //! Set null value to be return when reading null data (0=return the data)
324 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
325 //! Get the pointer to FitsOpenFile
326 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
327 //! Get the FITS file pointer (cfistio pointer)
328 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
329 //! Get the number of HDU in the FITS file
330 inline int NHDU(void) const
331 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
332 //! Get the number of the HDU read
333 inline int HDU(void) const
334 {if(FitsOF) return FitsOF->HDU(); else return 0;}
335 //! Get the HDU type
336 inline int HDUType(void) const
337 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
338 //! Get NAXIS1
339 inline LONGLONG Naxis1(void) const {return Naxis[0];}
340 //! Get NAXIS2
341 inline LONGLONG Naxis2(void) const {return Naxis[1];}
342
343protected:
344 void Init(FitsOpenFile* fof,int ihdu,int lp);
345
346 LONGLONG Naxis[2];
347 double NulVal;
348 unsigned short DbgLevel;
349
350 FitsOpenFile* FitsOF;
351};
352
353///////////////////////////////////////////////////////////////////
354//! Class for reading a 2D image from a FITS file
355class FitsImg2DRead : public FitsImg2DRd {
356public:
357 FitsImg2DRead(string fname,int ihdu=0,int lp=0);
358 FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0);
359 FitsImg2DRead(FitsImg2DRead& fbt);
360 FitsImg2DRead();
361 virtual ~FitsImg2DRead();
362};
363
364
365///////////////////////////////////////////////////////////////////
366//! Class for reading a 3D image from a FITS file
367class FitsImg3DRd : public AnyDataObj {
368public:
369 FitsImg3DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
370 FitsImg3DRd(FitsImg3DRd& fbt);
371 FitsImg3DRd();
372 virtual ~FitsImg3DRd();
373
374 double ReadKey(const char *keyname);
375 long ReadKeyL(const char *keyname);
376 LONGLONG ReadKeyLL(const char *keyname);
377 string ReadKeyS(const char *keyname);
378
379 LONGLONG Read(TArray<uint_2>& data);
380 LONGLONG Read(TArray<int_4>& data);
381 LONGLONG Read(TArray<int_8>& data);
382 LONGLONG Read(TArray<float>& data);
383 LONGLONG Read(TArray<double>& data);
384
385 LONGLONG Read(LONGLONG j, LONGLONG k, TVector<int_4>& data);
386 LONGLONG Read(LONGLONG j, LONGLONG k, TVector<float>& data);
387 LONGLONG Read(LONGLONG j, LONGLONG k, TVector<double>& data);
388
389 double Read(LONGLONG i, LONGLONG j, LONGLONG k);
390
391 //! Set debug level
392 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
393 //! Set null value to be return when reading null data (0=return the data)
394 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
395 //! Get the pointer to FitsOpenFile
396 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
397 //! Get the FITS file pointer (cfistio pointer)
398 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
399 //! Get the number of HDU in the FITS file
400 inline int NHDU(void) const
401 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
402 //! Get the number of the HDU read
403 inline int HDU(void) const
404 {if(FitsOF) return FitsOF->HDU(); else return 0;}
405 //! Get the HDU type
406 inline int HDUType(void) const
407 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
408 //! Get NAXIS1
409 inline LONGLONG Naxis1(void) const {return Naxis[0];}
410 //! Get NAXIS2
411 inline LONGLONG Naxis2(void) const {return Naxis[1];}
412 //! Get NAXIS3
413 inline LONGLONG Naxis3(void) const {return Naxis[2];}
414
415protected:
416 void Init(FitsOpenFile* fof,int ihdu,int lp);
417
418 LONGLONG Naxis[3];
419 double NulVal;
420 unsigned short DbgLevel;
421
422 FitsOpenFile* FitsOF;
423};
424
425///////////////////////////////////////////////////////////////////
426//! Class for reading a 3D image from a FITS file
427class FitsImg3DRead : public FitsImg3DRd {
428public:
429 FitsImg3DRead(string fname,int ihdu=0,int lp=0);
430 FitsImg3DRead(const char *cfname,int ihdu=0,int lp=0);
431 FitsImg3DRead(FitsImg3DRead& fbt);
432 FitsImg3DRead();
433 virtual ~FitsImg3DRead();
434};
435
436} // namespace SOPHYA
437#endif /* FABTCOLREAD_H_SEEN */
Note: See TracBrowser for help on using the repository browser.