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

Last change on this file since 3493 was 3493, checked in by ansari, 17 years ago

1/ Ajout methodes FitsArrayHandler<T>::ReadAtOffset() WriteAtOffset() pour lecture/ecriture de tableaux <> HDU IMAGE par morceaux
2/ Ajout entete commentaire avec copyright LAL+DAPNIA dans les fichiers .h

Reza 30/04/2008

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