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

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

structuration a la ppersist+ convention sur hdu

File size: 11.9 KB
RevLine 
[839]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
[875]12namespace SOPHYA {
13
[1136]14 class FitsFile;
15 class FitsInFile;
16 class FitsOutFile;
17
18
19
[903]20//
[1136]21//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
[875]22
[903]23/*!
[1136]24The class structure is analogous to Sophya-PPersist system :
[903]25Each SOPHYA object XXX is associated with a object of class FITS_XXX
[1136]26 (inheriting from FitsFileHandler), to which input/output operations with FITS
27 files are delegated (through a class Hierarchy : FitsFile (virtual),
28 FitsInFile, FitsOutFile) . A typical example of use is the following :
[903]29
30\verbatim
31 int m=... ;
32 SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object
33 .... fill the sphere ....
34
35 FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
36 // delegated object
37 fits_sph.Write("myfile.fits"); // writing on FITS file
38
39 FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
40 // load a delegated object
41 // from FITS file
42 SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
43 // casting the delegated object
44 // into a SOPHYA object
45\endverbatim
46
47*/
[839]48
[1136]49class FitsIOHandler {
[839]50
51
[1136]52 public:
53
54virtual ~FitsIOHandler() {}
[903]55/*!
56this method is called from inherited objects :
57
[1136]58opens a file 'flnm'
[903]59
[1136]60gets parameters in header (hdunum)
[903]61
[1047]62calls the method 'ReadFromFits' from the inherited object
[903]63
[1136]64
[903]65*/
[1136]66 void Read(char flnm[],int hdunum= 2);
[903]67/*!
68this method is called from inherited objects :
69
[1136]70for writing a new object in a new fits-extension, at the end of
[903]71
[1136]72the existing file (flnm), if OldFile=true.
[903]73
[1136]74If OldFile=false, an exception occurs
75
76By convention, primary header does not contain fits-image data : i.e.
77all data are fits-extensions. The first relevant header will have hdunum=2.
78For switching off this convention use the method :
[903]79
[1136]80firstImageOnPrimaryHeader() (see below)
81
82In that case do not forget to precise hdunum=1 when reading data on primary header.
83
84calls the method 'WriteToFits' from the inherited object
85
[903]86*/
[1136]87 void Write(char flnm[], bool OldFile=false) ;
[903]88
[1136]89 /*!
90Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. With default value for hdunum, one reads the next extension, with respect to the current position.
91 */
92 void Read(FitsInFile& ifts, int hdunum=0);
93 void Write(FitsOutFile& ofts) ;
[903]94
95
[1136]96 protected:
97 virtual void ReadFromFits(FitsInFile& is)=0;
98 virtual void WriteToFits(FitsOutFile& os) =0;
99 friend class FitsInFile;
100 friend class FitsOutFile;
[903]101
[1136]102 };
103
104
105
106class FitsFile
107{
108
109public:
110
111 FitsFile() { InitNull();};
112 virtual ~FitsFile();
113
[1047]114 static string getErrStatus(int status);
[903]115
116
[1047]117
[1136]118
119inline int statusF() const { return fits_status_;}
120
121
122protected:
123
124 void ResetStatus(int& status) ;
125 static void printerror(int&) ;
126 static void printerror(int&,char* texte) ;
127 inline void InitNull() { cout << " init fitsfile " << endl; fptr_= NULL; hdutype_= 0; hdunum_ = 1;
128 fits_status_ = 0;}
129
130 //! pointer to the FITS file, defined in fitsio.h
131 fitsfile *fptr_;
132
133 //! image or bintable ?
134 int hdutype_;
135
136//! index of header to be read/written
137 int hdunum_;
138
139 //! last status returned by fitsio library. updated only by several methods
140 int fits_status_;
141
142
143};
144
145
146 class FitsInFile : public FitsFile {
147
148 public:
149 FitsInFile();
150 // FitsInFile(char flnm[], int hdunum=0);
151 FitsInFile(char flnm[]);
152 ~FitsInFile() { cout << " destructeur FitsInFile " << endl; };
153
154
[1047]155//////////////////////////////////////////////////////////
[1136]156// methods with general purpose
157///////////////////////////////////////
[1047]158
[1136]159
160
161 static int NbBlocks(char flnm[]);
162 static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl );
163
164
165
166 // void ReadFInit(char flnm[],int hdunum=0);
167 void ReadFInit(int hdunum);
168
[1047]169 /*! return a reference on a DVList containing the keywords from FITS file
170 */
[1136]171inline const DVList& DVListFromFits() const { return dvl_;}
[1047]172
[1136]173void moveToFollowingHeader();
[1047]174
175
[1136]176 //////////////////////////////////////////////////////////
177 /////// methods for managing extensions ////////////////
178 //////////////////////////////////////////////////////////
179
180
181
[1047]182/////////////////////////////////////////////////////////////
[1136]183// methods for managing FITS IMAGE extension
184///////////////////////////////////////////////////
[1047]185
186
187/*! return true if the current header corresponds to a FITS image extension */
188inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
189
[1136]190
191
[903]192 /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
193 */
[861]194inline int nbDimOfImage() const {return naxis_;}
[1047]195/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
196 */
197 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
[903]198/*!
199 total number of data in the current IMAGE extension
200 */
[839]201inline int nbOfImageData() const { return nbData_; }
[903]202
203
[1047]204
[1136]205//////////////////////////////////////////////////////////////////////////
206// methods for managing FITS BINARY TABLE or ASCII TABLE extension
207////////////////////////////////////////////////////////////////////////
[1047]208
209
210
211
[1136]212/*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
213inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
[1047]214
215
[1136]216static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
217 vector<int>& repeat,
218 vector<string>& noms,
219 vector<char>& types,
220 vector<int>& taille_des_chaines);
[1047]221
222
223
[903]224 /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
225
226D : double
227
228E : float
229
230I : integer
231
232S : character string
233
234 */
[839]235 char ColTypeFromFits(int nocol) const;
[903]236 /*! name of the column number 'nocol' of the current BINTABLE extension
237 */
[839]238 string ColNameFromFits(int nocol) const;
[903]239
240 /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
241 */
[839]242 int ColStringLengthFromFits(int nocol) const;
[903]243
244
245
246 /*!
[1047]247get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
248 */
249 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
250** cdata) ;
251
252 /*!
253get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
254 */
255 void GetBinTabLine(int NoLine, float* fdata) ;
256
[1136]257/*!
[903]258fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
259
260\param <nentries> number of data to be read
261 */
[839]262 void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
[903]263
264 /*! same as previous method with float data */
[839]265 void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
[903]266 /*! same as previous method with int data */
[839]267 void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const;
[903]268 /*! same as previous method with char* data */
[839]269 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
270 // Write elements into the FITS data array
[903]271
[1136]272/////////////////////////////////////////////////////////////
273// methods for managing any type of FITS extension
274////////////////////////////////////////////////////////
[1045]275
[1136]276 /*! return number of columns (return 1 if IMAGE) */
277 int NbColsFromFits() const;
278 /*! number of data in the current IMAGE extension on FITS file, or number
279 of data of column number 'nocol' of the current BINTABLE extension
280 */
281 int NentriesFromFits(int nocol) const;
[1045]282
283
[1136]284/*!
[1047]285fill the array 'map' with double data from the current extension on FITS file.
286If the extension is BINTABLE, the first column is provided.
287
288\param <nentries> number of data to be read
[903]289 */
[1047]290 void GetSingleColumn(double* map, int nentries) const;
[903]291
[1047]292 /*! same as above with float data */
293 void GetSingleColumn(float* map, int nentries) const;
[839]294
[1047]295 /*! same as above with int data */
296 void GetSingleColumn(int* map, int nentries) const;
297
[1136]298 private :
[1047]299
[1136]300void InitNull();
301static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
[903]302static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
[839]303
304
[1136]305
[839]306
[903]307 //! fits-Image parameter
[839]308 int bitpix_;
[903]309
310 //! fits-Image parameter
[839]311 int naxis_;
[903]312
313 //! fits-Image parameters : sizes of dimensions
[861]314 vector<int> naxisn_;
[903]315
316 //! fits-Image parameter: number of data
[839]317 int nbData_;
318
[903]319 //! Bintable parameter
[839]320 int nrows_;
[903]321
322 //! Bintable parameter
[839]323 vector<int> repeat_;
324
[903]325 //! Bintable parameter
[839]326 int nbcols_;
327
[903]328 //! Bintable parameter: column names
329 vector<string> noms_;
[1136]330
[903]331 //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*)
332 vector<char> types_;
[1136]333
[903]334 //! Bintable parameters: length of the char* variables
335 vector<int> taille_des_chaines_;
[839]336
[903]337 //! DVList for transferring keywords
[839]338 DVList dvl_;
[1045]339
[1047]340
[1136]341 };
[1047]342
[875]343
[1136]344 class FitsOutFile : public FitsFile {
[875]345
[1136]346 public:
347 FitsOutFile();
348 FitsOutFile(char flnm[], bool OldFile=false);
349 ~FitsOutFile() { cout << " destructeur FitsOutFile " << endl;};
350 inline void InitNull() {imageOnPrimary_=false;}
351
352 //////////////////////////////////////////////////////////
353 /////// methods for managing extensions ////////////////
354 //////////////////////////////////////////////////////////
355
356
357
358/////////////////////////////////////////////////////////////
359// methods for managing FITS IMAGE extension
360///////////////////////////////////////////////////
361
362
363 inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
364
365 /*! create an IMAGE header on FITS file.
366\param <type> type of data (see method ColTypeFromFits)
367\param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
368\param <naxisn> array containind sizes of the different dimensions
369 */
370 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
371
372 /*! write double data from array 'map'on an IMAGE extension
373\param <nbData> number of data to be written
374
375 */
376 void putImageToFits( int nbData, double* map) const;
377
378 /*! same as previous method with float data */
379 void putImageToFits(int nbData, float* map ) const;
380
381 /*! same as previous method with int data */
382 void putImageToFits(int nbData, int* map) const;
383
384
385
386//////////////////////////////////////////////////////////////////////////
387// methods for managing FITS BINARY TABLE or ASCII TABLE extension
388////////////////////////////////////////////////////////////////////////
389
390
391
392 /*! create an BINTABLE header on FITS file.
393\param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits)
394\param <Noms> array of the names of columns
395\param <nentries> number of data of each column
396\param <tfields> number of columns
397\param <dvl> a SOPHYA DVList containing keywords to be appended
398\param <extname> keyword EXTNAME for FITS file
399\param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
400 */
401 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ;
402
403 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
404\param <nentries> number of data to be written
405
406 */
407 void putColToFits(int nocol, int nentries, double* donnees) const;
408
409 /*! same as previous method with float data */
410 void putColToFits(int nocol, int nentries, float* donnees) const;
411
412 /*! same as previous method with int data */
413 void putColToFits(int nocol, int nentries, int* donnees) const;
414
415 /*! same as previous method with char* data */
416 void putColToFits(int nocol, int nentries, char** donnees) const;
417
418 private :
419
420 void writeSignatureOnFits() const;
421
422
423 bool imageOnPrimary_;
424
425 };
426
427
428
[875]429} // Fin du namespace
430
431
[839]432#endif
Note: See TracBrowser for help on using the repository browser.