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

Last change on this file since 3123 was 3114, checked in by cmv, 19 years ago

1-/ intro des reader et writer pour tableaux 3D
2-/ j enleve la variable redondante FitsPtr :

si travail OK c est une modif mineure
mais ca peut conduire a de gros PB si qquechose a ete oublie
ATTENTION ATTENTION MODIF .... cmv 13/12/2006

File size: 10.5 KB
RevLine 
[1654]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"
[2322]6#include <iostream>
[1654]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
[2449]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
[2456]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;}
[2449]39
[2456]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
[2453]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
[2449]50protected:
51 void Init(const char *cfname);
52 void Delete(void);
53
54 string FitsFN;
[2456]55 int NHdu, IHdu, HduType;
[2449]56 fitsfile *FitsPtr;
[2456]57 bool HasBeenPos;
[2449]58};
59
60///////////////////////////////////////////////////////////////////
[1654]61//! Class for reading a column in a FITS ASCII or BINARY table
[2449]62class FitsABTColRd : public AnyDataObj {
[1654]63public:
[2449]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();
[1654]71
72 void ChangeBuffer(long blen=100,long bsens=1);
73
[1814]74 double ReadKey(char *keyname);
[2451]75 long ReadKeyL(char *keyname);
76 string ReadKeyS(char *keyname);
[1814]77
[1659]78 double Read(long n,bool usebuffer=true);
[2170]79
[2456]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);
[1654]85
[1659]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
[1654]96 //! Set debug level
[2456]97 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
[1654]98 //! Set null value to be return when reading null data (0=return the data)
[2456]99 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
[1654]100 //! Get the FITS file name
[2456]101 inline string FileName(void) const
102 {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
[2449]103 //! Get the pointer to FitsOpenFile
[2456]104 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
[1673]105 //! Get the FITS file pointer (cfistio pointer)
[3114]106 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
[1654]107 //! Get the number of HDU in the FITS file
[2456]108 inline int NHDU(void) const
109 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
[1654]110 //! Get the number of the HDU read
[2456]111 inline int HDU(void) const
112 {if(FitsOF) return FitsOF->HDU(); else return 0;}
[1654]113 //! Get the HDU type
[2456]114 inline int HDUType(void) const
115 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
[1654]116 //! Get the number of rows in the FITS HDU to be read
[2456]117 inline long GetNbLine(void) const {return NBline;}
[1654]118 //! Get the number of columns in the FITS HDU to be read
[2456]119 inline int GetNbCol(void) const {return NBcol;}
[1654]120 //! Get the columns number that is read
[2456]121 inline int GetColNum(void) const {return ColNum;}
[1654]122 //! Get the columns label that is read
[2456]123 inline string GetColLabel(void) const {return ColLabel;}
[1654]124 //! Get the columns type code that is read
[2456]125 inline int GetColTypeCode(void) const {return ColTypeCode;}
[1654]126 //! Get the columns fits tunit that is read
[2456]127 inline string GetColTUnit(void) const {return ColTUnit;}
[1654]128 //! Get the columns fits tform that is read
[2456]129 inline string GetColTForm(void) const {return ColTForm;}
[1657]130 //! Get the read requested buffer length
[2456]131 inline long GetBLen(void) const {return BuffLen;}
[1654]132 //! Get the read buffer direction
[2456]133 inline long GetBSens(void) const {return BuffSens;}
[1654]134 //! Print to os
[2456]135 virtual void Print(ostream& os,int lp=1) const;
[1654]136 //! Print to stdout
[2456]137 inline void Print(int lp=1) const {Print(cout,lp);}
[1657]138 //! Get the read effective buffer length
[2456]139 inline long GetNBuffer(void) const {return NBuffer;}
[1654]140 //! Get the read bufferpointer
141 inline double* GetBuffer(void) {return Buffer;}
142
143protected:
[2449]144 void Init(FitsOpenFile* fof,const char *collabel,int colnum
[1654]145 ,int ihdu,long blen,long bsens,int lp);
146 void Delete(void);
147
[2456]148 string ColLabel,ColTUnit,ColTForm;
149 int ColNum,ColTypeCode,NBcol;
[1654]150 long NBline;
151
[1657]152 double NulVal;
153 unsigned short DbgLevel;
[1654]154 long BuffLen, BuffSens;
155
[1657]156 unsigned long NFitsRead;
[2449]157 FitsOpenFile* FitsOF;
[1654]158 long LineDeb, LineFin;
159 double *Buffer;
160 long NBuffer;
161};
162
[2449]163///////////////////////////////////////////////////////////////////
164//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
165class FitsABTColRead : public FitsABTColRd {
166public:
167 FitsABTColRead(string fname,string collabel,int ihdu=0
168 ,long blen=100,long bsens=1,int lp=0);
169 FitsABTColRead(string fname,int colnum,int ihdu=0
170 ,long blen=100,long bsens=1,int lp=0);
171 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
172 ,long blen=100,long bsens=1,int lp=0);
173 FitsABTColRead(const char *cfname,int colnum,int ihdu=0
174 ,long blen=100,long bsens=1,int lp=0);
175 FitsABTColRead(FitsABTColRead& fbt);
176 FitsABTColRead();
177 virtual ~FitsABTColRead();
178};
179
[2453]180
181///////////////////////////////////////////////////////////////////
182//! Class for reading a 2D image from a FITS file
183class FitsImg2DRd : public AnyDataObj {
184public:
185 FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
186 FitsImg2DRd(FitsImg2DRd& fbt);
187 FitsImg2DRd();
188 virtual ~FitsImg2DRd();
189
190 double ReadKey(char *keyname);
191 long ReadKeyL(char *keyname);
192 string ReadKeyS(char *keyname);
193
[3114]194 size_t Read(TMatrix<uint_2>& data);
195 size_t Read(TMatrix<int_4>& data);
196 size_t Read(TMatrix<int_8>& data);
197 size_t Read(TMatrix<float>& data);
198 size_t Read(TMatrix<double>& data);
[2453]199
200 //! Set debug level
201 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
202 //! Set null value to be return when reading null data (0=return the data)
203 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
204 //! Get the pointer to FitsOpenFile
[2456]205 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
206 //! Get the FITS file pointer (cfistio pointer)
[3114]207 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
[2456]208 //! Get the number of HDU in the FITS file
209 inline int NHDU(void) const
210 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
[2453]211 //! Get the number of the HDU read
[2456]212 inline int HDU(void) const
213 {if(FitsOF) return FitsOF->HDU(); else return 0;}
[2453]214 //! Get the HDU type
[2456]215 inline int HDUType(void) const
216 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
[2453]217 //! Get NAXIS1
[2456]218 inline long Naxis1(void) const {return Naxis[0];}
[2453]219 //! Get NAXIS2
[2456]220 inline long Naxis2(void) const {return Naxis[1];}
[2453]221
222protected:
223 void Init(FitsOpenFile* fof,int ihdu,int lp);
224
225 long Naxis[2];
226 double NulVal;
227 unsigned short DbgLevel;
228
229 FitsOpenFile* FitsOF;
230};
[2591]231
[2791]232///////////////////////////////////////////////////////////////////
233//! Class for reading a 2D image from a FITS file
234class FitsImg2DRead : public FitsImg2DRd {
235public:
236 FitsImg2DRead(string fname,int ihdu=0,int lp=0);
237 FitsImg2DRead(const char *cfname,int ihdu=0,int lp=0);
238 FitsImg2DRead(FitsImg2DRead& fbt);
239 FitsImg2DRead();
240 virtual ~FitsImg2DRead();
241};
242
[3114]243
244///////////////////////////////////////////////////////////////////
245//! Class for reading a 3D image from a FITS file
246class FitsImg3DRd : public AnyDataObj {
247public:
248 FitsImg3DRd(FitsOpenFile* fof,int ihdu=0,int lp=0);
249 FitsImg3DRd(FitsImg3DRd& fbt);
250 FitsImg3DRd();
251 virtual ~FitsImg3DRd();
252
253 double ReadKey(char *keyname);
254 long ReadKeyL(char *keyname);
255 string ReadKeyS(char *keyname);
256
257 size_t Read(TArray<uint_2>& data);
258 size_t Read(TArray<int_4>& data);
259 size_t Read(TArray<int_8>& data);
260 size_t Read(TArray<float>& data);
261 size_t Read(TArray<double>& data);
262
263 //! Set debug level
264 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
265 //! Set null value to be return when reading null data (0=return the data)
266 inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
267 //! Get the pointer to FitsOpenFile
268 inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
269 //! Get the FITS file pointer (cfistio pointer)
270 inline fitsfile* GetFitsPtr(void) const {return FitsOF->GetFitsPtr();}
271 //! Get the number of HDU in the FITS file
272 inline int NHDU(void) const
273 {if(FitsOF) return FitsOF->NHDU(); else return 0;}
274 //! Get the number of the HDU read
275 inline int HDU(void) const
276 {if(FitsOF) return FitsOF->HDU(); else return 0;}
277 //! Get the HDU type
278 inline int HDUType(void) const
279 {if(FitsOF) return FitsOF->HDUType(); else return 0;}
280 //! Get NAXIS1
281 inline long Naxis1(void) const {return Naxis[0];}
282 //! Get NAXIS2
283 inline long Naxis2(void) const {return Naxis[1];}
284 //! Get NAXIS3
285 inline long Naxis3(void) const {return Naxis[2];}
286
287protected:
288 void Init(FitsOpenFile* fof,int ihdu,int lp);
289
290 long Naxis[3];
291 double NulVal;
292 unsigned short DbgLevel;
293
294 FitsOpenFile* FitsOF;
295};
296
297///////////////////////////////////////////////////////////////////
298//! Class for reading a 3D image from a FITS file
299class FitsImg3DRead : public FitsImg3DRd {
300public:
301 FitsImg3DRead(string fname,int ihdu=0,int lp=0);
302 FitsImg3DRead(const char *cfname,int ihdu=0,int lp=0);
303 FitsImg3DRead(FitsImg3DRead& fbt);
304 FitsImg3DRead();
305 virtual ~FitsImg3DRead();
306};
307
[2591]308} // namespace SOPHYA
309#endif /* FABTCOLREAD_H_SEEN */
Note: See TracBrowser for help on using the repository browser.