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

Last change on this file since 4025 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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