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