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

Last change on this file since 1661 was 1418, checked in by lemeur, 25 years ago

mots-cles maison type string

File size: 10.7 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 inline fitsfile* fitsfilePtr() {return fptr_;}
108
109
110 protected:
111
112 void ResetStatus(int& status) ;
113 static void printerror(int&) ;
114 static void printerror(int&,char* texte) ;
115 inline void InitNull() {fptr_ = NULL; hdutype_= FitsExtensionType_NULL; hdunum_ = 0;
116 fits_status_ = 0; imageOnPrimary_ = true;}
117 fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */
118 FitsExtensionType hdutype_; /**< image or bintable ? */
119 int hdunum_; /**< index of header to be read/written */
120 int fits_status_; /**< last status returned by fitsio library. updated only by several methods */
121 bool imageOnPrimary_;
122
123 };
124
125//! Class for saving SOPHYA objects on FITS Format Files (uses cfitsio lib)
126
127 class FitsInFile : public FitsFile {
128
129 public:
130 FitsInFile();
131 FitsInFile(string const & flnm);
132 FitsInFile(const char * flnm);
133 ~FitsInFile() { ; };
134
135 static int NbBlocks(char flnm[]);
136 int NbBlocks();
137 static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl );
138
139 void ReadHeader(int hdunum);
140bool hasKeyword(int hdunum, string keyw);
141string getStringKeyword(int hdunum, string keyname,int& retStatus);
142
143 /*! \return a reference on a DVList containing the keywords from FITS file */
144 inline const DVList& DVListFromFits() const { return dvl_;}
145
146 DVList DVListFromPrimaryHeader() const;
147 void moveToFollowingHeader();
148
149
150
151
152 //////////////////////////////////////////////////////////
153 /////// methods for managing extensions ////////////////
154 //////////////////////////////////////////////////////////
155
156
157/////////////////////////////////////////////////////////////
158// methods for managing FITS IMAGE extension
159///////////////////////////////////////////////////
160
161
162
163/*! \return true if the current header corresponds to a FITS image extension */
164inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);}
165
166
167
168 /*! \return number of dimensions of an image extension : NAXIS parameter (in FITS notations) */
169inline int nbDimOfImage() const {return naxis_;}
170
171/*! \return a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 etc. */
172 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
173
174
175/*! \return total number of data in the current IMAGE extension */
176inline int nbOfImageData() const { return nbData_; }
177
178/*! \return data type of the current IMAGE extension */
179inline FitsFile::FitsDataType ImageType() const {return imageDataType_;}
180
181
182//////////////////////////////////////////////////////////////////////////
183// methods for managing FITS BINARY TABLE or ASCII TABLE extension
184////////////////////////////////////////////////////////////////////////
185
186
187
188
189/*! \return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
190inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
191
192
193
194
195 static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
196 vector<int>& repeat,
197 vector<string>& noms,
198 vector<FitsDataType>& types,
199 vector<int>& taille_des_chaines);
200 FitsDataType ColTypeFromFits(int nocol) const;
201 string ColNameFromFits(int nocol) const;
202 int ColStringLengthFromFits(int nocol) const;
203 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
204** cdata) ;
205 void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
206 void GetBinTabLine(int NoLine, float* fdata) ;
207 void GetBinTabFCol(r_8* valeurs, int nentries, int NoCol) const;
208 void GetBinTabFCol(r_4* valeurs, int nentries, int NoCol) const;
209 void GetBinTabFCol(int_4* valeurs, int nentries, int NoCol) const;
210 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
211
212/////////////////////////////////////////////////////////////
213// methods for managing any type of FITS extension
214////////////////////////////////////////////////////////
215
216/*! \return true if the current header is beyond the maximum */
217inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
218/*! \return true if the current header is incorrect, following a cfitsio, movavs error */
219inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
220
221 int NbColsFromFits() const;
222 int NentriesFromFits(int nocol) const;
223
224
225 void GetSingleColumn(r_8* map, int nentries) const;
226
227 void GetSingleColumn(r_4* map, int nentries) const;
228
229 void GetSingleColumn(int_4* map, int nentries) const;
230
231
232
233
234
235 private :
236
237void InitNull();
238void getHeader();
239static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
240static void GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn);
241
242 FitsDataType imageDataType_; /**< fits-Image parameter (bitpix)*/
243 int naxis_; /**< fits-Image parameter */
244 vector<int> naxisn_; /**< fits-Image parameters : sizes of dimensions */
245 int nbData_; /*< fits-Image parameter: number of data */
246 int nrows_; /**< Bintable parameter */
247 vector<int> repeat_; /**< Bintable parameter */
248 int nbcols_; /**< Bintable parameter */
249 vector<string> noms_; /**< Bintable parameter: column names */
250 vector<FitsDataType> types_; /**< Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) */
251 DVList dvl_; /**< DVList for transferring keywords */
252 vector<int> taille_des_chaines_; /**< Bintable parameters: length of the char* variables */
253
254 };
255
256//! Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
257
258 class FitsOutFile : public FitsFile {
259
260 public:
261
262 FitsOutFile();
263 FitsOutFile(string const & flnm, WriteMode wrm = unknown );
264 FitsOutFile(const char * flnm, WriteMode wrm = unknown );
265 ~FitsOutFile() { if (dvlToPrimary_ != NULL) delete dvlToPrimary_;};
266 inline void InitNull() {dvlToPrimary_ = NULL;}
267
268 //////////////////////////////////////////////////////////
269 /////// methods for managing extensions ////////////////
270 //////////////////////////////////////////////////////////
271
272
273
274/////////////////////////////////////////////////////////////
275// methods for managing FITS IMAGE extension
276///////////////////////////////////////////////////
277
278
279 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
280 void PutImageToFits( int nbData, r_8* map) const;
281 void PutImageToFits(int nbData, r_4* map ) const;
282 void PutImageToFits(int nbData, int_4* map) const;
283
284
285
286//////////////////////////////////////////////////////////////////////////
287// methods for managing FITS BINARY TABLE or ASCII TABLE extension
288////////////////////////////////////////////////////////////////////////
289
290
291
292 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ;
293 void appendInputHeader(FitsInFile& headerin, int hdunum);
294 void writeAppendedHeaderOnFits();
295 void PrintHeaderToBeAppended();
296 void insertCommentLineOnHeader(string comment);
297 void insertKeywordOnHeader(string keyname, double value, string comment);
298 void insertKeywordOnHeader(string keyname, int value, string comment);
299 void insertKeywordOnHeader(string keyname, string value, string comment);
300 void PutColToFits(int nocol, int nentries, r_8* donnees) const;
301 void PutColToFits(int nocol, int nentries, r_4* donnees) const;
302 void PutColToFits(int nocol, int nentries, int_4* donnees) const;
303 void PutColToFits(int nocol, int nentries, char** donnees) const;
304 void PutBinTabLine(long NoLine, BnTblLine& ligne) const;
305
306
307/////////////////////////////////////////////////////////////
308// methods for managing any type of FITS extension
309////////////////////////////////////////////////////////
310
311
312void DVListIntoPrimaryHeader(DVList& dvl) ;
313
314
315
316 private :
317
318 void openoutputfitsfile(const char * flnm, WriteMode wrm);
319 void writeSignatureOnFits(int hdunum) const;
320 void addKeywordsOfDVList( DVList& dvl) const;
321 void addDVListOnPrimary();
322
323 DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
324 list<FitsKeyword> mots_cles_;
325
326 };
327
328 struct BnTblLine
329 {
330 BnTblLine() {}
331 void setFormat(int dc, int fc, int ic, int lc, int bc, int cc, vector<string> names);
332 bool sameFormat(const BnTblLine& btl) const;
333
334 void Print();
335
336 vector<double> ddata_;
337 vector<float> fdata_;
338 vector<int> idata_;
339 vector<string> cdata_;
340 vector<string> ColName_;
341 vector<long> ldata_;
342 vector<unsigned char> bdata_;
343
344 };
345
346
347
348
349
350} // Fin du namespace
351
352#endif
Note: See TracBrowser for help on using the repository browser.