Ignore:
Timestamp:
Aug 24, 2000, 12:18:02 PM (25 years ago)
Author:
ansari
Message:

structuration a la ppersist+ convention sur hdu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1047 r1136  
    1212namespace SOPHYA {
    1313
     14 class FitsFile;
     15 class FitsInFile;
     16 class FitsOutFile;
     17
     18
     19
    1420//
    15 //! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
     21//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
    1622
    1723/*!
    18 
     24The class structure is analogous to Sophya-PPersist system :
    1925Each 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 :
     26 (inheriting from FitsFileHandler), to which input/output operations with FITS
     27 files are delegated (through a class Hierarchy : FitsFile (virtual),
     28 FitsInFile, FitsOutFile) . A typical example of use is the following :
    2229
    2330\verbatim
     
    3946
    4047*/
     48
     49class FitsIOHandler {
     50
     51
     52  public:
     53
     54virtual ~FitsIOHandler() {}
     55/*!
     56this method is called from inherited objects :
     57
     58opens a file 'flnm'
     59
     60gets parameters in header (hdunum)
     61
     62calls the method 'ReadFromFits' from the inherited  object
     63
     64
     65*/
     66  void   Read(char flnm[],int hdunum= 2);
     67/*!
     68this method is called from inherited objects :
     69
     70for writing a new object in a new fits-extension, at the end of
     71
     72the existing file (flnm), if OldFile=true.
     73
     74If OldFile=false, an exception occurs
     75 
     76By convention, primary header does not contain fits-image data : i.e.
     77all data are fits-extensions. The first relevant header will have hdunum=2.
     78For switching off this convention use the method :
     79
     80firstImageOnPrimaryHeader() (see below)
     81
     82In that case do not forget to precise hdunum=1 when reading data on primary header.
     83
     84calls the method 'WriteToFits' from the inherited  object
     85
     86*/
     87  void   Write(char flnm[], bool OldFile=false) ;
     88
     89  /*!
     90Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. With default value for hdunum, one reads the next extension, with respect to the current position.
     91   */
     92  void   Read(FitsInFile& ifts, int hdunum=0);
     93  void   Write(FitsOutFile& ofts) ;
     94
     95
     96  protected: 
     97  virtual void    ReadFromFits(FitsInFile& is)=0;           
     98  virtual void    WriteToFits(FitsOutFile& os) =0;           
     99  friend class FitsInFile;
     100  friend class FitsOutFile;
     101
     102  };
     103
     104
     105
    41106class FitsFile
    42107{
     
    44109public:
    45110
    46   FitsFile();
     111  FitsFile() { InitNull();};
    47112  virtual ~FitsFile();
     113
     114  static string getErrStatus(int status);
     115
     116
     117
     118
     119inline  int statusF() const { return fits_status_;}
     120 
     121
     122protected:
     123
     124   void ResetStatus(int& status) ;
     125   static  void printerror(int&) ;
     126   static  void printerror(int&,char* texte) ;
     127   inline void InitNull() { cout << " init fitsfile " << endl; fptr_= NULL; hdutype_= 0; hdunum_ = 1;
     128   fits_status_ = 0;}
     129
     130  //! pointer to the FITS file, defined in fitsio.h
     131  fitsfile *fptr_;
     132 
     133  //!  image or bintable ?
     134  int hdutype_;
     135
     136//! index of header to be read/written
     137  int hdunum_; 
     138
     139  //! last status returned by fitsio library. updated only by several methods
     140  int fits_status_;
     141
     142   
     143};
     144
     145
     146 class FitsInFile : public  FitsFile {
     147
     148 public:
     149   FitsInFile();
     150   //   FitsInFile(char flnm[], int hdunum=0);
     151   FitsInFile(char flnm[]);
     152   ~FitsInFile() {  cout << " destructeur FitsInFile " << endl; };
     153
     154
     155//////////////////////////////////////////////////////////
     156//     methods with general purpose
     157///////////////////////////////////////
     158
     159
     160
    48161  static int NbBlocks(char flnm[]);
    49162  static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
    50163
    51   protected:
     164
     165
     166  //  void ReadFInit(char flnm[],int hdunum=0);
     167  void ReadFInit(int hdunum);
    52168 
    53 /*!
    54 this method is called from inherited objects :
    55 
    56 moves to header 'hdunum' on file 'flnm'
    57 
    58 gets parameters in header
    59 
    60 calls the method 'ReadFromFits' from the inherited  object
    61 
    62 */
    63   void   ReadF(char flnm[],int hdunum= 0);
    64   //  FitsFile* ReadFInit(char flnm[],int hdunum=0);
    65   void ReadFInit(char flnm[],int hdunum=0);
    66  
    67 /*!
    68 this method is called from inherited objects :
    69 
    70 opens a file 'flnm'
    71 
    72 gets parameters in header
    73 
    74 calls the method 'ReadFromFits' from the inherited  object
    75 
    76 */
    77   void    WriteF(char flnm[], bool OldFile=false);
    78  //    virtual void    ReadFromFits(FitsFile& ff)=0;           
    79 
    80 
    81 
    82   virtual void    ReadFromFits()=0;           
    83   virtual void    WriteToFits()=0;           
    84 
    85   static string getErrStatus(int status);
    86 
    87 
    88   //////////////////////////////////////////////////////////
    89   ///////   methods for managing extensions ////////////////
    90   //////////////////////////////////////////////////////////
    91 
    92 //////////////////////////////////////////////////////////
    93     //     methods with general purpose
    94     ///////////////////////////////////////
    95 
    96169  /*! return a reference on a DVList containing the keywords from FITS file
    97170   */
    98   inline const DVList& DVListFromFits() const { return dvl_;}
    99 
    100   void moveToFollowingHeader();
    101   int statusF() const;
     171inline const DVList& DVListFromFits() const { return dvl_;}
     172
     173void moveToFollowingHeader();
     174
     175
     176       //////////////////////////////////////////////////////////
     177       ///////   methods for managing extensions ////////////////
     178       //////////////////////////////////////////////////////////
     179
    102180
    103181
    104182/////////////////////////////////////////////////////////////
    105   //       methods for managing FITS IMAGE extension
    106   ///////////////////////////////////////////////////
    107 
    108 
    109   //read
    110   //----
     183//       methods for managing FITS IMAGE extension
     184///////////////////////////////////////////////////
     185
    111186
    112187/*! return true if the current header  corresponds to a FITS image extension */
    113188inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
     189
     190
    114191
    115192  /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
     
    125202
    126203
    127 //write
    128 //-----
    129 
    130 
    131   /*! create an IMAGE header on FITS file.
    132 \param <type> type of data (see method ColTypeFromFits)
    133 \param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
    134 \param <naxisn>  array containind sizes of the different dimensions
    135   */
    136   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
    137 
    138   /*! write double data from array 'map'on an IMAGE extension
    139 \param <nbData>  number of data to be written
    140 
    141    */
    142   void putImageToFits( int nbData, double* map) const;
    143 
    144   /*! same as previous method with float data */
    145   void putImageToFits(int nbData, float* map ) const;
    146 
    147   /*! same as previous method with int data */
    148   void putImageToFits(int nbData, int* map) const;
    149 
    150 
    151204
    152205//////////////////////////////////////////////////////////////////////////
    153   //       methods for managing FITS BINARY TABLE or ASCII TABLE extension
    154   ////////////////////////////////////////////////////////////////////////
    155 
    156 
    157 
    158 // read
    159 //-----
     206//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
     207////////////////////////////////////////////////////////////////////////
     208
     209
     210
    160211
    161212/*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
    162213inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
    163  /*! return number of columns (return 1 if IMAGE) */
    164   int     NbColsFromFits() const;
    165   /*! number of data in the current IMAGE extension on FITS file, or number
    166  of data of column number 'nocol' of the current BINTABLE extension
    167   */
    168   int     NentriesFromFits(int nocol) const;
     214
     215
     216static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
     217                                  vector<int>& repeat,
     218                                  vector<string>& noms,
     219                                  vector<char>& types,   
     220                                  vector<int>&  taille_des_chaines);
     221
     222
     223
    169224  /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
    170225
     
    200255  void GetBinTabLine(int NoLine, float* fdata) ;
    201256
    202 
    203 
    204 
    205 
    206   /*!
     257/*!
    207258fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
    208259
     
    219270  // Write elements into the FITS data array
    220271
    221 
    222 
    223   //write
    224   //-----
     272/////////////////////////////////////////////////////////////
     273//       methods for managing any type of FITS extension
     274////////////////////////////////////////////////////////
     275
     276 /*! return number of columns (return 1 if IMAGE) */
     277  int     NbColsFromFits() const;
     278  /*! number of data in the current IMAGE extension on FITS file, or number
     279 of data of column number 'nocol' of the current BINTABLE extension
     280  */
     281  int     NentriesFromFits(int nocol) const;
     282
     283
     284/*!
     285fill the array 'map' with double data from the current extension on FITS file.
     286If the extension is BINTABLE, the first column is provided.
     287
     288\param <nentries>  number of data to be read
     289  */
     290  void    GetSingleColumn(double* map, int nentries) const;
     291
     292  /*! same as above with float data */
     293  void    GetSingleColumn(float*  map, int nentries) const;
     294
     295  /*! same as above with int data */
     296  void    GetSingleColumn(int* map, int nentries) const;
     297
     298  private :
     299
     300void InitNull();
     301static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
     302static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
     303
     304
     305 
     306
     307  //! fits-Image parameter
     308  int bitpix_;
     309
     310  //! fits-Image parameter
     311  int naxis_;
     312
     313  //! fits-Image parameters : sizes of dimensions
     314  vector<int> naxisn_;
     315
     316  //! fits-Image parameter: number of data
     317  int nbData_;
     318
     319  //! Bintable parameter
     320  int nrows_;
     321
     322  //! Bintable parameter
     323  vector<int> repeat_;
     324
     325  //! Bintable parameter
     326  int nbcols_;
     327
     328  //! Bintable parameter: column names
     329  vector<string> noms_;
     330
     331  //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
     332  vector<char> types_;   
     333
     334  //! Bintable parameters:   length of the char* variables                 
     335  vector<int>  taille_des_chaines_;
     336
     337  //! DVList for transferring keywords
     338  DVList dvl_;
     339
     340
     341 };
     342
     343
     344 class FitsOutFile : public  FitsFile {
     345
     346 public:
     347   FitsOutFile();
     348   FitsOutFile(char flnm[], bool OldFile=false);
     349   ~FitsOutFile() {  cout << " destructeur FitsOutFile " << endl;};
     350   inline void InitNull() {imageOnPrimary_=false;}
     351
     352       //////////////////////////////////////////////////////////
     353       ///////   methods for managing extensions ////////////////
     354       //////////////////////////////////////////////////////////
     355
     356
     357
     358/////////////////////////////////////////////////////////////
     359//       methods for managing FITS IMAGE extension
     360///////////////////////////////////////////////////
     361
     362
     363   inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
     364
     365  /*! create an IMAGE header on FITS file.
     366\param <type> type of data (see method ColTypeFromFits)
     367\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
     368\param <naxisn>  array containind sizes of the different dimensions
     369  */
     370  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
     371
     372  /*! write double data from array 'map'on an IMAGE extension
     373\param <nbData>  number of data to be written
     374
     375   */
     376  void putImageToFits( int nbData, double* map) const;
     377
     378  /*! same as previous method with float data */
     379  void putImageToFits(int nbData, float* map ) const;
     380
     381  /*! same as previous method with int data */
     382  void putImageToFits(int nbData, int* map) const;
     383
     384
     385
     386//////////////////////////////////////////////////////////////////////////
     387//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
     388////////////////////////////////////////////////////////////////////////
     389
     390
    225391
    226392  /*! create an BINTABLE header on FITS file.
     
    250416  void putColToFits(int nocol, int nentries, char** donnees) const;
    251417
    252 
    253 /////////////////////////////////////////////////////////////
    254   //       methods for managing any type of FITS extension
    255   ////////////////////////////////////////////////////////
    256 
    257 
    258   /*!
    259 fill the array 'map' with double data from the current extension on FITS file.
    260 If the extension is BINTABLE, the first column is provided.
    261 
    262 \param <nentries>  number of data to be read
    263   */
    264   void    GetSingleColumn(double* map, int nentries) const;
    265 
    266   /*! same as above with float data */
    267   void    GetSingleColumn(float*  map, int nentries) const;
    268 
    269   /*! same as above with int data */
    270   void    GetSingleColumn(int* map, int nentries) const;
    271 
    272 
    273 
    274 private:
    275 
    276    void InitNull();
    277    void ResetStatus(int& status) ;
    278    static  void printerror(int&) ;
    279    static  void printerror(int&,char* texte) ;
    280 
    281 static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
    282 static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
    283                                   vector<int>& repeat,
    284                                   vector<string>& noms,
    285                                   vector<char>& types,   
    286                                   vector<int>&  taille_des_chaines);
    287 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
     418  private :
     419
    288420  void writeSignatureOnFits() const;
    289421
    290   //! pointer to the FITS file, defined in fitsio.h
    291   fitsfile *fptr_;
    292  
    293   //!  image or bintable ?
    294   int hdutype_;
    295 
    296 //! index of header to be read/written
    297   int hdunum_; 
    298 
    299 
    300   //! fits-Image parameter
    301   int bitpix_;
    302 
    303   //! fits-Image parameter
    304   int naxis_;
    305 
    306   //! fits-Image parameters : sizes of dimensions
    307   vector<int> naxisn_;
    308 
    309   //! fits-Image parameter: number of data
    310   int nbData_;
    311 
    312   //! Bintable parameter
    313   int nrows_;
    314 
    315   //! Bintable parameter
    316   vector<int> repeat_;
    317 
    318   //! Bintable parameter
    319   int nbcols_;
    320 
    321   //! Bintable parameter: column names
    322   vector<string> noms_;
    323  
    324   //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
    325   vector<char> types_;   
    326    
    327   //! Bintable parameters:   length of the char* variables                 
    328   vector<int>  taille_des_chaines_;
    329 
    330   //! DVList for transferring keywords
    331   DVList dvl_;
    332 
    333 
    334 
    335   //! last status returned by fitsio library. updated only by several methods
    336   int fits_status_;
    337 };
     422
     423  bool imageOnPrimary_;
     424
     425 };
     426
    338427
    339428
Note: See TracChangeset for help on using the changeset viewer.