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

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

normalisation des DVList

File size: 12.2 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
[1143]60gets parameters in extension-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) ;
[1143]127 inline void InitNull() { fptr_= NULL; hdutype_= 0; hdunum_ = 1;
[1136]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[]);
[1143]152 ~FitsInFile() { ; };
[1136]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
[1143]173/* get the keywords of primary header in a DVList */
174DVList DVListFromPrimaryHeader() const;
175
[1136]176void moveToFollowingHeader();
[1047]177
178
[1136]179 //////////////////////////////////////////////////////////
180 /////// methods for managing extensions ////////////////
181 //////////////////////////////////////////////////////////
182
183
184
[1047]185/////////////////////////////////////////////////////////////
[1136]186// methods for managing FITS IMAGE extension
187///////////////////////////////////////////////////
[1047]188
189
190/*! return true if the current header corresponds to a FITS image extension */
191inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
192
[1136]193
194
[903]195 /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
196 */
[861]197inline int nbDimOfImage() const {return naxis_;}
[1047]198/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
199 */
200 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
[903]201/*!
202 total number of data in the current IMAGE extension
203 */
[839]204inline int nbOfImageData() const { return nbData_; }
[903]205
206
[1047]207
[1136]208//////////////////////////////////////////////////////////////////////////
209// methods for managing FITS BINARY TABLE or ASCII TABLE extension
210////////////////////////////////////////////////////////////////////////
[1047]211
212
213
214
[1136]215/*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
216inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
[1047]217
218
[1136]219static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
220 vector<int>& repeat,
221 vector<string>& noms,
222 vector<char>& types,
223 vector<int>& taille_des_chaines);
[1047]224
225
226
[903]227 /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
228
229D : double
230
231E : float
232
233I : integer
234
235S : character string
236
237 */
[839]238 char ColTypeFromFits(int nocol) const;
[903]239 /*! name of the column number 'nocol' of the current BINTABLE extension
240 */
[839]241 string ColNameFromFits(int nocol) const;
[903]242
243 /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
244 */
[839]245 int ColStringLengthFromFits(int nocol) const;
[903]246
247
248
249 /*!
[1047]250get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
251 */
252 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
253** cdata) ;
254
255 /*!
256get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
257 */
258 void GetBinTabLine(int NoLine, float* fdata) ;
259
[1136]260/*!
[903]261fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
262
263\param <nentries> number of data to be read
264 */
[839]265 void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
[903]266
267 /*! same as previous method with float data */
[839]268 void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
[903]269 /*! same as previous method with int data */
[839]270 void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const;
[903]271 /*! same as previous method with char* data */
[839]272 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
273 // Write elements into the FITS data array
[903]274
[1136]275/////////////////////////////////////////////////////////////
276// methods for managing any type of FITS extension
277////////////////////////////////////////////////////////
[1045]278
[1136]279 /*! return number of columns (return 1 if IMAGE) */
280 int NbColsFromFits() const;
281 /*! number of data in the current IMAGE extension on FITS file, or number
282 of data of column number 'nocol' of the current BINTABLE extension
283 */
284 int NentriesFromFits(int nocol) const;
[1045]285
286
[1136]287/*!
[1047]288fill the array 'map' with double data from the current extension on FITS file.
289If the extension is BINTABLE, the first column is provided.
290
291\param <nentries> number of data to be read
[903]292 */
[1047]293 void GetSingleColumn(double* map, int nentries) const;
[903]294
[1047]295 /*! same as above with float data */
296 void GetSingleColumn(float* map, int nentries) const;
[839]297
[1047]298 /*! same as above with int data */
299 void GetSingleColumn(int* map, int nentries) const;
300
[1136]301 private :
[1047]302
[1136]303void InitNull();
304static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
[903]305static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
[839]306
307
[1136]308
[839]309
[903]310 //! fits-Image parameter
[839]311 int bitpix_;
[903]312
313 //! fits-Image parameter
[839]314 int naxis_;
[903]315
316 //! fits-Image parameters : sizes of dimensions
[861]317 vector<int> naxisn_;
[903]318
319 //! fits-Image parameter: number of data
[839]320 int nbData_;
321
[903]322 //! Bintable parameter
[839]323 int nrows_;
[903]324
325 //! Bintable parameter
[839]326 vector<int> repeat_;
327
[903]328 //! Bintable parameter
[839]329 int nbcols_;
330
[903]331 //! Bintable parameter: column names
332 vector<string> noms_;
[1136]333
[903]334 //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*)
335 vector<char> types_;
[1136]336
[903]337 //! Bintable parameters: length of the char* variables
338 vector<int> taille_des_chaines_;
[839]339
[903]340 //! DVList for transferring keywords
[839]341 DVList dvl_;
[1045]342
[1047]343
[1136]344 };
[1047]345
[875]346
[1136]347 class FitsOutFile : public FitsFile {
[875]348
[1136]349 public:
350 FitsOutFile();
351 FitsOutFile(char flnm[], bool OldFile=false);
[1143]352 ~FitsOutFile() { ;};
[1136]353 inline void InitNull() {imageOnPrimary_=false;}
354
355 //////////////////////////////////////////////////////////
356 /////// methods for managing extensions ////////////////
357 //////////////////////////////////////////////////////////
358
359
360
361/////////////////////////////////////////////////////////////
362// methods for managing FITS IMAGE extension
363///////////////////////////////////////////////////
364
365
366 inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
367
368 /*! create an IMAGE header on FITS file.
369\param <type> type of data (see method ColTypeFromFits)
370\param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
371\param <naxisn> array containind sizes of the different dimensions
372 */
[1143]373 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl) ;
[1136]374
[1143]375
[1136]376 /*! write double data from array 'map'on an IMAGE extension
377\param <nbData> number of data to be written
378
379 */
380 void putImageToFits( int nbData, double* map) const;
381
382 /*! same as previous method with float data */
383 void putImageToFits(int nbData, float* map ) const;
384
385 /*! same as previous method with int data */
386 void putImageToFits(int nbData, int* map) const;
387
388
389
390//////////////////////////////////////////////////////////////////////////
391// methods for managing FITS BINARY TABLE or ASCII TABLE extension
392////////////////////////////////////////////////////////////////////////
393
394
395
396 /*! create an BINTABLE header on FITS file.
[1143]397\param <fieldType> array conta
398ining characters denoting types of the different column (see method ColTypeFromFits)
[1136]399\param <Noms> array of the names of columns
400\param <nentries> number of data of each column
401\param <tfields> number of columns
402\param <dvl> a SOPHYA DVList containing keywords to be appended
403\param <extname> keyword EXTNAME for FITS file
404\param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
405 */
406 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ;
407
408 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
409\param <nentries> number of data to be written
410
411 */
412 void putColToFits(int nocol, int nentries, double* donnees) const;
413
414 /*! same as previous method with float data */
415 void putColToFits(int nocol, int nentries, float* donnees) const;
416
417 /*! same as previous method with int data */
418 void putColToFits(int nocol, int nentries, int* donnees) const;
419
420 /*! same as previous method with char* data */
421 void putColToFits(int nocol, int nentries, char** donnees) const;
422
[1143]423/////////////////////////////////////////////////////////////
424// methods for managing any type of FITS extension
425////////////////////////////////////////////////////////
426
427
428/* put keywords from a DVList into the primary header of the fits-file */
429void DVListIntoPrimaryHeader(DVList& dvl) const;
430
431
432
[1136]433 private :
434
435 void writeSignatureOnFits() const;
[1143]436 void addKeywordsOfDVList(DVList& dvl) const;
[1136]437
438 bool imageOnPrimary_;
439
440 };
441
442
443
[875]444} // Fin du namespace
445
446
[839]447#endif
Note: See TracBrowser for help on using the repository browser.