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