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

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

lecture de spheres fits, sans NSIDE ni LASTPIX

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