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

Last change on this file since 4020 was 3772, checked in by cmv, 15 years ago

lecture fits3D axe 1 dans TVector, cmv 09/05/2010

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