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

Last change on this file since 2174 was 1978, checked in by lemeur, 23 years ago

suppression mots cles FITS de format, dans dvlist, en lecture

File size: 10.9 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
12// classes for saving/loading SOPHYA objects to/from FITS files...
13// Guy le Meur (september 2000)
14
15
16namespace SOPHYA {
17
18 struct BnTblLine;
19 class FitsFile;
20 class FitsInFile;
21 class FitsOutFile;
22
23
24
25class FitsKeyword
26{
27
28 public:
29
30FitsKeyword();
31FitsKeyword(string comment);
32FitsKeyword(string keyname, string value, string comment);
33FitsKeyword(string keyname, string value, string comment, char type);
34void writeOnFits(fitsfile* ptr);
35
36void Print();
37
38 private:
39
40 char datatype_;
41 string keyname_;
42 double dvalue_;
43 int ivalue_;
44 string svalue_;
45 string comment_;
46};
47
48
49
50//
51//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
52
53class FitsIOHandler {
54
55
56 public:
57
58 virtual ~FitsIOHandler() {}
59 void Read(char flnm[],int hdunum= 0);
60 void Write(char flnm[]) ;
61 void Read(FitsInFile& ifts, int hdunum=0);
62 void Write(FitsOutFile& ofts) ;
63
64
65 protected:
66
67 virtual void ReadFromFits(FitsInFile& is)=0;
68 virtual void WriteToFits(FitsOutFile& os) =0;
69
70 friend class FitsInFile;
71 friend class FitsOutFile;
72 };
73
74
75//! Class (virtual) for managing FITS format files
76 class FitsFile {
77
78 public:
79
80 enum WriteMode {append, clear, unknown};
81
82 enum FitsExtensionType {
83 FitsExtensionType_NULL,
84 FitsExtensionType_IMAGE,
85 FitsExtensionType_ASCII_TBL,
86 FitsExtensionType_BINARY_TBL,
87 FitsExtensionType_EOF,
88 FitsExtensionType_ERROR
89 };
90 enum FitsDataType {
91 FitsDataType_NULL,
92 FitsDataType_double,
93 FitsDataType_float,
94 FitsDataType_int,
95 FitsDataType_char,
96 FitsDataType_ASCII,
97 FitsDataType_long,
98 FitsDataType_byte
99 };
100
101 FitsFile() { InitNull(); };
102 virtual ~FitsFile();
103 static string GetErrStatus(int status);
104 inline int statusF() const { return fits_status_;}
105 inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;}
106 inline int currentHeaderIndex() {return hdunum_;}
107
108
109 protected:
110
111void ResetStatus(int& status) ;
112static void printerror(int&) ;
113static void printerror(int&,char* texte) ;
114static void printerrorAndContinue(int& status, char* texte);
115inline void InitNull()
116 {
117 fptr_ = NULL;
118 hdutype_= FitsExtensionType_NULL;
119 hdunum_ = 0;
120 fits_status_ = 0; imageOnPrimary_ = true;
121 }
122inline fitsfile* fitsfilePtr() const {return fptr_;}
123
124
125
126 fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */
127 FitsExtensionType hdutype_; /**< image or bintable ? */
128 int hdunum_; /**< index of header to be read/written */
129 int fits_status_; /**< last status returned by fitsio library. updated only by several methods */
130 bool imageOnPrimary_;
131
132 };
133
134//! Class for saving SOPHYA objects on FITS Format Files (uses cfitsio lib)
135
136 class FitsInFile : public FitsFile {
137
138 public:
139 FitsInFile();
140 FitsInFile(string const & flnm);
141 FitsInFile(const char * flnm);
142 ~FitsInFile() { ; };
143
144 static int NbBlocks(char flnm[]);
145 int NbBlocks();
146 static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl );
147
148 void ReadHeader(int hdunum);
149bool hasKeyword(int hdunum, string keyw);
150string getStringKeyword(int hdunum, string keyname,int& retStatus);
151
152 /*! \return a reference on a DVList containing the keywords from FITS file */
153 inline const DVList& DVListFromFits() const { return dvl_;}
154
155 void GetKeywordsFromHeader (int hdunum, list<FitsKeyword>& mots_cles) const;
156
157
158 DVList DVListFromPrimaryHeader() const;
159 void moveToFollowingHeader();
160
161
162
163
164 //////////////////////////////////////////////////////////
165 /////// methods for managing extensions ////////////////
166 //////////////////////////////////////////////////////////
167
168
169/////////////////////////////////////////////////////////////
170// methods for managing FITS IMAGE extension
171///////////////////////////////////////////////////
172
173
174
175/*! \return true if the current header corresponds to a FITS image extension */
176inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);}
177
178
179
180 /*! \return number of dimensions of an image extension : NAXIS parameter (in FITS notations) */
181inline int nbDimOfImage() const {return naxis_;}
182
183/*! \return a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 etc. */
184 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
185
186
187/*! \return total number of data in the current IMAGE extension */
188inline int nbOfImageData() const { return nbData_; }
189
190/*! \return data type of the current IMAGE extension */
191inline FitsFile::FitsDataType ImageType() const {return imageDataType_;}
192
193
194
195//////////////////////////////////////////////////////////////////////////
196// methods for managing FITS BINARY TABLE or ASCII TABLE extension
197////////////////////////////////////////////////////////////////////////
198
199
200
201
202/*! \return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
203inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
204
205
206
207
208 static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
209 vector<int>& repeat,
210 vector<string>& noms,
211 vector<FitsDataType>& types,
212 vector<int>& taille_des_chaines);
213 FitsDataType ColTypeFromFits(int nocol) const;
214 string ColNameFromFits(int nocol) const;
215 int ColStringLengthFromFits(int nocol) const;
216 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
217** cdata) ;
218 void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
219 void GetBinTabLine(int NoLine, float* fdata) ;
220 void GetBinTabFCol(r_8* valeurs, int nentries, int NoCol) const;
221 void GetBinTabFCol(r_4* valeurs, int nentries, int NoCol) const;
222 void GetBinTabFCol(int_4* valeurs, int nentries, int NoCol) const;
223 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
224
225/////////////////////////////////////////////////////////////
226// methods for managing any type of FITS extension
227////////////////////////////////////////////////////////
228
229/*! \return true if the current header is beyond the maximum */
230inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
231/*! \return true if the current header is incorrect, following a cfitsio, movavs error */
232inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
233
234 int NbColsFromFits() const;
235 int NentriesFromFits(int nocol) const;
236
237
238 void GetSingleColumn(r_8* map, int nentries) const;
239
240 void GetSingleColumn(r_4* map, int nentries) const;
241
242 void GetSingleColumn(int_4* map, int nentries) const;
243
244
245
246
247
248 private :
249
250void InitNull();
251
252void getHeaderWithSophyaObject();
253static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
254static void GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn);
255
256 FitsDataType imageDataType_; /**< fits-Image parameter (bitpix)*/
257 int naxis_; /**< fits-Image parameter */
258 vector<int> naxisn_; /**< fits-Image parameters : sizes of dimensions */
259 int nbData_; /*< fits-Image parameter: number of data */
260 int nrows_; /**< Bintable parameter */
261 vector<int> repeat_; /**< Bintable parameter */
262 int nbcols_; /**< Bintable parameter */
263 vector<string> noms_; /**< Bintable parameter: column names */
264 vector<FitsDataType> types_; /**< Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) */
265 DVList dvl_; /**< DVList for transferring keywords */
266 vector<int> taille_des_chaines_; /**< Bintable parameters: length of the char* variables */
267
268 double dnull_;
269 float fnull_;
270 int inull_;
271 string cnull_;
272
273
274
275 };
276
277//! Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
278
279 class FitsOutFile : public FitsFile {
280
281 public:
282
283 FitsOutFile();
284 FitsOutFile(string const & flnm, WriteMode wrm = unknown );
285 FitsOutFile(const char * flnm, WriteMode wrm = unknown );
286 ~FitsOutFile() { if (dvlToPrimary_ != NULL) delete dvlToPrimary_;};
287 inline void InitNull() {dvlToPrimary_ = NULL;}
288
289 //////////////////////////////////////////////////////////
290 /////// methods for managing extensions ////////////////
291 //////////////////////////////////////////////////////////
292
293
294
295/////////////////////////////////////////////////////////////
296// methods for managing FITS IMAGE extension
297///////////////////////////////////////////////////
298
299
300 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
301 void PutImageToFits( int nbData, r_8* map) const;
302 void PutImageToFits(int nbData, r_4* map ) const;
303 void PutImageToFits(int nbData, int_4* map) const;
304
305
306
307//////////////////////////////////////////////////////////////////////////
308// methods for managing FITS BINARY TABLE or ASCII TABLE extension
309////////////////////////////////////////////////////////////////////////
310
311
312
313 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ;
314 void appendInputHeader(FitsInFile& headerin, int hdunum);
315 void writeAppendedHeaderOnFits();
316 void PrintHeaderToBeAppended();
317 void insertCommentLineOnHeader(string comment);
318 void insertKeywordOnHeader(string keyname, double value, string comment);
319 void insertKeywordOnHeader(string keyname, int value, string comment);
320 void insertKeywordOnHeader(string keyname, string value, string comment);
321 void PutColToFits(int nocol, int nentries, r_8* donnees) const;
322 void PutColToFits(int nocol, int nentries, r_4* donnees) const;
323 void PutColToFits(int nocol, int nentries, int_4* donnees) const;
324 void PutColToFits(int nocol, int nentries, char** donnees) const;
325 void PutBinTabLine(long NoLine, BnTblLine& ligne) const;
326
327
328/////////////////////////////////////////////////////////////
329// methods for managing any type of FITS extension
330////////////////////////////////////////////////////////
331
332
333void DVListIntoPrimaryHeader(DVList& dvl) ;
334
335
336
337 private :
338
339 void openoutputfitsfile(const char * flnm, WriteMode wrm);
340 void writeSignatureOnFits(int hdunum) const;
341 void addKeywordsOfDVList( DVList& dvl) const;
342 void addDVListOnPrimary();
343
344 DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
345 list<FitsKeyword> mots_cles_;
346
347 };
348
349 struct BnTblLine
350 {
351 BnTblLine() {}
352 void setFormat(int dc, int fc, int ic, int lc, int bc, int cc, vector<string> names);
353 bool sameFormat(const BnTblLine& btl) const;
354
355 void Print();
356
357 vector<double> ddata_;
358 vector<float> fdata_;
359 vector<int> idata_;
360 vector<string> cdata_;
361 vector<string> ColName_;
362 vector<long> ldata_;
363 vector<unsigned char> bdata_;
364
365 };
366
367
368
369
370
371} // Fin du namespace
372
373#endif
Note: See TracBrowser for help on using the repository browser.