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

Last change on this file since 1824 was 1771, checked in by lemeur, 24 years ago

mises a jour pour ELDESTINO

File size: 10.8 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();
251void getHeaderWithSophyaObject();
252static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
253static void GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn);
254
255 FitsDataType imageDataType_; /**< fits-Image parameter (bitpix)*/
256 int naxis_; /**< fits-Image parameter */
257 vector<int> naxisn_; /**< fits-Image parameters : sizes of dimensions */
258 int nbData_; /*< fits-Image parameter: number of data */
259 int nrows_; /**< Bintable parameter */
260 vector<int> repeat_; /**< Bintable parameter */
261 int nbcols_; /**< Bintable parameter */
262 vector<string> noms_; /**< Bintable parameter: column names */
263 vector<FitsDataType> types_; /**< Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) */
264 DVList dvl_; /**< DVList for transferring keywords */
265 vector<int> taille_des_chaines_; /**< Bintable parameters: length of the char* variables */
266
267 };
268
269//! Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
270
271 class FitsOutFile : public FitsFile {
272
273 public:
274
275 FitsOutFile();
276 FitsOutFile(string const & flnm, WriteMode wrm = unknown );
277 FitsOutFile(const char * flnm, WriteMode wrm = unknown );
278 ~FitsOutFile() { if (dvlToPrimary_ != NULL) delete dvlToPrimary_;};
279 inline void InitNull() {dvlToPrimary_ = NULL;}
280
281 //////////////////////////////////////////////////////////
282 /////// methods for managing extensions ////////////////
283 //////////////////////////////////////////////////////////
284
285
286
287/////////////////////////////////////////////////////////////
288// methods for managing FITS IMAGE extension
289///////////////////////////////////////////////////
290
291
292 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
293 void PutImageToFits( int nbData, r_8* map) const;
294 void PutImageToFits(int nbData, r_4* map ) const;
295 void PutImageToFits(int nbData, int_4* map) const;
296
297
298
299//////////////////////////////////////////////////////////////////////////
300// methods for managing FITS BINARY TABLE or ASCII TABLE extension
301////////////////////////////////////////////////////////////////////////
302
303
304
305 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ;
306 void appendInputHeader(FitsInFile& headerin, int hdunum);
307 void writeAppendedHeaderOnFits();
308 void PrintHeaderToBeAppended();
309 void insertCommentLineOnHeader(string comment);
310 void insertKeywordOnHeader(string keyname, double value, string comment);
311 void insertKeywordOnHeader(string keyname, int value, string comment);
312 void insertKeywordOnHeader(string keyname, string value, string comment);
313 void PutColToFits(int nocol, int nentries, r_8* donnees) const;
314 void PutColToFits(int nocol, int nentries, r_4* donnees) const;
315 void PutColToFits(int nocol, int nentries, int_4* donnees) const;
316 void PutColToFits(int nocol, int nentries, char** donnees) const;
317 void PutBinTabLine(long NoLine, BnTblLine& ligne) const;
318
319
320/////////////////////////////////////////////////////////////
321// methods for managing any type of FITS extension
322////////////////////////////////////////////////////////
323
324
325void DVListIntoPrimaryHeader(DVList& dvl) ;
326
327
328
329 private :
330
331 void openoutputfitsfile(const char * flnm, WriteMode wrm);
332 void writeSignatureOnFits(int hdunum) const;
333 void addKeywordsOfDVList( DVList& dvl) const;
334 void addDVListOnPrimary();
335
336 DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
337 list<FitsKeyword> mots_cles_;
338
339 };
340
341 struct BnTblLine
342 {
343 BnTblLine() {}
344 void setFormat(int dc, int fc, int ic, int lc, int bc, int cc, vector<string> names);
345 bool sameFormat(const BnTblLine& btl) const;
346
347 void Print();
348
349 vector<double> ddata_;
350 vector<float> fdata_;
351 vector<int> idata_;
352 vector<string> cdata_;
353 vector<string> ColName_;
354 vector<long> ldata_;
355 vector<unsigned char> bdata_;
356
357 };
358
359
360
361
362
363} // Fin du namespace
364
365#endif
Note: See TracBrowser for help on using the repository browser.