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

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

fonction de manipulation directe de headers

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