Changeset 1218 in Sophya for trunk/SophyaExt


Ignore:
Timestamp:
Oct 3, 2000, 2:14:14 PM (25 years ago)
Author:
ansari
Message:

doc dans .cc

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

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

    r1209 r1218  
    88
    99
     10void BnTblLine::setFormat(int dc, int fc, int ic, int cc, vector<string> names)
     11   {
     12    int nbcols = dc + fc + ic + cc;
     13    int maxName = names.size();
     14    if (nbcols != maxName)
     15      {
     16        cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
     17        maxName = nbcols < maxName ? nbcols : maxName;
     18      }
     19    ColName_ = vector<string>(nbcols);
     20     for (int k=0; k < maxName; k++) ColName_[k] = names[k];
     21    if (dc >0) ddata_ = vector<double>(dc);
     22    if (fc >0) fdata_ = vector<float>(fc);
     23    if (ic >0) idata_ = vector<int>(fc);
     24    if (cc >0) cdata_ = vector<string>(fc);
     25   }
     26
     27bool BnTblLine::sameFormat(const BnTblLine& btl) const
     28   {
     29     if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true;
     30     else return false;
     31   }
     32
     33void BnTblLine::Print()
     34   {
     35     int k;
     36     cout << " ********* ligne ************* " << endl;
     37     cout << " *** noms de variables  " << endl;
     38     for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
     39     cout << endl;
     40     cout << " *** variables doubles  " << endl;
     41     for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
     42     cout << endl;
     43     cout << " *** variables float  " << endl;
     44     for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
     45     cout << endl;
     46     cout << " *** variables int  " << endl;
     47     for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
     48     cout << endl;
     49     cout << " *** variables string  " << endl;
     50     for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
     51     cout << endl;
     52     cout << " ***************************** " << endl;
     53   }
     54
     55
     56
     57/*!
     58  \class SOPHYA::FitsIOHandler
     59The class structure is analogous to Sophya-PPersist system :
     60Each SOPHYA object XXX is associated with a object of class FITS_XXX
     61 (inheriting from FitsFileHandler), to which input/output operations with FITS
     62 files are delegated (through a class Hierarchy : FitsFile (virtual),
     63 FitsInFile, FitsOutFile) . A typical example of use is the following :
     64
     65\verbatim
     66  int m=... ;
     67  SphereHEALPix<r_8> sphere1(m);           // definition of the SOPHYA object
     68  .... fill the sphere ....
     69
     70  FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
     71                                           // delegated object
     72  fits_sph.Write("myfile.fits");           // writing on FITS file
     73
     74   FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
     75                                           // load a delegated object
     76                                           // from FITS file
     77   SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
     78                                           // casting the delegated object
     79                                           // into a SOPHYA object
     80\endverbatim
     81 
     82
     83*/
     84
     85/*! \fn void  SOPHYA::FitsIOHandler::Read(char flnm[],int hdunum)
     86
     87this method is called from inherited objects :
     88
     89opens a file 'flnm'
     90
     91gets parameters in extension-header (hdunum)
     92
     93calls the method 'ReadFromFits' from the inherited  object
     94*/
    1095void   FitsIOHandler::Read(char flnm[],int hdunum)
    1196{
     
    1398  Read(ifts, hdunum);
    1499}
     100
     101  /*! \fn void SOPHYA::FitsIOHandler::Read(FitsInFile& is, int hdunum)
     102Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. If hdunum is not addressed, , one reads the next extension, with respect to the current position.
     103   */
    15104void FitsIOHandler::Read(FitsInFile& is, int hdunum)
    16105{
     
    21110
    22111
     112/*! \fn void SOPHYA::FitsIOHandler::Write(char flnm[])
     113this method is called from inherited objects.
     114
     115for writing a new object in a new fits-extension :
     116
     117\warning By convention, primary header does not contain fits-image data : i.e.
     118all data are fits-extensions. The first relevant header will have hdunum=2.
     119For switching off this convention use the method :
     120
     121firstImageOnPrimaryHeader() (see below)
     122
     123In that case do not forget to precise hdunum=1 when reading data on primary header.
     124
     125calls the method 'WriteToFits' from the inherited  object
     126
     127*/
    23128void FitsIOHandler::Write(char flnm[])
    24129
     
    33138}
    34139
     140
     141/*!
     142  \class SOPHYA::FitsIOHandler
     143Class (virtual) for managing FITS format files
     144*/
    35145
    36146
     
    87197}
    88198
     199/*!
     200  \class SOPHYA::FitsInFile
     201
     202class for saving  SOPHYA objects on FITS Format Files (uses cfitsio lib)
     203*/
     204
    89205FitsInFile::FitsInFile()
    90206{
    91207  InitNull();
    92208}
    93 //FitsInFile::FitsInFile(char flnm[], int hdunum)
     209
    94210FitsInFile::FitsInFile(char flnm[])
    95211{
     
    118234}
    119235
     236//////////////////////////////////////////////////////////
     237//     methods with general purpose
     238/////////////////////////////////////////////////////////
    120239
    121240int FitsInFile::NbBlocks(char flnm[])
     
    200319}
    201320
     321
     322void FitsInFile::ReadFInit(int hdunum)
     323{
     324   InitNull();
     325  // int status = 0;
     326 
     327  //  fits_open_file(&fptr_,flnm,READONLY,&status);
     328  //  if( status ) printerror( status );
     329
     330  int status = 0;
     331
     332  if (hdunum <= 1)
     333    {
     334      hdunum_ = 1;
     335      // presence of image ?
     336      int naxis= 0;
     337      fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
     338      if( status ) printerror( status );
     339      if (naxis > 0 )       // there is an image
     340        {
     341          hdutype_ = IMAGE_HDU;
     342          GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
     343          nbData_ =  1;
     344          int k;
     345          for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
     346          KeywordsIntoDVList(fptr_, dvl_,hdunum_);
     347        }
     348      else
     349        {
     350          throw PException(" first header : no image, probably error in hdunum");
     351        }
     352  //
     353    }
     354  else
     355    {
     356      hdunum_ = hdunum-1;
     357      int hdutype;
     358      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
     359      if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
     360      moveToFollowingHeader();
     361    }
     362}
     363
     364
    202365void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
    203366{
     
    230393
    231394
    232 void FitsInFile::ReadFInit(int hdunum)
    233 {
    234    InitNull();
    235   // int status = 0;
    236  
    237   //  fits_open_file(&fptr_,flnm,READONLY,&status);
    238   //  if( status ) printerror( status );
    239 
    240   int status = 0;
    241 
    242   if (hdunum <= 1)
    243     {
    244       hdunum_ = 1;
    245       // presence of image ?
    246       int naxis= 0;
    247       fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
    248       if( status ) printerror( status );
    249       if (naxis > 0 )       // there is an image
    250         {
    251           hdutype_ = IMAGE_HDU;
    252           GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
    253           nbData_ =  1;
    254           int k;
    255           for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
    256           KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    257         }
    258       else
    259         {
    260           throw PException(" first header : no image, probably error in hdunum");
    261         }
    262   //
    263     }
    264   else
    265     {
    266       hdunum_ = hdunum-1;
    267       int hdutype;
    268       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    269       if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
    270       moveToFollowingHeader();
    271     }
    272 }
    273 
     395
     396
     397  /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const
     398
     399   \return the keywords of primary header in a DVList
     400
     401*/
    274402DVList  FitsInFile::DVListFromPrimaryHeader() const
    275403   {
     
    308436
    309437
     438
     439
     440
     441/*! \fn int  SOPHYA::FitsInFile::NbColsFromFits() const
     442\return number of columns (return 1 if IMAGE)
     443*/
    310444int  FitsInFile::NbColsFromFits() const
    311445{
     
    320454}
    321455
     456/*! \fn  int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const
     457\return number of data in the current IMAGE extension on FITS file, or number
     458 of data of column number 'nocol' of the current BINTABLE extension
     459*/
    322460int FitsInFile::NentriesFromFits(int nocol) const
    323461{
     
    334472}
    335473
     474/*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const
     475
     476return a character denoting data type of column number 'nocol' in a BINTABLE :
     477
     478D : double
     479
     480E : float
     481
     482I : integer
     483   
     484S : character string
     485
     486  */
     487
    336488char FitsInFile::ColTypeFromFits(int nocol) const
    337489{
     
    342494  return types_[nocol];
    343495}
     496
     497
     498/*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const
     499
     500\return name of the column number 'nocol' of the current BINTABLE extension
     501   */
     502
    344503string FitsInFile::ColNameFromFits(int nocol) const
    345504{
     
    350509  return noms_[nocol];
    351510}
     511
     512/*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const
     513
     514 \return number of characters of each data  for the column number 'nocol' (if char* typed) of the current BINTABLE extension
     515*/
    352516
    353517int FitsInFile::ColStringLengthFromFits(int nocol) const
     
    365529  return  taille_des_chaines_[index];
    366530}
     531
     532
     533
     534/*! \fn void  SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
     535
     536Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     537  */
     538
    367539void  FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
    368540{
     
    405577}
    406578
     579/*! \fn void   SOPHYA::FitsInFile::GetBinTabLine(long NoLine,  BnTblLine& ligne)
     580Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     581*/
    407582void   FitsInFile::GetBinTabLine(long NoLine,  BnTblLine& ligne)
    408583{
     
    447622}
    448623
     624/*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
     625
     626Get the NoLine-th float 'line'  from the current BINTABLE extension on FITS file,
     627*/
    449628void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
    450629{
     
    466645
    467646
     647/*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
     648
     649fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
     650
     651\param <nentries>  number of data to be read
     652*/
    468653void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
    469654    {
     
    499684    }
    500685
     686/*! \fn  void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
     687
     688 same as previous method with float data
     689*/
    501690void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
    502691    {
     
    531720    }
    532721
     722/*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     723
     724 same as previous method with int data
     725*/
     726
    533727void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
    534728    {
     
    561755    }
    562756
     757/*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
     758
     759 same as previous method with char* data
     760*/
     761
    563762void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
    564763    {
     
    587786    }
    588787
     788/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const
     789fill the array 'map' with double data from the current extension on FITS file.
     790If the extension is BINTABLE, the first column is provided.
     791
     792\param <nentries>  number of data to be read
     793*/
    589794void FitsInFile::GetSingleColumn(double* map, int nentries) const
    590795{
     
    619824}
    620825
     826/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
     827same as above with float data
     828*/
    621829void FitsInFile::GetSingleColumn(float* map, int nentries) const
    622830{
     
    649857}
    650858
     859/*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
     860 same as above with int data
     861*/
    651862void FitsInFile::GetSingleColumn( int* map, int nentries) const
    652863{
     
    8661077}
    8671078
     1079
     1080/*!
     1081  \class SOPHYA::FitsOutFile
     1082 Class for loading  SOPHYA objects from FITS Format Files (uses cfitsio lib)
     1083*/
     1084
    8681085FitsOutFile::FitsOutFile()
    8691086{
     
    8711088}
    8721089
     1090   /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
     1091
     1092\param <WriteMode>  enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
     1093
     1094   */
    8731095FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
    8741096{
     
    9291151
    9301152
     1153/*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl)
     1154
     1155create an IMAGE header on FITS file.
     1156\param <type> type of data (see method ColTypeFromFits)
     1157\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
     1158\param <naxisn>  array containind sizes of the different dimensions
     1159*/
    9311160void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl)
    9321161{
     
    9681197
    9691198}
     1199
     1200
     1201/*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const
     1202
     1203write double data from array 'map'on an IMAGE extension
     1204\param <nbData>  number of data to be written
     1205*/
    9701206void FitsOutFile::PutImageToFits(int nbData, double* map) const
    9711207{
     
    9771213}
    9781214
     1215/*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const
     1216
     1217same as previous method with float data
     1218*/
    9791219void FitsOutFile::PutImageToFits(int nbData, float* map) const
    9801220{
     
    9861226
    9871227}
     1228
     1229  /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const
     1230
     1231 same as previous method with int data */
    9881232void FitsOutFile::PutImageToFits( int nbData, int* map) const
    9891233{
     
    9981242
    9991243
     1244/*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
     1245
     1246create an BINTABLE header on FITS file.
     1247\param <fieldType> array conta
     1248ining characters denoting types of the different column (see method ColTypeFromFits)
     1249\param <Noms>  array of the names of columns
     1250\param <nentries>  number of data of each column
     1251\param <tfields> number of columns
     1252\param <dvl> a SOPHYA DVList containing keywords to be appended
     1253\param <extname> keyword EXTNAME for FITS file
     1254\param <taille_des_chaines> vector containing the number of characters of  data  for each char* typed column, with order of appearance in 'fieldType'
     1255*/
    10001256void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
    10011257{
     
    10921348}
    10931349
     1350/*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
     1351
     1352write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
     1353\param <nentries>  number of data to be written
     1354*/
    10941355void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
    10951356{
     
    11141375  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    11151376}
     1377
     1378
     1379
     1380  /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
     1381
     1382same as previous method with float data
     1383*/
    11161384void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
    11171385{
     
    11401408  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    11411409}
     1410
     1411
     1412/*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
     1413
     1414same as previous method with int data
     1415*/
    11421416void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
    11431417{
     
    11661440  if( status )  printerror( status," ecriture du fichier fits" );
    11671441}
     1442
     1443
     1444/*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
     1445same as previous method with char* data
     1446*/
    11681447void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
    11691448{
     
    12281507
    12291508
     1509/* \fn void  SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
     1510
     1511Put keywords from a DVList into the primary header of the fits-file
     1512*/
    12301513void  FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
    12311514{
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1209 r1218  
    1010#define LEN_KEYWORD 9
    1111
     12// classes for saving/loading SOPHYA objects to/from FITS files...
     13// Guy le Meur (september 2000)
     14
     15
    1216namespace SOPHYA {
    1317
    14 struct BnTblLine
    15  {
    16 BnTblLine() {}
    17 void setFormat(int dc, int fc, int ic, int cc, vector<string> names)
    18    {
    19     int nbcols = dc + fc + ic + cc;
    20     int maxName = names.size();
    21     if (nbcols != maxName)
    22       {
    23         cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
    24         maxName = nbcols < maxName ? nbcols : maxName;
    25       }
    26     ColName_ = vector<string>(nbcols);
    27      for (int k=0; k < maxName; k++) ColName_[k] = names[k];
    28     if (dc >0) ddata_ = vector<double>(dc);
    29     if (fc >0) fdata_ = vector<float>(fc);
    30     if (ic >0) idata_ = vector<int>(fc);
    31     if (cc >0) cdata_ = vector<string>(fc);
    32    }
    33 
    34 bool sameFormat(const BnTblLine& btl) const
    35    {
    36      if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true;
    37      else return false;
    38    }
    39 
    40 void Print()
    41    {
    42      int k;
    43      cout << " ********* ligne ************* " << endl;
    44      cout << " *** noms de variables  " << endl;
    45      for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
    46      cout << endl;
    47      cout << " *** variables doubles  " << endl;
    48      for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
    49      cout << endl;
    50      cout << " *** variables float  " << endl;
    51      for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
    52      cout << endl;
    53      cout << " *** variables int  " << endl;
    54      for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
    55      cout << endl;
    56      cout << " *** variables string  " << endl;
    57      for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
    58      cout << endl;
    59      cout << " ***************************** " << endl;
    60    }
    61   vector<double> ddata_;
    62   vector<float>  fdata_;
    63   vector<int>    idata_;
    64   vector<string>  cdata_;
    65   vector<string> ColName_;
    66 
    67  };
    68 
    69  class FitsFile;
    70  class FitsInFile;
    71  class FitsOutFile;
    72  enum WriteMode {append, clear, unknown};
    73 
     18  struct BnTblLine;
     19  class FitsFile;
     20  class FitsInFile;
     21  class FitsOutFile;
     22  enum WriteMode {append, clear, unknown};
     23 
    7424
    7525//
    7626//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
    7727
    78 /*!
    79 The class structure is analogous to Sophya-PPersist system :
    80 Each SOPHYA object XXX is associated with a object of class FITS_XXX
    81  (inheriting from FitsFileHandler), to which input/output operations with FITS
    82  files are delegated (through a class Hierarchy : FitsFile (virtual),
    83  FitsInFile, FitsOutFile) . A typical example of use is the following :
    84 
    85 \verbatim
    86   int m=... ;
    87   SphereHEALPix<r_8> sphere1(m);           // definition of the SOPHYA object
    88   .... fill the sphere ....
    89 
    90   FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
    91                                            // delegated object
    92   fits_sph.Write("myfile.fits");           // writing on FITS file
    93 
    94    FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
    95                                            // load a delegated object
    96                                            // from FITS file
    97    SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
    98                                            // casting the delegated object
    99                                            // into a SOPHYA object
    100 \endverbatim
    101 
    102 */
    103 
    104 class FitsIOHandler {
    105 
    106 
    107   public:
    108 
    109 virtual ~FitsIOHandler() {}
    110 /*!
    111 this method is called from inherited objects :
    112 
    113 opens a file 'flnm'
    114 
    115 gets parameters in extension-header (hdunum)
    116 
    117 calls the method 'ReadFromFits' from the inherited  object
    118 
    119 
    120 */
    121   void   Read(char flnm[],int hdunum= 0);
    122 /*!
    123 this method is called from inherited objects :
    124 
    125 for writing a new object in a new fits-extension :
    126 
    127 ???
    128 
    129  at the end of
    130 
    131 the existing file (flnm), if OldFile=true.
    132 
    133 If OldFile=false, an exception occurs
     28 class FitsIOHandler {
     29
     30
     31 public:
     32
     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) ;
     38
     39
     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;
     47  };
     48
     49
     50//! Class (virtual) for managing FITS format files
     51 class FitsFile {
     52
     53 public:
     54
     55   FitsFile() { InitNull(); };
     56   virtual ~FitsFile();
     57   static string GetErrStatus(int status);
     58   inline  int   statusF() const { return fits_status_;}
    13459 
    135 By convention, primary header does not contain fits-image data : i.e.
    136 all data are fits-extensions. The first relevant header will have hdunum=2.
    137 For switching off this convention use the method :
    138 
    139 firstImageOnPrimaryHeader() (see below)
    140 
    141 In that case do not forget to precise hdunum=1 when reading data on primary header.
    142 
    143 calls the method 'WriteToFits' from the inherited  object
    144 
    145 */
    146   void   Write(char flnm[]) ;
    147 
    148   /*!
    149 Read 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.
    150    */
    151   void   Read(FitsInFile& ifts, int hdunum=0);
    152   void   Write(FitsOutFile& ofts) ;
    153 
    154 
    155   protected: 
    156   virtual void    ReadFromFits(FitsInFile& is)=0;           
    157   virtual void    WriteToFits(FitsOutFile& os) =0;           
    158   friend class FitsInFile;
    159   friend class FitsOutFile;
    160   private :
    161   };
    162 
    163 
    164 
    165 class FitsFile
    166 {
    167 
    168 public:
    169 
    170 FitsFile()
    171 {
    172  InitNull();
    173 };
    174   virtual ~FitsFile();
    175 
    176   static string GetErrStatus(int status);
    177 
    178 
    179 
    180 
    181 inline  int statusF() const { return fits_status_;}
    182  
    183 
    184 protected:
    185 
    186    void ResetStatus(int& status) ;
     60
     61 protected:
     62
     63   void         ResetStatus(int& status) ;
    18764   static  void printerror(int&) ;
    18865   static  void printerror(int&,char* texte) ;
    189    inline void InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 1;
     66   inline void  InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 1;
    19067   fits_status_ = 0;}
    19168
    192   //! pointer to the FITS file, defined in fitsio.h
    193   fitsfile *fptr_;
    194  
    195   //!  image or bintable ?
    196   int hdutype_;
    197 
    198 //! index of header to be read/written
    199   int hdunum_; 
    200 
    201   //! last status returned by fitsio library. updated only by several methods
    202   int fits_status_;
    203 
    204    
    205 };
    206 
     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 */
     73
     74 };
     75
     76//! Class for saving  SOPHYA objects on FITS Format Files (uses cfitsio lib)
    20777
    20878 class FitsInFile : public  FitsFile {
     
    21080 public:
    21181   FitsInFile();
    212    //   FitsInFile(char flnm[], int hdunum=0);
    21382   FitsInFile(char flnm[]);
    21483   ~FitsInFile() { ; };
    21584
    216 
    217 //////////////////////////////////////////////////////////
    218 //     methods with general purpose
    219 ///////////////////////////////////////
    220 
    221 
    222 
    223   static int NbBlocks(char flnm[]);
    224   static void GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
    225 
    226 
    227 
    228   //  void ReadFInit(char flnm[],int hdunum=0);
    229   void ReadFInit(int hdunum);
     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);
    23088 
    231   /*! return a reference on a DVList containing the keywords from FITS file
    232    */
    233 inline const DVList& DVListFromFits() const { return dvl_;}
    234 
    235 /* get the keywords of primary header in a DVList */
    236 DVList  DVListFromPrimaryHeader() const;
    237 
    238 void moveToFollowingHeader();
     89  /*! \return a reference on a DVList containing the keywords from FITS file */
     90  inline const DVList& DVListFromFits() const { return dvl_;}
     91
     92  DVList  DVListFromPrimaryHeader() const;
     93  void    moveToFollowingHeader();
     94
     95
    23996
    24097
     
    24299       ///////   methods for managing extensions ////////////////
    243100       //////////////////////////////////////////////////////////
    244 
    245101
    246102
     
    250106
    251107
    252 /*! return true if the current header  corresponds to a FITS image extension */
     108
     109/*! \return true if the current header  corresponds to a FITS image extension */
    253110inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
    254111
    255112
    256113
    257   /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
    258    */
     114  /*! \return number of dimensions of an image extension : NAXIS parameter (in FITS notations)   */
    259115inline int nbDimOfImage() const {return naxis_;}
    260 /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
    261  */
     116
     117/*! \return a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 etc. */
    262118 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
    263 /*!
    264  total number of data in the current IMAGE extension
    265  */
     119
     120
     121/*! \return total number of data in the current IMAGE extension */
    266122inline int nbOfImageData() const { return nbData_; }
    267123
     
    275131
    276132
    277 /*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
     133/*! \return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
    278134inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
    279135
    280136
    281 static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
     137 static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
    282138                                  vector<int>& repeat,
    283139                                  vector<string>& noms,
    284140                                  vector<char>& types,   
    285141                                  vector<int>&  taille_des_chaines);
    286 
    287 
    288 
    289   /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
    290 
    291 D : double
    292 
    293 E : float
    294 
    295 I : integer
    296    
    297 S : character string
    298 
    299   */
    300   char    ColTypeFromFits(int nocol) const;
    301   /*! name of the column number 'nocol' of the current BINTABLE extension
    302    */
    303   string  ColNameFromFits(int nocol) const;
    304 
    305   /*! number of characters of each data  for the column number 'nocol' (if char* typed) of the current BINTABLE extension
    306    */
    307   int     ColStringLengthFromFits(int nocol) const;
    308 
    309 
    310 
    311   /*!
    312 Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    313   */
    314   void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
     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
    315146** cdata) ;
    316   /*!
    317 Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    318   */
    319   void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
    320 
    321   /*!
    322 Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    323   */
    324   void GetBinTabLine(int NoLine, float* fdata) ;
    325 
    326 /*!
    327 fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
    328 
    329 \param <nentries>  number of data to be read
    330   */
    331   void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const;
    332 
    333   /*! same as previous method with float data */
    334   void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const;
    335   /*! same as previous method with int data */
    336   void GetBinTabFCol(int* valeurs, int nentries,  int NoCol) const;
    337   /*! same as previous method with char* data */
    338   void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
    339   // Write elements into the FITS data array
     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;
    340153
    341154/////////////////////////////////////////////////////////////
     
    343156////////////////////////////////////////////////////////
    344157
    345  /*! return number of columns (return 1 if IMAGE) */
    346158  int     NbColsFromFits() const;
    347   /*! number of data in the current IMAGE extension on FITS file, or number
    348  of data of column number 'nocol' of the current BINTABLE extension
    349   */
    350159  int     NentriesFromFits(int nocol) const;
    351160
    352161
    353 /*!
    354 fill the array 'map' with double data from the current extension on FITS file.
    355 If the extension is BINTABLE, the first column is provided.
    356 
    357 \param <nentries>  number of data to be read
    358   */
    359162  void    GetSingleColumn(double* map, int nentries) const;
    360163
    361   /*! same as above with float data */
    362164  void    GetSingleColumn(float*  map, int nentries) const;
    363165
    364   /*! same as above with int data */
    365166  void    GetSingleColumn(int* map, int nentries) const;
    366167
     
    371172static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
    372173
    373 
    374  
    375 
    376   //! fits-Image parameter
    377   int bitpix_;
    378 
    379   //! fits-Image parameter
    380   int naxis_;
    381 
    382   //! fits-Image parameters : sizes of dimensions
    383   vector<int> naxisn_;
    384 
    385   //! fits-Image parameter: number of data
    386   int nbData_;
    387 
    388   //! Bintable parameter
    389   int nrows_;
    390 
    391   //! Bintable parameter
    392   vector<int> repeat_;
    393 
    394   //! Bintable parameter
    395   int nbcols_;
    396 
    397   //! Bintable parameter: column names
    398   vector<string> noms_;
    399 
    400   //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
    401   vector<char> types_;   
    402 
    403   //! Bintable parameters:   length of the char* variables                 
    404   vector<int>  taille_des_chaines_;
    405 
    406   //! DVList for transferring keywords
    407   DVList dvl_;
    408 
    409 
    410  };
    411 
     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 */
     185
     186 };
     187
     188//! Class for loading  SOPHYA objects from FITS Format Files (uses cfitsio lib)
    412189
    413190 class FitsOutFile : public  FitsFile {
     
    417194
    418195   FitsOutFile();
    419    /*!
    420 \param <WriteMode>  enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
    421 
    422    */
    423196   FitsOutFile(char flnm[], WriteMode wrm = unknown );
    424197   ~FitsOutFile() { ;};
     
    437210
    438211   inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
    439 
    440   /*! create an IMAGE header on FITS file.
    441 \param <type> type of data (see method ColTypeFromFits)
    442 \param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
    443 \param <naxisn>  array containind sizes of the different dimensions
    444   */
    445   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl) ;
    446 
    447 
    448   /*! write double data from array 'map'on an IMAGE extension
    449 \param <nbData>  number of data to be written
    450 
    451    */
    452   void PutImageToFits( int nbData, double* map) const;
    453 
    454   /*! same as previous method with float data */
    455   void PutImageToFits(int nbData, float* map ) const;
    456 
    457   /*! same as previous method with int data */
    458   void PutImageToFits(int nbData, int* map) const;
     212   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl) ;
     213   void PutImageToFits( int nbData, double* map) const;
     214   void PutImageToFits(int nbData, float* map ) const;
     215   void PutImageToFits(int nbData, int* map) const;
    459216
    460217
     
    466223
    467224
    468   /*! create an BINTABLE header on FITS file.
    469 \param <fieldType> array conta
    470 ining characters denoting types of the different column (see method ColTypeFromFits)
    471 \param <Noms>  array of the names of columns
    472 \param <nentries>  number of data of each column
    473 \param <tfields> number of columns
    474 \param <dvl> a SOPHYA DVList containing keywords to be appended
    475 \param <extname> keyword EXTNAME for FITS file
    476 \param <taille_des_chaines> vector containing the number of characters of  data  for each char* typed column, with order of appearance in 'fieldType'
    477    */
    478225   void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname,  vector<int> taille_des_chaines) ;
    479 
    480   /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
    481 \param <nentries>  number of data to be written
    482 
    483    */
    484   void PutColToFits(int nocol, int nentries, double* donnees) const;
    485 
    486   /*! same as previous method with float data */
    487   void PutColToFits(int nocol, int nentries, float* donnees) const;
    488 
    489   /*! same as previous method with int data */
    490   void PutColToFits(int nocol, int nentries, int* donnees) const;
    491 
    492   /*! same as previous method with char* data */
    493   void PutColToFits(int nocol, int nentries, char** donnees) const;
    494 
    495   void PutBinTabLine(long NoLine,  BnTblLine& ligne) const;
     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;
    496231
    497232
     
    501236
    502237
    503 /* Put keywords from a DVList into the primary header of the fits-file */
    504238void  DVListIntoPrimaryHeader(DVList& dvl) const;
    505239
     
    515249 };
    516250
     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;
     256
     257   void Print();
     258
     259   vector<double> ddata_;
     260   vector<float>  fdata_;
     261   vector<int>    idata_;
     262   vector<string>  cdata_;
     263   vector<string> ColName_;
     264
     265 };
    517266
    518267
Note: See TracChangeset for help on using the changeset viewer.