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

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

Mise en place de l heritage FitsIOHandler (ancien) de FitsHandlerInterface pour une gestion commune - a partir de FitsManager - Reza 13/01/2006

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