[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 |
|
---|
[875] | 12 | namespace SOPHYA {
|
---|
| 13 |
|
---|
[903] | 14 | //
|
---|
| 15 | //! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
|
---|
[875] | 16 |
|
---|
[903] | 17 | /*!
|
---|
| 18 |
|
---|
| 19 | Each SOPHYA object XXX is associated with a object of class FITS_XXX
|
---|
| 20 | (inheriting from FitsFile), to which input/output operations with FITS
|
---|
| 21 | files are delegated. A typical example of use is the following :
|
---|
| 22 |
|
---|
| 23 | \verbatim
|
---|
| 24 | int m=... ;
|
---|
| 25 | SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object
|
---|
| 26 | .... fill the sphere ....
|
---|
| 27 |
|
---|
| 28 | FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
|
---|
| 29 | // delegated object
|
---|
| 30 | fits_sph.Write("myfile.fits"); // writing on FITS file
|
---|
| 31 |
|
---|
| 32 | FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
|
---|
| 33 | // load a delegated object
|
---|
| 34 | // from FITS file
|
---|
| 35 | SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
|
---|
| 36 | // casting the delegated object
|
---|
| 37 | // into a SOPHYA object
|
---|
| 38 | \endverbatim
|
---|
| 39 |
|
---|
| 40 | */
|
---|
[839] | 41 | class FitsFile
|
---|
| 42 | {
|
---|
| 43 |
|
---|
| 44 | public:
|
---|
| 45 |
|
---|
| 46 | FitsFile();
|
---|
| 47 | virtual ~FitsFile();
|
---|
[903] | 48 | static int NbBlocks(char flnm[]);
|
---|
| 49 | static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl );
|
---|
| 50 | /*! return true if the current header corresponds to a FITS image extension */
|
---|
| 51 | inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
|
---|
[839] | 52 |
|
---|
[903] | 53 | /*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */
|
---|
[839] | 54 | inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
|
---|
[903] | 55 |
|
---|
| 56 | /*!
|
---|
| 57 | this method is called from inherited objects :
|
---|
| 58 |
|
---|
| 59 | moves to header 'hdunum' on file 'flnm'
|
---|
| 60 |
|
---|
| 61 | gets parameters in header
|
---|
| 62 |
|
---|
| 63 | calls the method 'ReadFromFits' from the inherited delegated object
|
---|
| 64 |
|
---|
| 65 | */
|
---|
| 66 | void ReadF(char flnm[],int hdunum= 0);
|
---|
| 67 |
|
---|
| 68 | /*!
|
---|
| 69 | this method is called from inherited objects :
|
---|
| 70 |
|
---|
| 71 | opens a file 'flnm'
|
---|
| 72 |
|
---|
| 73 | gets parameters in header
|
---|
| 74 |
|
---|
| 75 | calls the method 'ReadFromFits' from the inherited delegated object
|
---|
| 76 |
|
---|
| 77 | */
|
---|
[839] | 78 | void WriteF(char flnm[],int hdunum= 0);
|
---|
[903] | 79 |
|
---|
| 80 |
|
---|
| 81 | /*!
|
---|
| 82 | fill the array 'map' with double data from the current extension on FITS file.
|
---|
| 83 | If the extension is BINTABLE, the first column is provided.
|
---|
| 84 |
|
---|
| 85 | \param <nentries> number of data to be read
|
---|
| 86 | */
|
---|
[839] | 87 | void GetSingleColumn(double* map, int nentries) const;
|
---|
[903] | 88 |
|
---|
| 89 | /*! same as above with float data */
|
---|
[839] | 90 | void GetSingleColumn(float* map, int nentries) const;
|
---|
[903] | 91 |
|
---|
| 92 | /*! same as above with int data */
|
---|
[839] | 93 | void GetSingleColumn(int* map, int nentries) const;
|
---|
[903] | 94 |
|
---|
| 95 | /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
|
---|
| 96 | */
|
---|
[861] | 97 | inline int nbDimOfImage() const {return naxis_;}
|
---|
[903] | 98 |
|
---|
| 99 | /*!
|
---|
| 100 | total number of data in the current IMAGE extension
|
---|
| 101 | */
|
---|
[839] | 102 | inline int nbOfImageData() const { return nbData_; }
|
---|
[903] | 103 |
|
---|
| 104 | /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
|
---|
| 105 | */
|
---|
[861] | 106 | inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
|
---|
[903] | 107 |
|
---|
| 108 | /*! return number of columns (return 1 if IMAGE) */
|
---|
[839] | 109 | int NbColsFromFits() const;
|
---|
[903] | 110 |
|
---|
| 111 | /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
|
---|
| 112 |
|
---|
| 113 | D : double
|
---|
| 114 |
|
---|
| 115 | E : float
|
---|
| 116 |
|
---|
| 117 | I : integer
|
---|
| 118 |
|
---|
| 119 | S : character string
|
---|
| 120 |
|
---|
| 121 | */
|
---|
[839] | 122 | char ColTypeFromFits(int nocol) const;
|
---|
[903] | 123 |
|
---|
| 124 | /*! number of data in the current IMAGE extension on FITS file, or number
|
---|
| 125 | of data of column number 'nocol' of the current BINTABLE extension
|
---|
| 126 | */
|
---|
[839] | 127 | int NentriesFromFits(int nocol) const;
|
---|
[903] | 128 |
|
---|
| 129 | /*! name of the column number 'nocol' of the current BINTABLE extension
|
---|
| 130 | */
|
---|
[839] | 131 | string ColNameFromFits(int nocol) const;
|
---|
[903] | 132 |
|
---|
| 133 |
|
---|
| 134 | /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
|
---|
| 135 | */
|
---|
[839] | 136 | int ColStringLengthFromFits(int nocol) const;
|
---|
[903] | 137 |
|
---|
| 138 | /*! return a reference on a DVList containing the keywords from FITS file
|
---|
| 139 | */
|
---|
[839] | 140 | inline const DVList& DVListFromFits() const { return dvl_;}
|
---|
[903] | 141 |
|
---|
| 142 |
|
---|
| 143 | /*!
|
---|
| 144 | fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
|
---|
| 145 |
|
---|
| 146 | \param <nentries> number of data to be read
|
---|
| 147 | */
|
---|
[839] | 148 | void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 149 |
|
---|
| 150 | /*! same as previous method with float data */
|
---|
[839] | 151 | void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 152 | /*! same as previous method with int data */
|
---|
[839] | 153 | void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 154 | /*! same as previous method with char* data */
|
---|
[839] | 155 | void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
|
---|
| 156 | // Write elements into the FITS data array
|
---|
[903] | 157 |
|
---|
| 158 | /*! write double data from array 'map'on an IMAGE extension
|
---|
| 159 | \param <nbData> number of data to be written
|
---|
| 160 |
|
---|
| 161 | */
|
---|
[839] | 162 | void putImageToFits( int nbData, double* map) const;
|
---|
[903] | 163 |
|
---|
| 164 | /*! same as previous method with float data */
|
---|
[839] | 165 | void putImageToFits(int nbData, float* map ) const;
|
---|
[903] | 166 |
|
---|
| 167 | /*! same as previous method with int data */
|
---|
[839] | 168 | void putImageToFits(int nbData, int* map) const;
|
---|
[903] | 169 |
|
---|
| 170 | /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
|
---|
| 171 | \param <nentries> number of data to be written
|
---|
| 172 |
|
---|
| 173 | */
|
---|
[839] | 174 | void putColToFits(int nocol, int nentries, double* donnees) const;
|
---|
[903] | 175 |
|
---|
| 176 | /*! same as previous method with float data */
|
---|
[839] | 177 | void putColToFits(int nocol, int nentries, float* donnees) const;
|
---|
[903] | 178 |
|
---|
| 179 | /*! same as previous method with int data */
|
---|
[839] | 180 | void putColToFits(int nocol, int nentries, int* donnees) const;
|
---|
[903] | 181 |
|
---|
| 182 | /*! same as previous method with char* data */
|
---|
[839] | 183 | void putColToFits(int nocol, int nentries, char** donnees) const;
|
---|
[903] | 184 |
|
---|
| 185 | /*! create an IMAGE header on FITS file.
|
---|
| 186 | \param <type> type of data (see method ColTypeFromFits)
|
---|
| 187 | \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
|
---|
| 188 | \param <naxisn> array containind sizes of the different dimensions
|
---|
| 189 | */
|
---|
[861] | 190 | void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) const;
|
---|
[903] | 191 |
|
---|
| 192 | /*! create an BINTABLE header on FITS file.
|
---|
| 193 | \param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits)
|
---|
| 194 | \param <Noms> array of the names of columns
|
---|
| 195 | \param <nentries> number of data of each column
|
---|
| 196 | \param <tfields> number of columns
|
---|
| 197 | \param <dvl> a SOPHYA DVList containing keywords to be appended
|
---|
| 198 | \param <extname> keyword EXTNAME for FITS file
|
---|
| 199 | \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
|
---|
| 200 | */
|
---|
[839] | 201 | void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const;
|
---|
| 202 |
|
---|
| 203 | void readheader();
|
---|
[903] | 204 | static void printerror(int&) ;
|
---|
| 205 | static void printerror(int&,char* texte) ;
|
---|
[839] | 206 | protected:
|
---|
| 207 | virtual void ReadFromFits(const FitsFile& ff)=0;
|
---|
| 208 | virtual void WriteToFits(const FitsFile& ff)=0;
|
---|
| 209 | private:
|
---|
| 210 |
|
---|
[903] | 211 | static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
|
---|
| 212 | static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
| 213 | vector<int>& repeat,
|
---|
| 214 | vector<string>& noms,
|
---|
| 215 | vector<char>& types,
|
---|
| 216 | vector<int>& taille_des_chaines);
|
---|
| 217 | static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl);
|
---|
[839] | 218 | void writeSignatureOnFits() const;
|
---|
| 219 |
|
---|
[903] | 220 | //! pointer to the FITS file, defined in fitsio.h
|
---|
| 221 | fitsfile *fptr_;
|
---|
[839] | 222 |
|
---|
[903] | 223 | //! image or bintable ?
|
---|
| 224 | int hdutype_;
|
---|
[839] | 225 |
|
---|
[903] | 226 | //! index of header to be read/written
|
---|
| 227 | int hdunum_;
|
---|
[839] | 228 |
|
---|
[903] | 229 |
|
---|
| 230 | //! fits-Image parameter
|
---|
[839] | 231 | int bitpix_;
|
---|
[903] | 232 |
|
---|
| 233 | //! fits-Image parameter
|
---|
[839] | 234 | int naxis_;
|
---|
[903] | 235 |
|
---|
| 236 | //! fits-Image parameters : sizes of dimensions
|
---|
[861] | 237 | vector<int> naxisn_;
|
---|
[903] | 238 |
|
---|
| 239 | //! fits-Image parameter: number of data
|
---|
[839] | 240 | int nbData_;
|
---|
| 241 |
|
---|
[903] | 242 | //! Bintable parameter
|
---|
[839] | 243 | int nrows_;
|
---|
[903] | 244 |
|
---|
| 245 | //! Bintable parameter
|
---|
[839] | 246 | vector<int> repeat_;
|
---|
| 247 |
|
---|
[903] | 248 | //! Bintable parameter
|
---|
[839] | 249 | int nbcols_;
|
---|
| 250 |
|
---|
[903] | 251 | //! Bintable parameter: column names
|
---|
| 252 | vector<string> noms_;
|
---|
| 253 |
|
---|
| 254 | //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*)
|
---|
| 255 | vector<char> types_;
|
---|
| 256 |
|
---|
| 257 | //! Bintable parameters: length of the char* variables
|
---|
| 258 | vector<int> taille_des_chaines_;
|
---|
[839] | 259 |
|
---|
[903] | 260 | //! DVList for transferring keywords
|
---|
[839] | 261 | DVList dvl_;
|
---|
| 262 | };
|
---|
[875] | 263 |
|
---|
| 264 |
|
---|
| 265 | } // Fin du namespace
|
---|
| 266 |
|
---|
| 267 |
|
---|
[839] | 268 | #endif
|
---|