[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;
|
---|
[1193] | 22 |
|
---|
[1353] | 23 |
|
---|
| 24 |
|
---|
| 25 | class FitsKeyword
|
---|
| 26 | {
|
---|
| 27 |
|
---|
| 28 | public:
|
---|
| 29 |
|
---|
| 30 | FitsKeyword();
|
---|
| 31 | FitsKeyword(string comment);
|
---|
| 32 | FitsKeyword(string keyname, string value, string comment);
|
---|
| 33 | void writeOnFits(fitsfile* ptr);
|
---|
| 34 |
|
---|
| 35 | void Print();
|
---|
| 36 |
|
---|
| 37 | private:
|
---|
| 38 |
|
---|
| 39 | char datatype_;
|
---|
| 40 | string keyname_;
|
---|
| 41 | double dvalue_;
|
---|
| 42 | int ivalue_;
|
---|
| 43 | string svalue_;
|
---|
| 44 | string comment_;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 |
|
---|
[903] | 49 | //
|
---|
[1136] | 50 | //! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
|
---|
[875] | 51 |
|
---|
[1353] | 52 | class FitsIOHandler {
|
---|
[903] | 53 |
|
---|
| 54 |
|
---|
[1218] | 55 | public:
|
---|
[903] | 56 |
|
---|
[1218] | 57 | virtual ~FitsIOHandler() {}
|
---|
| 58 | void Read(char flnm[],int hdunum= 0);
|
---|
| 59 | void Write(char flnm[]) ;
|
---|
| 60 | void Read(FitsInFile& ifts, int hdunum=0);
|
---|
| 61 | void Write(FitsOutFile& ofts) ;
|
---|
[903] | 62 |
|
---|
[839] | 63 |
|
---|
[1218] | 64 | protected:
|
---|
| 65 |
|
---|
| 66 | virtual void ReadFromFits(FitsInFile& is)=0;
|
---|
| 67 | virtual void WriteToFits(FitsOutFile& os) =0;
|
---|
| 68 |
|
---|
| 69 | friend class FitsInFile;
|
---|
| 70 | friend class FitsOutFile;
|
---|
[1136] | 71 | };
|
---|
| 72 |
|
---|
| 73 |
|
---|
[1218] | 74 | //! Class (virtual) for managing FITS format files
|
---|
| 75 | class FitsFile {
|
---|
[1136] | 76 |
|
---|
[1218] | 77 | public:
|
---|
[1136] | 78 |
|
---|
[1231] | 79 | enum WriteMode {append, clear, unknown};
|
---|
| 80 |
|
---|
| 81 | enum FitsExtensionType {
|
---|
[1334] | 82 | FitsExtensionType_NULL,
|
---|
[1231] | 83 | FitsExtensionType_IMAGE,
|
---|
| 84 | FitsExtensionType_ASCII_TBL,
|
---|
[1334] | 85 | FitsExtensionType_BINARY_TBL,
|
---|
| 86 | FitsExtensionType_EOF,
|
---|
| 87 | FitsExtensionType_ERROR
|
---|
[1231] | 88 | };
|
---|
| 89 | enum FitsDataType {
|
---|
[1300] | 90 | FitsDataType_NULL,
|
---|
[1231] | 91 | FitsDataType_double,
|
---|
| 92 | FitsDataType_float,
|
---|
| 93 | FitsDataType_int,
|
---|
| 94 | FitsDataType_char,
|
---|
[1352] | 95 | FitsDataType_ASCII
|
---|
[1231] | 96 | };
|
---|
| 97 |
|
---|
[1218] | 98 | FitsFile() { InitNull(); };
|
---|
| 99 | virtual ~FitsFile();
|
---|
| 100 | static string GetErrStatus(int status);
|
---|
| 101 | inline int statusF() const { return fits_status_;}
|
---|
[1234] | 102 | inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;}
|
---|
[1300] | 103 | inline int currentHeaderIndex() {return hdunum_;}
|
---|
[1353] | 104 | inline fitsfile* fitsfilePtr() {return fptr_;}
|
---|
[1136] | 105 |
|
---|
| 106 |
|
---|
[1218] | 107 | protected:
|
---|
[1136] | 108 |
|
---|
[1218] | 109 | void ResetStatus(int& status) ;
|
---|
[1136] | 110 | static void printerror(int&) ;
|
---|
| 111 | static void printerror(int&,char* texte) ;
|
---|
[1334] | 112 | inline void InitNull() {fptr_ = NULL; hdutype_= FitsExtensionType_NULL; hdunum_ = 0;
|
---|
[1234] | 113 | fits_status_ = 0; imageOnPrimary_ = true;}
|
---|
[1218] | 114 | fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */
|
---|
[1334] | 115 | FitsExtensionType hdutype_; /**< image or bintable ? */
|
---|
[1218] | 116 | int hdunum_; /**< index of header to be read/written */
|
---|
| 117 | int fits_status_; /**< last status returned by fitsio library. updated only by several methods */
|
---|
[1234] | 118 | bool imageOnPrimary_;
|
---|
[1136] | 119 |
|
---|
[1218] | 120 | };
|
---|
[1136] | 121 |
|
---|
[1218] | 122 | //! Class for saving SOPHYA objects on FITS Format Files (uses cfitsio lib)
|
---|
[1136] | 123 |
|
---|
| 124 | class FitsInFile : public FitsFile {
|
---|
| 125 |
|
---|
| 126 | public:
|
---|
| 127 | FitsInFile();
|
---|
[1231] | 128 | FitsInFile(string const & flnm);
|
---|
| 129 | FitsInFile(const char * flnm);
|
---|
[1143] | 130 | ~FitsInFile() { ; };
|
---|
[1136] | 131 |
|
---|
[1218] | 132 | static int NbBlocks(char flnm[]);
|
---|
[1334] | 133 | int NbBlocks();
|
---|
[1231] | 134 | static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl );
|
---|
[1353] | 135 |
|
---|
| 136 | void ReadHeader(int hdunum);
|
---|
[1354] | 137 | bool hasKeyword(int hdunum, string keyw);
|
---|
| 138 | string getStringKeyword(int hdunum, string keyname,int& retStatus);
|
---|
[1353] | 139 |
|
---|
[1218] | 140 | /*! \return a reference on a DVList containing the keywords from FITS file */
|
---|
| 141 | inline const DVList& DVListFromFits() const { return dvl_;}
|
---|
[1136] | 142 |
|
---|
[1218] | 143 | DVList DVListFromPrimaryHeader() const;
|
---|
| 144 | void moveToFollowingHeader();
|
---|
[1047] | 145 |
|
---|
[1136] | 146 |
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | //////////////////////////////////////////////////////////
|
---|
| 150 | /////// methods for managing extensions ////////////////
|
---|
| 151 | //////////////////////////////////////////////////////////
|
---|
| 152 |
|
---|
| 153 |
|
---|
[1047] | 154 | /////////////////////////////////////////////////////////////
|
---|
[1136] | 155 | // methods for managing FITS IMAGE extension
|
---|
| 156 | ///////////////////////////////////////////////////
|
---|
[1047] | 157 |
|
---|
| 158 |
|
---|
[1218] | 159 |
|
---|
| 160 | /*! \return true if the current header corresponds to a FITS image extension */
|
---|
[1334] | 161 | inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);}
|
---|
[1047] | 162 |
|
---|
[1136] | 163 |
|
---|
| 164 |
|
---|
[1218] | 165 | /*! \return number of dimensions of an image extension : NAXIS parameter (in FITS notations) */
|
---|
[861] | 166 | inline int nbDimOfImage() const {return naxis_;}
|
---|
[1218] | 167 |
|
---|
| 168 | /*! \return a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 etc. */
|
---|
[1047] | 169 | inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
|
---|
[1218] | 170 |
|
---|
| 171 |
|
---|
| 172 | /*! \return total number of data in the current IMAGE extension */
|
---|
[839] | 173 | inline int nbOfImageData() const { return nbData_; }
|
---|
[903] | 174 |
|
---|
[1300] | 175 | /*! \return data type of the current IMAGE extension */
|
---|
| 176 | inline FitsFile::FitsDataType ImageType() const {return imageDataType_;}
|
---|
[903] | 177 |
|
---|
[1047] | 178 |
|
---|
[1136] | 179 | //////////////////////////////////////////////////////////////////////////
|
---|
| 180 | // methods for managing FITS BINARY TABLE or ASCII TABLE extension
|
---|
| 181 | ////////////////////////////////////////////////////////////////////////
|
---|
[1047] | 182 |
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 |
|
---|
[1218] | 186 | /*! \return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
|
---|
[1334] | 187 | inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
|
---|
[1047] | 188 |
|
---|
| 189 |
|
---|
[1353] | 190 |
|
---|
| 191 |
|
---|
[1218] | 192 | static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
[1136] | 193 | vector<int>& repeat,
|
---|
| 194 | vector<string>& noms,
|
---|
[1300] | 195 | vector<FitsDataType>& types,
|
---|
[1136] | 196 | vector<int>& taille_des_chaines);
|
---|
[1300] | 197 | FitsDataType ColTypeFromFits(int nocol) const;
|
---|
[1218] | 198 | string ColNameFromFits(int nocol) const;
|
---|
| 199 | int ColStringLengthFromFits(int nocol) const;
|
---|
| 200 | void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
|
---|
[1047] | 201 | ** cdata) ;
|
---|
[1218] | 202 | void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
|
---|
| 203 | void GetBinTabLine(int NoLine, float* fdata) ;
|
---|
[1352] | 204 | void GetBinTabFCol(r_8* valeurs, int nentries, int NoCol) const;
|
---|
| 205 | void GetBinTabFCol(r_4* valeurs, int nentries, int NoCol) const;
|
---|
| 206 | void GetBinTabFCol(int_4* valeurs, int nentries, int NoCol) const;
|
---|
[1218] | 207 | void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
|
---|
[1047] | 208 |
|
---|
[1136] | 209 | /////////////////////////////////////////////////////////////
|
---|
| 210 | // methods for managing any type of FITS extension
|
---|
| 211 | ////////////////////////////////////////////////////////
|
---|
[1045] | 212 |
|
---|
[1334] | 213 | /*! \return true if the current header is beyond the maximum */
|
---|
| 214 | inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
|
---|
| 215 | /*! \return true if the current header is incorrect, following a cfitsio, movavs error */
|
---|
| 216 | inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
|
---|
| 217 |
|
---|
[1136] | 218 | int NbColsFromFits() const;
|
---|
| 219 | int NentriesFromFits(int nocol) const;
|
---|
[1045] | 220 |
|
---|
| 221 |
|
---|
[1352] | 222 | void GetSingleColumn(r_8* map, int nentries) const;
|
---|
[903] | 223 |
|
---|
[1352] | 224 | void GetSingleColumn(r_4* map, int nentries) const;
|
---|
[839] | 225 |
|
---|
[1352] | 226 | void GetSingleColumn(int_4* map, int nentries) const;
|
---|
[1047] | 227 |
|
---|
[1353] | 228 |
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 |
|
---|
[1136] | 232 | private :
|
---|
[1047] | 233 |
|
---|
[1136] | 234 | void InitNull();
|
---|
[1234] | 235 | void getHeader();
|
---|
[1136] | 236 | static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
|
---|
[1300] | 237 | static void GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn);
|
---|
[839] | 238 |
|
---|
[1300] | 239 | FitsDataType imageDataType_; /**< fits-Image parameter (bitpix)*/
|
---|
[1218] | 240 | int naxis_; /**< fits-Image parameter */
|
---|
| 241 | vector<int> naxisn_; /**< fits-Image parameters : sizes of dimensions */
|
---|
| 242 | int nbData_; /*< fits-Image parameter: number of data */
|
---|
| 243 | int nrows_; /**< Bintable parameter */
|
---|
| 244 | vector<int> repeat_; /**< Bintable parameter */
|
---|
| 245 | int nbcols_; /**< Bintable parameter */
|
---|
| 246 | vector<string> noms_; /**< Bintable parameter: column names */
|
---|
[1300] | 247 | vector<FitsDataType> types_; /**< Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) */
|
---|
[1218] | 248 | DVList dvl_; /**< DVList for transferring keywords */
|
---|
| 249 | vector<int> taille_des_chaines_; /**< Bintable parameters: length of the char* variables */
|
---|
[839] | 250 |
|
---|
[1136] | 251 | };
|
---|
[1047] | 252 |
|
---|
[1218] | 253 | //! Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
[875] | 254 |
|
---|
[1136] | 255 | class FitsOutFile : public FitsFile {
|
---|
[875] | 256 |
|
---|
[1136] | 257 | public:
|
---|
[1193] | 258 |
|
---|
[1136] | 259 | FitsOutFile();
|
---|
[1231] | 260 | FitsOutFile(string const & flnm, WriteMode wrm = unknown );
|
---|
| 261 | FitsOutFile(const char * flnm, WriteMode wrm = unknown );
|
---|
[1246] | 262 | ~FitsOutFile() { if (dvlToPrimary_ != NULL) delete dvlToPrimary_;};
|
---|
| 263 | inline void InitNull() {dvlToPrimary_ = NULL;}
|
---|
[1136] | 264 |
|
---|
| 265 | //////////////////////////////////////////////////////////
|
---|
| 266 | /////// methods for managing extensions ////////////////
|
---|
| 267 | //////////////////////////////////////////////////////////
|
---|
| 268 |
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | /////////////////////////////////////////////////////////////
|
---|
| 272 | // methods for managing FITS IMAGE extension
|
---|
| 273 | ///////////////////////////////////////////////////
|
---|
| 274 |
|
---|
| 275 |
|
---|
[1221] | 276 | void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
|
---|
[1352] | 277 | void PutImageToFits( int nbData, r_8* map) const;
|
---|
| 278 | void PutImageToFits(int nbData, r_4* map ) const;
|
---|
| 279 | void PutImageToFits(int nbData, int_4* map) const;
|
---|
[1136] | 280 |
|
---|
| 281 |
|
---|
[1143] | 282 |
|
---|
[1136] | 283 | //////////////////////////////////////////////////////////////////////////
|
---|
| 284 | // methods for managing FITS BINARY TABLE or ASCII TABLE extension
|
---|
| 285 | ////////////////////////////////////////////////////////////////////////
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 |
|
---|
[1221] | 289 | void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname, vector<int> taille_des_chaines) ;
|
---|
[1353] | 290 | void appendInputHeader(FitsInFile& headerin, int hdunum);
|
---|
| 291 | void writeAppendedHeaderOnFits();
|
---|
| 292 | void PrintHeaderToBeAppended();
|
---|
| 293 | void insertCommentLineOnHeader(string comment);
|
---|
| 294 | void insertKeywordOnHeader(string keyname, double value, string comment);
|
---|
[1352] | 295 | void PutColToFits(int nocol, int nentries, r_8* donnees) const;
|
---|
| 296 | void PutColToFits(int nocol, int nentries, r_4* donnees) const;
|
---|
| 297 | void PutColToFits(int nocol, int nentries, int_4* donnees) const;
|
---|
[1218] | 298 | void PutColToFits(int nocol, int nentries, char** donnees) const;
|
---|
| 299 | void PutBinTabLine(long NoLine, BnTblLine& ligne) const;
|
---|
[1136] | 300 |
|
---|
| 301 |
|
---|
[1143] | 302 | /////////////////////////////////////////////////////////////
|
---|
| 303 | // methods for managing any type of FITS extension
|
---|
| 304 | ////////////////////////////////////////////////////////
|
---|
| 305 |
|
---|
| 306 |
|
---|
[1246] | 307 | void DVListIntoPrimaryHeader(DVList& dvl) ;
|
---|
[1143] | 308 |
|
---|
| 309 |
|
---|
| 310 |
|
---|
[1136] | 311 | private :
|
---|
| 312 |
|
---|
[1231] | 313 | void openoutputfitsfile(const char * flnm, WriteMode wrm);
|
---|
[1246] | 314 | void writeSignatureOnFits(int hdunum) const;
|
---|
| 315 | void addKeywordsOfDVList( DVList& dvl) const;
|
---|
| 316 | void addDVListOnPrimary();
|
---|
[1136] | 317 |
|
---|
[1246] | 318 | DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
|
---|
[1353] | 319 | list<FitsKeyword> mots_cles_;
|
---|
| 320 |
|
---|
[1136] | 321 | };
|
---|
| 322 |
|
---|
[1218] | 323 | struct BnTblLine
|
---|
| 324 | {
|
---|
| 325 | BnTblLine() {}
|
---|
| 326 | void setFormat(int dc, int fc, int ic, int cc, vector<string> names);
|
---|
| 327 | bool sameFormat(const BnTblLine& btl) const;
|
---|
[1136] | 328 |
|
---|
[1218] | 329 | void Print();
|
---|
[1136] | 330 |
|
---|
[1218] | 331 | vector<double> ddata_;
|
---|
| 332 | vector<float> fdata_;
|
---|
| 333 | vector<int> idata_;
|
---|
| 334 | vector<string> cdata_;
|
---|
| 335 | vector<string> ColName_;
|
---|
| 336 | };
|
---|
| 337 |
|
---|
| 338 |
|
---|
[1353] | 339 |
|
---|
| 340 |
|
---|
| 341 |
|
---|
[875] | 342 | } // Fin du namespace
|
---|
| 343 |
|
---|
[839] | 344 | #endif
|
---|