[3537] | 1 | #ifndef MINIFITS_H_SEEN
|
---|
| 2 | #define MINIFITS_H_SEEN
|
---|
| 3 |
|
---|
| 4 | #include <stdio.h>
|
---|
[3658] | 5 | #include <exception>
|
---|
[3537] | 6 | #include <string>
|
---|
| 7 |
|
---|
| 8 | #include "brtypes.h"
|
---|
| 9 |
|
---|
| 10 | /*
|
---|
| 11 | Classe d'I/O simplifie FITS pour ACQ BAO-radio
|
---|
| 12 | R. Ansari, C. Magneville - Fev 2008
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | using namespace std;
|
---|
| 16 |
|
---|
[3658] | 17 | #define MFEX_MAXMSGLEN 160
|
---|
| 18 |
|
---|
| 19 | class MiniFITSException : public std::exception {
|
---|
[3537] | 20 | public:
|
---|
[3658] | 21 | explicit MiniFITSException(const char * m) throw() ;
|
---|
| 22 | explicit MiniFITSException(const string& m) throw() ;
|
---|
| 23 | virtual ~MiniFITSException() throw() ;
|
---|
| 24 | //! Implementation of std::exception what() method, returning the exception message
|
---|
| 25 | virtual const char* what() const throw();
|
---|
| 26 | virtual string const Msg() const ;
|
---|
[3537] | 27 | private:
|
---|
[3658] | 28 | char msg_[MFEX_MAXMSGLEN];
|
---|
[3537] | 29 | };
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | enum MiniFITS_DT { MF_Byte, MF_Int16, MF_Float32 };
|
---|
| 33 | enum MiniFITS_Mode { MF_Read, MF_Write };
|
---|
| 34 |
|
---|
| 35 | class MiniFITSFile {
|
---|
| 36 | public:
|
---|
| 37 | MiniFITSFile();
|
---|
| 38 | MiniFITSFile(string const & nom, MiniFITS_Mode rwm);
|
---|
| 39 | MiniFITSFile(const char* nom, MiniFITS_Mode rwm);
|
---|
| 40 |
|
---|
| 41 | ~MiniFITSFile();
|
---|
| 42 |
|
---|
| 43 | void Open(const char* nom, MiniFITS_Mode rwm);
|
---|
| 44 | inline void Open(string const & nom, MiniFITS_Mode rwm)
|
---|
| 45 | { return Open(nom.c_str(), rwm); }
|
---|
| 46 |
|
---|
| 47 | void Close();
|
---|
| 48 |
|
---|
| 49 | inline MiniFITS_DT DataType() { return dtype; }
|
---|
| 50 | string DataTypeToString();
|
---|
| 51 |
|
---|
| 52 | size_t NAxis1() { return nax1; }
|
---|
| 53 | size_t NAxis2() { return nax2; }
|
---|
| 54 |
|
---|
| 55 | void setDTypeNaxis(MiniFITS_DT dt, size_t na1, size_t na2);
|
---|
| 56 |
|
---|
| 57 | // Lecture avec indication de la taille (nb d'elements) et offset
|
---|
| 58 | int Read(void* data, size_t sz, size_t offset=0);
|
---|
| 59 | inline int ReadB(Byte* data, size_t nel, size_t offsel=0)
|
---|
| 60 | { return ( Read((void *)data, nel, offsel) ); }
|
---|
| 61 | inline int ReadI(Int16* data, size_t nel, size_t offsel=0)
|
---|
| 62 | { return ( Read((void *)data, nel*sizeof(Int16), offsel*sizeof(Int16)) ); }
|
---|
| 63 | inline int ReadF(Float32* data, size_t nel, size_t offsel=0)
|
---|
| 64 | { return ( Read((void *)data, nel*sizeof(Float32), offsel*sizeof(Float32)) ); }
|
---|
| 65 |
|
---|
| 66 | // Ecriture en mode append (fin de fichier)
|
---|
| 67 | int Write(void* data, size_t sz);
|
---|
| 68 | inline int WriteB(Byte* data, size_t nel)
|
---|
| 69 | { return ( Write((void *)data, nel) ); }
|
---|
| 70 | inline int WriteI(Int16* data, size_t nel)
|
---|
| 71 | { return ( Write((void *)data, nel*sizeof(Int16)) ); }
|
---|
| 72 | inline int WriteF(Float32* data, size_t nel)
|
---|
| 73 | { return ( Write((void *)data, nel*sizeof(Float32)) ); }
|
---|
| 74 |
|
---|
[3658] | 75 | // Ajout de mots-cle a l'entete FITS
|
---|
| 76 | int AddKeyI(const char* key, long val, const char* comm=NULL);
|
---|
| 77 | inline int AddKeyI(string const& key, long val)
|
---|
| 78 | { return AddKeyI(key.c_str(), val); }
|
---|
| 79 | inline int AddKeyI(string const& key, long val, string const& comm)
|
---|
| 80 | { return AddKeyI(key.c_str(), val, comm.c_str()); }
|
---|
| 81 | int AddKeyD(const char* key, double val, const char* comm=NULL);
|
---|
| 82 | inline int AddKeyD(string const& key, double val)
|
---|
| 83 | { return AddKeyD(key.c_str(), val); }
|
---|
| 84 | inline int AddKeyD(string const& key, double val, string const& comm)
|
---|
| 85 | { return AddKeyD(key.c_str(), val, comm.c_str()); }
|
---|
| 86 | int AddKeyS(const char* key, const char* val, const char* comm=NULL);
|
---|
| 87 | inline int AddKeyS(string const& key, string const& val)
|
---|
| 88 | { return AddKeyS(key.c_str(), val.c_str()); }
|
---|
| 89 | inline int AddKeyS(string const& key, string const& val, string const& comm)
|
---|
| 90 | { return AddKeyS(key.c_str(), val.c_str(), comm.c_str()); }
|
---|
| 91 |
|
---|
[3537] | 92 | // string getKey(string& key);
|
---|
| 93 | protected:
|
---|
| 94 | void FillHeader();
|
---|
| 95 | void DecodeHeader();
|
---|
| 96 | void Init();
|
---|
| 97 |
|
---|
| 98 | FILE* fip;
|
---|
| 99 | MiniFITS_Mode rwmode;
|
---|
| 100 | MiniFITS_DT dtype;
|
---|
| 101 | size_t nax1, nax2;
|
---|
| 102 | size_t totwsz; // total bytes ecrits
|
---|
| 103 | char* header; // entete FITS
|
---|
[3658] | 104 | int nkeya_; //
|
---|
[3537] | 105 | };
|
---|
| 106 |
|
---|
| 107 | #endif
|
---|