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

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

bintable avec elements vecteur, cmv 02/10/2011

File size: 16.2 KB
RevLine 
[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 Column Reader cmv 26/09/2001 */
7#ifndef FABTCOLREAD_H_SEEN
8#define FABTCOLREAD_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
19namespace SOPHYA {
20
[2449]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
[2456]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;}
[2449]44
[2456]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
[3572]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);
[2453]54 static void printerror(int sta);
55
[2449]56protected:
57 void Init(const char *cfname);
58 void Delete(void);
59
60 string FitsFN;
[2456]61 int NHdu, IHdu, HduType;
[2449]62 fitsfile *FitsPtr;
[2456]63 bool HasBeenPos;
[2449]64};
65
66///////////////////////////////////////////////////////////////////
[1654]67//! Class for reading a column in a FITS ASCII or BINARY table
[2449]68class FitsABTColRd : public AnyDataObj {
[1654]69public:
[2449]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();
[1654]77
78 void ChangeBuffer(long blen=100,long bsens=1);
79
[3572]80 double ReadKey(const char *keyname);
81 long ReadKeyL(const char *keyname);
82 LONGLONG ReadKeyLL(const char *keyname);
83 string ReadKeyS(const char *keyname);
[1814]84
[4023]85 double Read(LONGLONG n,long nfirstel,bool usebuffer=true);
86 inline double Read(LONGLONG n,bool usebuffer=true) {return Read(n,0,usebuffer);}
[2170]87
[3128]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);
[1654]93
[1659]94 //! return the value of the first row
[4023]95 double ReadFirstRow(long nfirstel,bool usebuffer=false) {return Read(0,nfirstel,usebuffer);}
96 double ReadFirstRow(bool usebuffer=false) {return Read(0,usebuffer);}
[1659]97 //! return the value of the last row
[4023]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);}
[1659]100
[4023]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);}
[1659]107
[1654]108 //! Set debug level
[2456]109 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
[1654]110 //! Set null value to be return when reading null data (0=return the data)
[2456]111 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
[1654]112 //! Get the FITS file name
[2456]113 inline string FileName(void) const
114 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
[2449]115 //! Get the pointer to FitsOpenFile
[2456]116 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
[1673]117 //! Get the FITS file pointer (cfistio pointer)
[3114]118 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
[1654]119 //! Get the number of HDU in the FITS file
[2456]120 inline int NHDU(void) const
121 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
[1654]122 //! Get the number of the HDU read
[2456]123 inline int HDU(void) const
124 {if(FitsOF) return FitsOF->HDU(); else return 0;}
[1654]125 //! Get the HDU type
[2456]126 inline int HDUType(void) const
127 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
[1654]128 //! Get the number of rows in the FITS HDU to be read
[3128]129 inline LONGLONG GetNbLine(void) const {return NBline;}
[1654]130 //! Get the number of columns in the FITS HDU to be read
[2456]131 inline int GetNbCol(void) const {return NBcol;}
[1654]132 //! Get the columns number that is read
[2456]133 inline int GetColNum(void) const {return ColNum;}
[1654]134 //! Get the columns label that is read
[2456]135 inline string GetColLabel(void) const {return ColLabel;}
[1654]136 //! Get the columns type code that is read
[2456]137 inline int GetColTypeCode(void) const {return ColTypeCode;}
[1654]138 //! Get the columns fits tunit that is read
[2456]139 inline string GetColTUnit(void) const {return ColTUnit;}
[1654]140 //! Get the columns fits tform that is read
[2456]141 inline string GetColTForm(void) const {return ColTForm;}
[4023]142 //! Get the columns fits repeat that is read
143 inline long GetColRepeat(void) const {return ColRepeat;}
[1657]144 //! Get the read requested buffer length
[2456]145 inline long GetBLen(void) const {return BuffLen;}
[1654]146 //! Get the read buffer direction
[2456]147 inline long GetBSens(void) const {return BuffSens;}
[1654]148 //! Print to os
[2456]149 virtual void Print(ostream& os,int lp=1) const;
[1654]150 //! Print to stdout
[2456]151 inline void Print(int lp=1) const {Print(cout,lp);}
[1657]152 //! Get the read effective buffer length
[2456]153 inline long GetNBuffer(void) const {return NBuffer;}
[1654]154 //! Get the read bufferpointer
155 inline double* GetBuffer(void) {return Buffer;}
156
157protected:
[2449]158 void Init(FitsOpenFile* fof,const char *collabel,int colnum
[1654]159 ,int ihdu,long blen,long bsens,int lp);
160 void Delete(void);
161
[2456]162 string ColLabel,ColTUnit,ColTForm;
163 int ColNum,ColTypeCode,NBcol;
[4023]164 long ColRepeat;
[3128]165 LONGLONG NBline;
[1654]166
[1657]167 double NulVal;
168 unsigned short DbgLevel;
[1654]169 long BuffLen, BuffSens;
170
[3128]171 LONGLONG NFitsRead;
[2449]172 FitsOpenFile* FitsOF;
[3128]173 LONGLONG LineDeb, LineFin;
[1654]174 double *Buffer;
175 long NBuffer;
176};
177
[2449]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
[2453]195
196///////////////////////////////////////////////////////////////////
[3660]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
[4023]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);}
[3660]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];}
[4023]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];}
[3660]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;
[4023]274 vector<long> ColRepeat;
[3660]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///////////////////////////////////////////////////////////////////
[2453]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
[3572]309 double ReadKey(const char *keyname);
310 long ReadKeyL(const char *keyname);
311 LONGLONG ReadKeyLL(const char *keyname);
312 string ReadKeyS(const char *keyname);
[2453]313
[3128]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);
[3188]319 double Read(LONGLONG numcol, LONGLONG numrow);
[2453]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
[2456]326 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
327 //! Get the FITS file pointer (cfistio pointer)
[3114]328 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
[2456]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;}
[2453]332 //! Get the number of the HDU read
[2456]333 inline int HDU(void) const
334 {if(FitsOF) return FitsOF->HDU(); else return 0;}
[2453]335 //! Get the HDU type
[2456]336 inline int HDUType(void) const
337 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
[2453]338 //! Get NAXIS1
[3128]339 inline LONGLONG Naxis1(void) const {return Naxis[0];}
[2453]340 //! Get NAXIS2
[3128]341 inline LONGLONG Naxis2(void) const {return Naxis[1];}
[2453]342
343protected:
344 void Init(FitsOpenFile* fof,int ihdu,int lp);
345
[3128]346 LONGLONG Naxis[2];
[2453]347 double NulVal;
348 unsigned short DbgLevel;
349
350 FitsOpenFile* FitsOF;
351};
[2591]352
[2791]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
[3114]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
[3572]374 double ReadKey(const char *keyname);
375 long ReadKeyL(const char *keyname);
376 LONGLONG ReadKeyLL(const char *keyname);
377 string ReadKeyS(const char *keyname);
[3114]378
[3128]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);
[3772]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
[3188]389 double Read(LONGLONG i, LONGLONG j, LONGLONG k);
[3114]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
[3128]409 inline LONGLONG Naxis1(void) const {return Naxis[0];}
[3114]410 //! Get NAXIS2
[3128]411 inline LONGLONG Naxis2(void) const {return Naxis[1];}
[3114]412 //! Get NAXIS3
[3128]413 inline LONGLONG Naxis3(void) const {return Naxis[2];}
[3114]414
415protected:
416 void Init(FitsOpenFile* fof,int ihdu,int lp);
417
[3128]418 LONGLONG Naxis[3];
[3114]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
[2591]436} // namespace SOPHYA
437#endif /* FABTCOLREAD_H_SEEN */
Note: See TracBrowser for help on using the repository browser.