[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);
|
---|
[1045] | 67 | FitsFile* ReadFInit(char flnm[],int hdunum=0);
|
---|
| 68 | void ReadFFromFits();
|
---|
[903] | 69 |
|
---|
| 70 | /*!
|
---|
| 71 | this method is called from inherited objects :
|
---|
| 72 |
|
---|
| 73 | opens a file 'flnm'
|
---|
| 74 |
|
---|
| 75 | gets parameters in header
|
---|
| 76 |
|
---|
| 77 | calls the method 'ReadFromFits' from the inherited delegated object
|
---|
| 78 |
|
---|
| 79 | */
|
---|
[971] | 80 | void WriteF(char flnm[], bool OldFile=false);
|
---|
[903] | 81 |
|
---|
| 82 |
|
---|
| 83 | /*!
|
---|
| 84 | fill the array 'map' with double data from the current extension on FITS file.
|
---|
| 85 | If the extension is BINTABLE, the first column is provided.
|
---|
| 86 |
|
---|
| 87 | \param <nentries> number of data to be read
|
---|
| 88 | */
|
---|
[839] | 89 | void GetSingleColumn(double* map, int nentries) const;
|
---|
[903] | 90 |
|
---|
| 91 | /*! same as above with float data */
|
---|
[839] | 92 | void GetSingleColumn(float* map, int nentries) const;
|
---|
[903] | 93 |
|
---|
| 94 | /*! same as above with int data */
|
---|
[839] | 95 | void GetSingleColumn(int* map, int nentries) const;
|
---|
[903] | 96 |
|
---|
| 97 | /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
|
---|
| 98 | */
|
---|
[861] | 99 | inline int nbDimOfImage() const {return naxis_;}
|
---|
[903] | 100 |
|
---|
| 101 | /*!
|
---|
| 102 | total number of data in the current IMAGE extension
|
---|
| 103 | */
|
---|
[839] | 104 | inline int nbOfImageData() const { return nbData_; }
|
---|
[903] | 105 |
|
---|
| 106 | /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
|
---|
| 107 | */
|
---|
[861] | 108 | inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
|
---|
[903] | 109 |
|
---|
| 110 | /*! return number of columns (return 1 if IMAGE) */
|
---|
[839] | 111 | int NbColsFromFits() const;
|
---|
[903] | 112 |
|
---|
| 113 | /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
|
---|
| 114 |
|
---|
| 115 | D : double
|
---|
| 116 |
|
---|
| 117 | E : float
|
---|
| 118 |
|
---|
| 119 | I : integer
|
---|
| 120 |
|
---|
| 121 | S : character string
|
---|
| 122 |
|
---|
| 123 | */
|
---|
[839] | 124 | char ColTypeFromFits(int nocol) const;
|
---|
[903] | 125 |
|
---|
| 126 | /*! number of data in the current IMAGE extension on FITS file, or number
|
---|
| 127 | of data of column number 'nocol' of the current BINTABLE extension
|
---|
| 128 | */
|
---|
[839] | 129 | int NentriesFromFits(int nocol) const;
|
---|
[903] | 130 |
|
---|
| 131 | /*! name of the column number 'nocol' of the current BINTABLE extension
|
---|
| 132 | */
|
---|
[839] | 133 | string ColNameFromFits(int nocol) const;
|
---|
[903] | 134 |
|
---|
| 135 |
|
---|
| 136 | /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
|
---|
| 137 | */
|
---|
[839] | 138 | int ColStringLengthFromFits(int nocol) const;
|
---|
[903] | 139 |
|
---|
| 140 | /*! return a reference on a DVList containing the keywords from FITS file
|
---|
| 141 | */
|
---|
[839] | 142 | inline const DVList& DVListFromFits() const { return dvl_;}
|
---|
[903] | 143 |
|
---|
| 144 |
|
---|
| 145 | /*!
|
---|
| 146 | fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
|
---|
| 147 |
|
---|
| 148 | \param <nentries> number of data to be read
|
---|
| 149 | */
|
---|
[839] | 150 | void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 151 |
|
---|
| 152 | /*! same as previous method with float data */
|
---|
[839] | 153 | void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 154 | /*! same as previous method with int data */
|
---|
[839] | 155 | void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const;
|
---|
[903] | 156 | /*! same as previous method with char* data */
|
---|
[839] | 157 | void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
|
---|
| 158 | // Write elements into the FITS data array
|
---|
[903] | 159 |
|
---|
[1045] | 160 | /*!
|
---|
| 161 | get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 162 | */
|
---|
| 163 | void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
|
---|
| 164 | ** cdata) const;
|
---|
| 165 | /*!
|
---|
| 166 | get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 167 | */
|
---|
| 168 | void GetBinTabLine(int NoLine, float* fdata) const;
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 |
|
---|
[903] | 173 | /*! write double data from array 'map'on an IMAGE extension
|
---|
| 174 | \param <nbData> number of data to be written
|
---|
| 175 |
|
---|
| 176 | */
|
---|
[839] | 177 | void putImageToFits( int nbData, double* map) const;
|
---|
[903] | 178 |
|
---|
| 179 | /*! same as previous method with float data */
|
---|
[839] | 180 | void putImageToFits(int nbData, float* map ) const;
|
---|
[903] | 181 |
|
---|
| 182 | /*! same as previous method with int data */
|
---|
[839] | 183 | void putImageToFits(int nbData, int* map) const;
|
---|
[903] | 184 |
|
---|
| 185 | /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
|
---|
| 186 | \param <nentries> number of data to be written
|
---|
| 187 |
|
---|
| 188 | */
|
---|
[839] | 189 | void putColToFits(int nocol, int nentries, double* donnees) const;
|
---|
[903] | 190 |
|
---|
| 191 | /*! same as previous method with float data */
|
---|
[839] | 192 | void putColToFits(int nocol, int nentries, float* donnees) const;
|
---|
[903] | 193 |
|
---|
| 194 | /*! same as previous method with int data */
|
---|
[839] | 195 | void putColToFits(int nocol, int nentries, int* donnees) const;
|
---|
[903] | 196 |
|
---|
| 197 | /*! same as previous method with char* data */
|
---|
[839] | 198 | void putColToFits(int nocol, int nentries, char** donnees) const;
|
---|
[903] | 199 |
|
---|
| 200 | /*! create an IMAGE header on FITS file.
|
---|
| 201 | \param <type> type of data (see method ColTypeFromFits)
|
---|
| 202 | \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
|
---|
| 203 | \param <naxisn> array containind sizes of the different dimensions
|
---|
| 204 | */
|
---|
[971] | 205 | void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
|
---|
[903] | 206 |
|
---|
| 207 | /*! create an BINTABLE header on FITS file.
|
---|
| 208 | \param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits)
|
---|
| 209 | \param <Noms> array of the names of columns
|
---|
| 210 | \param <nentries> number of data of each column
|
---|
| 211 | \param <tfields> number of columns
|
---|
| 212 | \param <dvl> a SOPHYA DVList containing keywords to be appended
|
---|
| 213 | \param <extname> keyword EXTNAME for FITS file
|
---|
| 214 | \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
|
---|
| 215 | */
|
---|
[971] | 216 | void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ;
|
---|
[839] | 217 |
|
---|
[971] | 218 | void moveToFollowingHeader();
|
---|
[839] | 219 | void readheader();
|
---|
[903] | 220 | static void printerror(int&) ;
|
---|
| 221 | static void printerror(int&,char* texte) ;
|
---|
[839] | 222 | protected:
|
---|
[971] | 223 | virtual void ReadFromFits(FitsFile& ff)=0;
|
---|
| 224 | virtual void WriteToFits(FitsFile& ff)=0;
|
---|
[839] | 225 | private:
|
---|
| 226 |
|
---|
[1045] | 227 | void InitNull();
|
---|
| 228 |
|
---|
[903] | 229 | static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
|
---|
| 230 | static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
| 231 | vector<int>& repeat,
|
---|
| 232 | vector<string>& noms,
|
---|
| 233 | vector<char>& types,
|
---|
| 234 | vector<int>& taille_des_chaines);
|
---|
[971] | 235 | static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
|
---|
[839] | 236 | void writeSignatureOnFits() const;
|
---|
| 237 |
|
---|
[903] | 238 | //! pointer to the FITS file, defined in fitsio.h
|
---|
| 239 | fitsfile *fptr_;
|
---|
[839] | 240 |
|
---|
[903] | 241 | //! image or bintable ?
|
---|
| 242 | int hdutype_;
|
---|
[839] | 243 |
|
---|
[903] | 244 | //! index of header to be read/written
|
---|
| 245 | int hdunum_;
|
---|
[839] | 246 |
|
---|
[903] | 247 |
|
---|
| 248 | //! fits-Image parameter
|
---|
[839] | 249 | int bitpix_;
|
---|
[903] | 250 |
|
---|
| 251 | //! fits-Image parameter
|
---|
[839] | 252 | int naxis_;
|
---|
[903] | 253 |
|
---|
| 254 | //! fits-Image parameters : sizes of dimensions
|
---|
[861] | 255 | vector<int> naxisn_;
|
---|
[903] | 256 |
|
---|
| 257 | //! fits-Image parameter: number of data
|
---|
[839] | 258 | int nbData_;
|
---|
| 259 |
|
---|
[903] | 260 | //! Bintable parameter
|
---|
[839] | 261 | int nrows_;
|
---|
[903] | 262 |
|
---|
| 263 | //! Bintable parameter
|
---|
[839] | 264 | vector<int> repeat_;
|
---|
| 265 |
|
---|
[903] | 266 | //! Bintable parameter
|
---|
[839] | 267 | int nbcols_;
|
---|
| 268 |
|
---|
[903] | 269 | //! Bintable parameter: column names
|
---|
| 270 | vector<string> noms_;
|
---|
| 271 |
|
---|
| 272 | //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*)
|
---|
| 273 | vector<char> types_;
|
---|
| 274 |
|
---|
| 275 | //! Bintable parameters: length of the char* variables
|
---|
| 276 | vector<int> taille_des_chaines_;
|
---|
[839] | 277 |
|
---|
[903] | 278 | //! DVList for transferring keywords
|
---|
[839] | 279 | DVList dvl_;
|
---|
[1045] | 280 |
|
---|
[839] | 281 | };
|
---|
[875] | 282 |
|
---|
| 283 |
|
---|
| 284 | } // Fin du namespace
|
---|
| 285 |
|
---|
| 286 |
|
---|
[839] | 287 | #endif
|
---|