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

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

debug/check fits : gestion NTuple colonnes double + init hdunum_ ds FitsFile(FitsInOutFile&) + correction gestion TArray/TMatrix/TVector ds fitsarrhand.h - Reza 17/01/2006

File size: 13.0 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) ;
[2907]287 void GetBinTabLine(int NoLine, double* ddata) ;
[1352]288 void GetBinTabFCol(r_8* valeurs, int nentries, int NoCol) const;
289 void GetBinTabFCol(r_4* valeurs, int nentries, int NoCol) const;
290 void GetBinTabFCol(int_4* valeurs, int nentries, int NoCol) const;
[1218]291 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
[1047]292
[1136]293/////////////////////////////////////////////////////////////
294// methods for managing any type of FITS extension
295////////////////////////////////////////////////////////
[1045]296
[1334]297/*! \return true if the current header is beyond the maximum */
298inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
299/*! \return true if the current header is incorrect, following a cfitsio, movavs error */
300inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
301
[1136]302 int NbColsFromFits() const;
303 int NentriesFromFits(int nocol) const;
[1045]304
305
[1352]306 void GetSingleColumn(r_8* map, int nentries) const;
[903]307
[1352]308 void GetSingleColumn(r_4* map, int nentries) const;
[839]309
[1352]310 void GetSingleColumn(int_4* map, int nentries) const;
[1047]311
[1353]312
313
314
315
[1136]316 private :
[1047]317
[1136]318void InitNull();
[1978]319
[1771]320void getHeaderWithSophyaObject();
[1136]321static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
[1300]322static void GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn);
[839]323
[1300]324 FitsDataType imageDataType_; /**< fits-Image parameter (bitpix)*/
[1218]325 int naxis_; /**< fits-Image parameter */
326 vector<int> naxisn_; /**< fits-Image parameters : sizes of dimensions */
327 int nbData_; /*< fits-Image parameter: number of data */
328 int nrows_; /**< Bintable parameter */
329 vector<int> repeat_; /**< Bintable parameter */
330 int nbcols_; /**< Bintable parameter */
331 vector<string> noms_; /**< Bintable parameter: column names */
[1300]332 vector<FitsDataType> types_; /**< Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) */
[1218]333 DVList dvl_; /**< DVList for transferring keywords */
334 vector<int> taille_des_chaines_; /**< Bintable parameters: length of the char* variables */
[839]335
[1978]336 double dnull_;
337 float fnull_;
338 int inull_;
339 string cnull_;
340
341
342
[1136]343 };
[1047]344
[1218]345//! Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
[875]346
[1136]347 class FitsOutFile : public FitsFile {
[875]348
[1136]349 public:
[1193]350
[1136]351 FitsOutFile();
[1231]352 FitsOutFile(string const & flnm, WriteMode wrm = unknown );
353 FitsOutFile(const char * flnm, WriteMode wrm = unknown );
[2860]354 FitsOutFile(FitsInOutFile const& fios);
355 virtual ~FitsOutFile();
[1246]356 inline void InitNull() {dvlToPrimary_ = NULL;}
[1136]357
358 //////////////////////////////////////////////////////////
359 /////// methods for managing extensions ////////////////
360 //////////////////////////////////////////////////////////
361
362
363
364/////////////////////////////////////////////////////////////
365// methods for managing FITS IMAGE extension
366///////////////////////////////////////////////////
367
368
[1221]369 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
[1352]370 void PutImageToFits( int nbData, r_8* map) const;
371 void PutImageToFits(int nbData, r_4* map ) const;
372 void PutImageToFits(int nbData, int_4* map) const;
[1136]373
374
[1143]375
[1136]376//////////////////////////////////////////////////////////////////////////
377// methods for managing FITS BINARY TABLE or ASCII TABLE extension
378////////////////////////////////////////////////////////////////////////
379
380
381
[1221]382 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ;
[1353]383 void appendInputHeader(FitsInFile& headerin, int hdunum);
384 void writeAppendedHeaderOnFits();
385 void PrintHeaderToBeAppended();
386 void insertCommentLineOnHeader(string comment);
[1418]387 void insertKeywordOnHeader(string keyname, double value, string comment);
388 void insertKeywordOnHeader(string keyname, int value, string comment);
389 void insertKeywordOnHeader(string keyname, string value, string comment);
[1352]390 void PutColToFits(int nocol, int nentries, r_8* donnees) const;
391 void PutColToFits(int nocol, int nentries, r_4* donnees) const;
392 void PutColToFits(int nocol, int nentries, int_4* donnees) const;
[1218]393 void PutColToFits(int nocol, int nentries, char** donnees) const;
394 void PutBinTabLine(long NoLine, BnTblLine& ligne) const;
[1136]395
396
[1143]397/////////////////////////////////////////////////////////////
398// methods for managing any type of FITS extension
399////////////////////////////////////////////////////////
400
401
[1246]402void DVListIntoPrimaryHeader(DVList& dvl) ;
[1143]403
404
405
[1136]406 private :
407
[1231]408 void openoutputfitsfile(const char * flnm, WriteMode wrm);
[1246]409 void writeSignatureOnFits(int hdunum) const;
410 void addKeywordsOfDVList( DVList& dvl) const;
411 void addDVListOnPrimary();
[1136]412
[1246]413 DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
[1353]414 list<FitsKeyword> mots_cles_;
415
[1136]416 };
417
[1218]418 struct BnTblLine
419 {
420 BnTblLine() {}
[1359]421 void setFormat(int dc, int fc, int ic, int lc, int bc, int cc, vector<string> names);
[1218]422 bool sameFormat(const BnTblLine& btl) const;
[1136]423
[1218]424 void Print();
[1136]425
[1218]426 vector<double> ddata_;
427 vector<float> fdata_;
[1359]428 vector<int> idata_;
[1218]429 vector<string> cdata_;
430 vector<string> ColName_;
[1359]431 vector<long> ldata_;
432 vector<unsigned char> bdata_;
433
[1218]434 };
435
436
[1353]437
[875]438} // Fin du namespace
439
[839]440#endif
Note: See TracBrowser for help on using the repository browser.