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