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

Last change on this file since 2860 was 2860, checked in by ansari, 20 years ago

Ajout constructeur de copie (pas parfait) pour FitsInOutFile + modifs classes FitsFile/FitsInFile/FitsOutFile pour heriter de FitsInOutFile avec constructeur a partir de FitsInOutFile - Reza 20/12/2005

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