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

Last change on this file since 1301 was 1300, checked in by ansari, 25 years ago

classe FITS_AutoReader

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