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

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

suppression lecture Bufferisee de FitsABTColRd (inutile: cfitsio gere bufferisation en interne et complication code), cmv 22/10/2011

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