source: Sophya/trunk/SophyaExt/FitsIOServer/fitsfile.h@ 1045

Last change on this file since 1045 was 1045, checked in by ansari, 25 years ago

ecriture premiere image en HDU 2

File size: 8.5 KB
Line 
1#ifndef FITSFILE_H
2#define FITSFILE_H
3
4#include "ndatablock.h"
5#include "dvlist.h"
6#include "FitsIO/fitsio.h"
7
8#define OPENFILE 0
9#define CREATEFILE 1
10#define LEN_KEYWORD 9
11
12namespace SOPHYA {
13
14//
15//! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
16
17/*!
18
19Each SOPHYA object XXX is associated with a object of class FITS_XXX
20 (inheriting from FitsFile), to which input/output operations with FITS
21 files are delegated. A typical example of use is the following :
22
23\verbatim
24 int m=... ;
25 SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object
26 .... fill the sphere ....
27
28 FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
29 // delegated object
30 fits_sph.Write("myfile.fits"); // writing on FITS file
31
32 FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
33 // load a delegated object
34 // from FITS file
35 SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
36 // casting the delegated object
37 // into a SOPHYA object
38\endverbatim
39
40*/
41class FitsFile
42{
43
44public:
45
46 FitsFile();
47 virtual ~FitsFile();
48 static int NbBlocks(char flnm[]);
49 static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl );
50/*! return true if the current header corresponds to a FITS image extension */
51inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
52
53/*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
54inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
55
56/*!
57this method is called from inherited objects :
58
59moves to header 'hdunum' on file 'flnm'
60
61gets parameters in header
62
63calls the method 'ReadFromFits' from the inherited delegated object
64
65*/
66 void ReadF(char flnm[],int hdunum= 0);
67 FitsFile* ReadFInit(char flnm[],int hdunum=0);
68 void ReadFFromFits();
69
70/*!
71this method is called from inherited objects :
72
73opens a file 'flnm'
74
75gets parameters in header
76
77calls the method 'ReadFromFits' from the inherited delegated object
78
79*/
80 void WriteF(char flnm[], bool OldFile=false);
81
82
83 /*!
84fill the array 'map' with double data from the current extension on FITS file.
85If the extension is BINTABLE, the first column is provided.
86
87\param <nentries> number of data to be read
88 */
89 void GetSingleColumn(double* map, int nentries) const;
90
91 /*! same as above with float data */
92 void GetSingleColumn(float* map, int nentries) const;
93
94 /*! same as above with int data */
95 void GetSingleColumn(int* map, int nentries) const;
96
97 /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
98 */
99inline int nbDimOfImage() const {return naxis_;}
100
101/*!
102 total number of data in the current IMAGE extension
103 */
104inline int nbOfImageData() const { return nbData_; }
105
106/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
107 */
108 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
109
110 /*! return number of columns (return 1 if IMAGE) */
111 int NbColsFromFits() const;
112
113 /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
114
115D : double
116
117E : float
118
119I : integer
120
121S : character string
122
123 */
124 char ColTypeFromFits(int nocol) const;
125
126 /*! number of data in the current IMAGE extension on FITS file, or number
127 of data of column number 'nocol' of the current BINTABLE extension
128 */
129 int NentriesFromFits(int nocol) const;
130
131 /*! name of the column number 'nocol' of the current BINTABLE extension
132 */
133 string ColNameFromFits(int nocol) const;
134
135
136 /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
137 */
138 int ColStringLengthFromFits(int nocol) const;
139
140 /*! return a reference on a DVList containing the keywords from FITS file
141 */
142 inline const DVList& DVListFromFits() const { return dvl_;}
143
144
145 /*!
146fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
147
148\param <nentries> number of data to be read
149 */
150 void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
151
152 /*! same as previous method with float data */
153 void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
154 /*! same as previous method with int data */
155 void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const;
156 /*! same as previous method with char* data */
157 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
158 // Write elements into the FITS data array
159
160 /*!
161get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
162 */
163 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
164** cdata) const;
165 /*!
166get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
167 */
168 void GetBinTabLine(int NoLine, float* fdata) const;
169
170
171
172
173 /*! write double data from array 'map'on an IMAGE extension
174\param <nbData> number of data to be written
175
176 */
177 void putImageToFits( int nbData, double* map) const;
178
179 /*! same as previous method with float data */
180 void putImageToFits(int nbData, float* map ) const;
181
182 /*! same as previous method with int data */
183 void putImageToFits(int nbData, int* map) const;
184
185 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
186\param <nentries> number of data to be written
187
188 */
189 void putColToFits(int nocol, int nentries, double* donnees) const;
190
191 /*! same as previous method with float data */
192 void putColToFits(int nocol, int nentries, float* donnees) const;
193
194 /*! same as previous method with int data */
195 void putColToFits(int nocol, int nentries, int* donnees) const;
196
197 /*! same as previous method with char* data */
198 void putColToFits(int nocol, int nentries, char** donnees) const;
199
200 /*! create an IMAGE header on FITS file.
201\param <type> type of data (see method ColTypeFromFits)
202\param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
203\param <naxisn> array containind sizes of the different dimensions
204 */
205 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
206
207 /*! create an BINTABLE header on FITS file.
208\param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits)
209\param <Noms> array of the names of columns
210\param <nentries> number of data of each column
211\param <tfields> number of columns
212\param <dvl> a SOPHYA DVList containing keywords to be appended
213\param <extname> keyword EXTNAME for FITS file
214\param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
215 */
216 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ;
217
218 void moveToFollowingHeader();
219 void readheader();
220static void printerror(int&) ;
221static void printerror(int&,char* texte) ;
222 protected:
223 virtual void ReadFromFits(FitsFile& ff)=0;
224 virtual void WriteToFits(FitsFile& ff)=0;
225private:
226
227 void InitNull();
228
229static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
230static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
231 vector<int>& repeat,
232 vector<string>& noms,
233 vector<char>& types,
234 vector<int>& taille_des_chaines);
235static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
236 void writeSignatureOnFits() const;
237
238 //! pointer to the FITS file, defined in fitsio.h
239 fitsfile *fptr_;
240
241 //! image or bintable ?
242 int hdutype_;
243
244//! index of header to be read/written
245 int hdunum_;
246
247
248 //! fits-Image parameter
249 int bitpix_;
250
251 //! fits-Image parameter
252 int naxis_;
253
254 //! fits-Image parameters : sizes of dimensions
255 vector<int> naxisn_;
256
257 //! fits-Image parameter: number of data
258 int nbData_;
259
260 //! Bintable parameter
261 int nrows_;
262
263 //! Bintable parameter
264 vector<int> repeat_;
265
266 //! Bintable parameter
267 int nbcols_;
268
269 //! Bintable parameter: column names
270 vector<string> noms_;
271
272 //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*)
273 vector<char> types_;
274
275 //! Bintable parameters: length of the char* variables
276 vector<int> taille_des_chaines_;
277
278 //! DVList for transferring keywords
279 DVList dvl_;
280
281};
282
283
284} // Fin du namespace
285
286
287#endif
Note: See TracBrowser for help on using the repository browser.