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

Last change on this file since 2456 was 2456, checked in by cmv, 22 years ago

amelioration architecture classe cmv 18/11/03

File size: 8.1 KB
Line 
1/* Interface Fits BINARY/ASCII Table Column Reader cmv 26/09/2001 */
2#ifndef FABTCOLREAD_H_SEEN
3#define FABTCOLREAD_H_SEEN
4
5#include "machdefs.h"
6#include <iostream>
7#include <string.h>
8#include <string>
9
10#include "anydataobj.h"
11#include "tvector.h"
12#include "FitsIO/fitsio.h"
13
14namespace SOPHYA {
15
16///////////////////////////////////////////////////////////////////
17//! Class for opening a FITS file for reading
18class FitsOpenFile : public AnyDataObj {
19public:
20 FitsOpenFile(string fname);
21 FitsOpenFile(const char *cfname);
22 FitsOpenFile();
23 FitsOpenFile(FitsOpenFile& fof);
24 virtual ~FitsOpenFile();
25
26 inline string FileName() const {return FitsFN;}
27 //! Get the number of the HDU read
28 inline int HDU(void) const {return IHdu;}
29 //! Get the number of the HDU type
30 inline int HDUType(void) const {return HduType;}
31 //! Get the number of HDU in file
32 inline int NHDU() const {return NHdu;}
33 //! Get the CFISTIO fits file pointer
34 inline fitsfile* GetFitsPtr() const {return FitsPtr;}
35 //! Set the positionning status of the file
36 inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;}
37 //! Get the positionning status of the file
38 inline bool GetPosStatus(void) const {return HasBeenPos;}
39
40 int MoveToHDU(int ihdu);
41 int MoveToFirst(int hdutype,int ihdudeb=1);
42 int MoveToLast(int hdutype,int ihdudeb=1);
43 void Print(void);
44
45 static double ReadKey(fitsfile *fitsptr,char *keyname);
46 static long ReadKeyL(fitsfile *fitsptr,char *keyname);
47 static string ReadKeyS(fitsfile *fitsptr,char *keyname);
48 static void printerror(int sta);
49
50protected:
51 void Init(const char *cfname);
52 void Delete(void);
53
54 string FitsFN;
55 int NHdu, IHdu, HduType;
56 fitsfile *FitsPtr;
57 bool HasBeenPos;
58};
59
60///////////////////////////////////////////////////////////////////
61//! Class for reading a column in a FITS ASCII or BINARY table
62class FitsABTColRd : public AnyDataObj {
63public:
64 FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
65 ,long blen=100,long bsens=1,int lp=0);
66 FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
67 ,long blen=100,long bsens=1,int lp=0);
68 FitsABTColRd(FitsABTColRd& fbt);
69 FitsABTColRd();
70 virtual ~FitsABTColRd();
71
72 void ChangeBuffer(long blen=100,long bsens=1);
73
74 double ReadKey(char *keyname);
75 long ReadKeyL(char *keyname);
76 string ReadKeyS(char *keyname);
77
78 double Read(long n,bool usebuffer=true);
79
80 long Read(long n1,long n2,TVector<uint_2>& data);
81 long Read(long n1,long n2,TVector<int_4>& data);
82 long Read(long n1,long n2,TVector<int_8>& data);
83 long Read(long n1,long n2,TVector<float>& data);
84 long Read(long n1,long n2,TVector<double>& data);
85
86 //! return the value of the first row
87 double ReadFirstRow(bool usebuffer=false)
88 {return Read(0,usebuffer);}
89 //! return the value of the last row
90 double ReadLastRow(bool usebuffer=false)
91 {return Read(NBline-1,usebuffer);}
92
93 long FirstRow(double val1,double val2,long rowstart=-1);
94 long LastRow(double val1,double val2,long rowstart=-1);
95
96 //! Set debug level
97 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
98 //! Set null value to be return when reading null data (0=return the data)
99 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
100 //! Get the FITS file name
101 inline string FileName(void) const
102 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
103 //! Get the pointer to FitsOpenFile
104 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
105 //! Get the FITS file pointer (cfistio pointer)
106 inline fitsfile* GetFitsPtr(void) const {return FitsPtr;}
107 //! Get the number of HDU in the FITS file
108 inline int NHDU(void) const
109 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
110 //! Get the number of the HDU read
111 inline int HDU(void) const
112 {if(FitsOF) return FitsOF->HDU(); else return 0;}
113 //! Get the HDU type
114 inline int HDUType(void) const
115 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
116 //! Get the number of rows in the FITS HDU to be read
117 inline long GetNbLine(void) const {return NBline;}
118 //! Get the number of columns in the FITS HDU to be read
119 inline int GetNbCol(void) const {return NBcol;}
120 //! Get the columns number that is read
121 inline int GetColNum(void) const {return ColNum;}
122 //! Get the columns label that is read
123 inline string GetColLabel(void) const {return ColLabel;}
124 //! Get the columns type code that is read
125 inline int GetColTypeCode(void) const {return ColTypeCode;}
126 //! Get the columns fits tunit that is read
127 inline string GetColTUnit(void) const {return ColTUnit;}
128 //! Get the columns fits tform that is read
129 inline string GetColTForm(void) const {return ColTForm;}
130 //! Get the read requested buffer length
131 inline long GetBLen(void) const {return BuffLen;}
132 //! Get the read buffer direction
133 inline long GetBSens(void) const {return BuffSens;}
134 //! Print to os
135 virtual void Print(ostream& os,int lp=1) const;
136 //! Print to stdout
137 inline void Print(int lp=1) const {Print(cout,lp);}
138 //! Get the read effective buffer length
139 inline long GetNBuffer(void) const {return NBuffer;}
140 //! Get the read bufferpointer
141 inline double* GetBuffer(void) {return Buffer;}
142
143protected:
144 void Init(FitsOpenFile* fof,const char *collabel,int colnum
145 ,int ihdu,long blen,long bsens,int lp);
146 void Delete(void);
147
148 string ColLabel,ColTUnit,ColTForm;
149 int ColNum,ColTypeCode,NBcol;
150 long NBline;
151
152 double NulVal;
153 unsigned short DbgLevel;
154 long BuffLen, BuffSens;
155
156 unsigned long NFitsRead;
157 FitsOpenFile* FitsOF;
158 fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
159 long LineDeb, LineFin;
160 double *Buffer;
161 long NBuffer;
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
169 ,long blen=100,long bsens=1,int lp=0);
170 FitsABTColRead(string fname,int colnum,int ihdu=0
171 ,long blen=100,long bsens=1,int lp=0);
172 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
173 ,long blen=100,long bsens=1,int lp=0);
174 FitsABTColRead(const char *cfname,int colnum,int ihdu=0
175 ,long blen=100,long bsens=1,int lp=0);
176 FitsABTColRead(FitsABTColRead& fbt);
177 FitsABTColRead();
178 virtual ~FitsABTColRead();
179};
180
181} // namespace SOPHYA
182#endif /* FABTCOLREAD_H_SEEN */
183
184///////////////////////////////////////////////////////////////////
185//! Class for reading a 2D image from a FITS file
186class FitsImg2DRd : public AnyDataObj {
187public:
188 FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
189 FitsImg2DRd(FitsImg2DRd& fbt);
190 FitsImg2DRd();
191 virtual ~FitsImg2DRd();
192
193 double ReadKey(char *keyname);
194 long ReadKeyL(char *keyname);
195 string ReadKeyS(char *keyname);
196
197 long Read(TMatrix<uint_2>& data);
198 long Read(TMatrix<int_4>& data);
199 long Read(TMatrix<int_8>& data);
200 long Read(TMatrix<float>& data);
201 long Read(TMatrix<double>& data);
202
203 //! Set debug level
204 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
205 //! Set null value to be return when reading null data (0=return the data)
206 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
207 //! Get the pointer to FitsOpenFile
208 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
209 //! Get the FITS file pointer (cfistio pointer)
210 inline fitsfile* GetFitsPtr(void) const {return FitsPtr;}
211 //! Get the number of HDU in the FITS file
212 inline int NHDU(void) const
213 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
214 //! Get the number of the HDU read
215 inline int HDU(void) const
216 {if(FitsOF) return FitsOF->HDU(); else return 0;}
217 //! Get the HDU type
218 inline int HDUType(void) const
219 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
220 //! Get NAXIS1
221 inline long Naxis1(void) const {return Naxis[0];}
222 //! Get NAXIS2
223 inline long Naxis2(void) const {return Naxis[1];}
224
225protected:
226 void Init(FitsOpenFile* fof,int ihdu,int lp);
227
228 long Naxis[2];
229 double NulVal;
230 unsigned short DbgLevel;
231
232 FitsOpenFile* FitsOF;
233 fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
234};
Note: See TracBrowser for help on using the repository browser.