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

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

read/write string, complex, bufferisation enlevee pour FitsABTColRd1F, cmv 03/10/2011

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