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

Last change on this file since 2013 was 1978, checked in by lemeur, 23 years ago

suppression mots cles FITS de format, dans dvlist, en lecture

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