Ignore:
Timestamp:
Apr 13, 2000, 11:25:15 AM (25 years ago)
Author:
ansari
Message:

methodes NbBlock et getBlockType

File:
1 edited

Legend:

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

    r867 r903  
    22#include "pexceptions.h"
    33#include "strutil.h"
    4 
    5 
     4#include "anydataobj.h"
     5#include "fitsspherehealpix.h"
    66FitsFile::FitsFile()
    77{
     
    1717{
    1818  int status = 0;
    19   if( fptr_ != NULL) fits_close_file(fptr_,&status);
     19  if( fptr_ != NULL)
     20    {
     21      fits_close_file(fptr_,&status);
     22      delete fptr_;
     23    }
    2024  if( status )  printerror( status );
    2125}
     26
     27
     28int FitsFile::NbBlocks(char flnm[])
     29{
     30  int status = 0;
     31  int nbhdu = 0;
     32  fitsfile* fileptr;
     33  fits_open_file(&fileptr,flnm,READONLY,&status);
     34  if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
     35  fits_get_num_hdus(fileptr, &nbhdu, &status);
     36  fits_close_file(fileptr,&status);
     37  return nbhdu;
     38}
     39
     40void FitsFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
     41{
     42  int status = 0;
     43  fitsfile* fileptr;
     44  fits_open_file(&fileptr,flnm,READONLY,&status);
     45  if( status ) printerror( status, "getBlockType: erreur ouverture fichier" );
     46  // move to the specified HDU number
     47  int hdutype = 0;
     48  fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
     49  if( status ) printerror( status,"getBlockType: erreur movabs");
     50  if(hdutype == IMAGE_HDU)
     51    {
     52      typeOfExtension = "IMAGE";
     53      int bitpix;
     54      GetImageParameters (fileptr, bitpix, naxis, naxisn);
     55      if(bitpix == DOUBLE_IMG) dataType = "double";
     56      else
     57        if(bitpix == FLOAT_IMG) dataType = "float";
     58        else
     59          if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = "int";
     60          else
     61            {
     62              cout << " bitpix= " << bitpix << endl;
     63              throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
     64            }
     65     
     66    }
     67  else
     68    if(hdutype == ASCII_TBL  || hdutype == BINARY_TBL)
     69      {
     70        int nrows = 0;
     71        vector<string> noms;
     72        vector<char> types;   
     73        vector<int>  taille_des_chaines;
     74        GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines); 
     75        for (int k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
     76        if(hdutype == ASCII_TBL)
     77          {
     78            typeOfExtension = "ASCII_TBL";
     79            dataType = "ASCII";
     80          }
     81        else
     82          {
     83            typeOfExtension = "BINARY_TBL";
     84            if(types[0] == 'D') dataType = "double";
     85            else
     86              if(types[0] == 'E') dataType = "float";
     87              else
     88                if(types[0] == 'I' ) dataType = "int";
     89                else
     90                  if(types[0] == 'S' ) dataType = "char*";
     91                  else
     92                    {
     93                      cout << " types[0]= " << types[0] << endl;
     94                      throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
     95            }
     96          }
     97      }
     98    else
     99      {
     100        cout << " hdutype= " << hdutype << endl;
     101        throw IOExc("FitsFile::getBlockType: this HDU type is unknown");
     102      }
     103 
     104  fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
     105  if( status ) printerror( status,"getBlockType: erreur movabs, pour dvlist");
     106  KeywordsIntoDVList(fileptr, dvl);
     107  fits_close_file(fileptr,&status);
     108}
     109
    22110void FitsFile::ReadF(char flnm[],int hdunum)
    23111{
     
    37125  if(hdutype_ == IMAGE_HDU)
    38126    {
    39       read_image();
     127      GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
     128      nbData_ =  1;
     129      for (int k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
     130      fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
     131      if( status ) printerror( status);
     132      KeywordsIntoDVList(fptr_, dvl_);
    40133    }
    41134  if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
    42135    {
    43       GetBinTabParameters();
     136      GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
     137  fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
     138  if( status ) printerror( status);
     139  KeywordsIntoDVList(fptr_, dvl_);
    44140    }
    45141  ReadFromFits(*this);
     
    199295
    200296
    201 void FitsFile::read_image()
    202 {
    203   cout << " Reading a FITS image in HDU : " << hdunum_ << endl;
     297
     298void FitsFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
     299{
     300  int hdunum=0;
     301  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
    204302  int status= 0;
    205303
    206304  // bits per pixels
    207   fits_read_key(fptr_,TINT,"BITPIX",&bitpix_,NULL,&status);
     305  fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
    208306  if( status )  printerror( status );
    209307
    210308  // number of dimensions in the FITS array
    211   int naxis= 0;
    212   fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
    213   if( status ) printerror( status );
    214   naxis_ = naxis;
    215 
    216   // read the NAXIS1 and NAXIS2 keyword to get image size
    217   long* naxes = new long[naxis_] ;
     309  naxis= 0;
     310  fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
     311  if( status ) printerror( status );
     312
     313  // read the NAXISn keywords to get image size
     314  long* naxes = new long[naxis] ;
    218315  int nfound;
    219   fits_read_keys_lng(fptr_,"NAXIS",1,naxis_,naxes,&nfound,&status);
    220   if( status ) printerror( status );
    221   if (nfound != naxis_ )
    222     cout << " WARNING : " << nfound << " axes found, expexted naxis= " << naxis_ << endl;
    223   int lastSize = naxes[naxis_-1];
    224   while (lastSize <= 1)
    225     {
    226       naxis_--;
    227       lastSize = naxes[naxis_-1];
    228     }
    229 
    230   nbData_ =  1;
    231   for (int k=0; k<naxis_; k++)
    232     {
    233       naxisn_.push_back( (int)naxes[k] );
    234       if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
    235 
     316  fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
     317  if( status ) printerror( status );
     318  if (nfound != naxis )
     319    cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
     320  for (int k=0; k<naxis; k++)
     321    {
     322      naxisn.push_back( (int)naxes[k] );
    236323    }
    237324  delete [] naxes;
    238325}
    239326
    240  
    241   void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
    242     {
    243       int status= 0;
    244       int DTYPE;
    245       long repeat,width;
    246             fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    247       if( DTYPE != TDOUBLE)
    248         {
    249           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
    250         }
    251       long nels=nentries;
    252       // no checking for undefined pixels
    253       int    anull;
    254       float dnull= 0.;
    255       fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
    256                             &anull,&status);
    257       if( status ) printerror( status,"erreur lecture de colonne" );
    258     }
    259 
    260   void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
    261     {
    262       int status= 0;
    263       int DTYPE;
    264       long repeat,width;
    265       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    266       if( DTYPE != TFLOAT)
    267         {
    268           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
    269         }
    270       long nels=nentries;
    271       // no checking for undefined pixels
    272       int    anull;
    273       float fnull= 0.;
    274       fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
    275                             &anull,&status);
    276       if( status ) printerror( status,"erreur lecture de colonne" );
    277     }
    278   void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
    279     {
    280       int status= 0;
    281       int DTYPE;
    282       long repeat,width;
    283       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    284       if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT )
    285         {
    286           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
    287         }
    288       long nels=nentries;
    289       // no checking for undefined pixels
    290       int    anull;
    291       int inull= 0;
    292       fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
    293                             &anull,&status);
    294       if( status ) printerror( status,"erreur lecture de colonne" );
    295     }
    296   void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
    297     {
    298       int status= 0;
    299       int DTYPE;
    300       long repeat,width;
    301       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    302       if( DTYPE != TSTRING )
    303         {
    304           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
    305         }
    306       long nels=nentries;
    307       // no checking for undefined pixels
    308       int    anull;
    309       char* cnull= " ";
    310       long frow=1;
    311       long felem=1;
    312       fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
    313                     &anull,&status);
    314       if( status ) printerror( status,"erreur lecture de colonne" );
    315     }
    316 int  FitsFile::NbColsFromFits() const
    317 {
    318   int status= 0;
    319   if(hdutype_ ==  BINARY_TBL) return nbcols_;
    320   else
    321     if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
    322     else
    323       {
    324         cout << " hdutype= " << hdutype_ << endl;
    325         throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
    326       }
    327 }
    328 
    329 char FitsFile::ColTypeFromFits(int nocol) const
    330 {
    331   int status= 0;
    332   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    333     {
    334       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    335     }
    336   return types_[nocol];
    337 }
    338 int FitsFile::NentriesFromFits(int nocol) const
    339 {
    340   int status= 0;
    341   if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
    342   else
    343     if(hdutype_ == ASCII_TBL) return nrows_;
    344     else
    345       if(hdutype_ == IMAGE_HDU) return nbData_;
    346       else
    347         {
    348           cout << "hdutype= " << hdutype_ << endl;
    349           throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
    350         }
    351 }
    352 
    353 string FitsFile::ColNameFromFits(int nocol) const
    354 {
    355   int status= 0;
    356   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    357     {
    358       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    359     }
    360   return noms_[nocol];
    361 }
    362 int FitsFile::ColStringLengthFromFits(int nocol) const
    363 {
    364   int status= 0;
    365   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    366     {
    367       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    368     }
    369   int index=-1;
    370   for (int k=0; k<=nocol; k++)
    371     {
    372       if (types_[k] == 'S') index++;
    373     }
    374   return  taille_des_chaines_[index];
    375 }
    376 
    377 void FitsFile::GetBinTabParameters()
    378 {
    379   int status= 0;
    380   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    381     {
    382       throw IOExc("FitsFile:: this HDU is not an ASCII table nor a binary table");
    383     }
    384   if(hdutype_ == ASCII_TBL)
    385     cout << " Reading a FITS ascii table in HDU : " << hdunum_ << endl; 
    386   if(hdutype_ == BINARY_TBL)
    387     cout << " Reading a FITS binary table in HDU : " << hdunum_ << endl;
    388 
    389   // get the number of columns
    390   int nbcols = 0;
    391   fits_get_num_cols(fptr_, &nbcols,&status);
    392   if( status ) printerror( status );
    393   nbcols_=nbcols;
    394 
    395   // get the number of rows
    396   long naxis2= 0;
    397   fits_get_num_rows(fptr_,&naxis2,&status);
    398   if( status ) printerror( status );
    399   nrows_= (int)naxis2;
    400 
    401   // get the datatype,  names and the repeat count
    402   noms_.clear();
    403   noms_.reserve(nbcols);
    404   types_.clear();
    405   types_.reserve(nbcols);
    406   repeat_.clear();
    407   repeat_.reserve(nbcols);
    408   taille_des_chaines_.clear();
    409   char **ttype = new char*[nbcols];
    410   for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
    411   int nfound;
    412   fits_read_keys_str(fptr_, "TTYPE",1,nbcols,ttype,&nfound, &status);
    413   if( status ) printerror( status,"erreur lecture des noms de colonne");
    414   //  int nentries = nrows_;
    415   int rept=0;
    416   for(int ii = 0; ii <  nbcols; ii++)
    417     {
    418       int DTYPE;
    419       long width;
    420       long repeat = 0;
    421       fits_get_coltype(fptr_,ii+1,&DTYPE,&repeat,&width,&status);
    422       if( status ) printerror( status,"erreur lecture type de colonne");
    423       rept = repeat;
    424       noms_.push_back(string(ttype[ii]));
    425       //      cout << " getparam: nentries= " << nentries << " rept= " << rept << endl;
    426       switch (DTYPE)
    427         {
    428         case TDOUBLE :
    429           types_.push_back('D');
    430           break;
    431         case TFLOAT :
    432           types_.push_back('E');
    433           break;
    434         case TLONG :
    435           types_.push_back('I');
    436           break;
    437         case TINT :
    438           types_.push_back('I');
    439           break;
    440         case TSHORT :
    441           types_.push_back('I');
    442           break;
    443         case TSTRING :
    444           types_.push_back('S');
    445           taille_des_chaines_.push_back(width);
    446           rept/=width;
    447           break;
    448         default :
    449           cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
    450           throw IOExc("FitsFile:: unknown type of field");
    451         }
    452       //    nentries = max(nentries, nrows_*rept);
    453       repeat_.push_back(rept);
    454     }
     327void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl)
     328{
    455329  // get number of keywords
    456330  int nkeys,keypos;
    457   fits_get_hdrpos(fptr_,&nkeys,&keypos,&status);
     331  int status = 0;
     332  fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
    458333  if( status ) printerror( status );
    459334
     
    470345  for(int j = num+1; j <= nkeys; j++)
    471346    {
    472       fits_read_keyn(fptr_,j,card,strval,NULL,&status);
     347      fits_read_keyn(fileptr,j,card,strval,NULL,&status);
    473348      if(status) printerror(status);
    474349
     
    488363            {
    489364            case 'C':
    490               dvl_[keyname]= strval;     
     365              dvl[keyname]= strval;       
    491366              break;
    492367            case 'I':
    493368              int ival;
    494               fits_read_key(fptr_,TINT,keyname,&ival,NULL,&status);
    495                 dvl_[keyname]= (int_4) ival;            // Portage mac DY
     369              fits_read_key(fileptr,TINT,keyname,&ival,NULL,&status);
     370                dvl[keyname]= (int_4) ival;             // Portage mac DY
    496371              break;
    497372            case 'L':
     
    499374              if(strncmp(strval,"T",1) == 0) ilog= 1;
    500375              else ilog= 0;
    501               dvl_[keyname]= (int_4) ilog;
     376              dvl[keyname]= (int_4) ilog;
    502377              break;
    503378            case 'F':
    504379              double dval;
    505               fits_read_key(fptr_,TDOUBLE,keyname,&dval,NULL,&status);
    506               dvl_[keyname]= dval;
     380              fits_read_key(fileptr,TDOUBLE,keyname,&dval,NULL,&status);
     381              dvl[keyname]= dval;
    507382              break;
    508383            }
     
    511386    }
    512387  //  dvl_.Print();
    513 }
     388}
     389
     390
     391 
     392  void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
     393    {
     394      int status= 0;
     395      int DTYPE;
     396      long repeat,width;
     397            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     398      if( DTYPE != TDOUBLE)
     399        {
     400          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
     401        }
     402      long nels=nentries;
     403      // no checking for undefined pixels
     404      int    anull;
     405      float dnull= 0.;
     406      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
     407                            &anull,&status);
     408      if( status ) printerror( status,"erreur lecture de colonne" );
     409    }
     410
     411  void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
     412    {
     413      int status= 0;
     414      int DTYPE;
     415      long repeat,width;
     416      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     417      if( DTYPE != TFLOAT)
     418        {
     419          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
     420        }
     421      long nels=nentries;
     422      // no checking for undefined pixels
     423      int    anull;
     424      float fnull= 0.;
     425      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
     426                            &anull,&status);
     427      if( status ) printerror( status,"erreur lecture de colonne" );
     428    }
     429  void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     430    {
     431      int status= 0;
     432      int DTYPE;
     433      long repeat,width;
     434      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     435      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT )
     436        {
     437          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
     438        }
     439      long nels=nentries;
     440      // no checking for undefined pixels
     441      int    anull;
     442      int inull= 0;
     443      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
     444                            &anull,&status);
     445      if( status ) printerror( status,"erreur lecture de colonne" );
     446    }
     447  void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
     448    {
     449      int status= 0;
     450      int DTYPE;
     451      long repeat,width;
     452      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     453      if( DTYPE != TSTRING )
     454        {
     455          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
     456        }
     457      long nels=nentries;
     458      // no checking for undefined pixels
     459      int    anull;
     460      char* cnull= " ";
     461      long frow=1;
     462      long felem=1;
     463      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
     464                    &anull,&status);
     465      if( status ) printerror( status,"erreur lecture de colonne" );
     466    }
     467int  FitsFile::NbColsFromFits() const
     468{
     469  int status= 0;
     470  if(hdutype_ ==  BINARY_TBL) return nbcols_;
     471  else
     472    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
     473    else
     474      {
     475        cout << " hdutype= " << hdutype_ << endl;
     476        throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
     477      }
     478}
     479
     480char FitsFile::ColTypeFromFits(int nocol) const
     481{
     482  int status= 0;
     483  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     484    {
     485      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     486    }
     487  return types_[nocol];
     488}
     489int FitsFile::NentriesFromFits(int nocol) const
     490{
     491  int status= 0;
     492  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
     493  else
     494    if(hdutype_ == ASCII_TBL) return nrows_;
     495    else
     496      if(hdutype_ == IMAGE_HDU) return nbData_;
     497      else
     498        {
     499          cout << "hdutype= " << hdutype_ << endl;
     500          throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
     501        }
     502}
     503
     504string FitsFile::ColNameFromFits(int nocol) const
     505{
     506  int status= 0;
     507  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     508    {
     509      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     510    }
     511  return noms_[nocol];
     512}
     513int FitsFile::ColStringLengthFromFits(int nocol) const
     514{
     515  int status= 0;
     516  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     517    {
     518      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     519    }
     520  int index=-1;
     521  for (int k=0; k<=nocol; k++)
     522    {
     523      if (types_[k] == 'S') index++;
     524    }
     525  return  taille_des_chaines_[index];
     526}
     527
     528
     529
     530void FitsFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
     531                                  vector<int>& repeat,
     532                                  vector<string>& noms,
     533                                  vector<char>& types,   
     534                                  vector<int>&  taille_des_chaines)
     535{
     536  int status= 0;
     537  int hdunum=0;
     538  int hdutype=0;
     539  fits_get_hdu_num(fileptr,&hdunum);
     540  fits_get_hdu_type(fileptr, &hdutype, &status);
     541
     542  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
     543    {
     544      throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
     545    }
     546  if(hdutype == ASCII_TBL)
     547    cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 
     548  if(hdutype == BINARY_TBL)
     549    cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
     550
     551  // get the number of columns
     552  fits_get_num_cols(fileptr, &nbcols,&status);
     553  if( status ) printerror( status );
     554
     555  // get the number of rows
     556  long naxis2= 0;
     557  fits_get_num_rows(fileptr,&naxis2,&status);
     558  if( status ) printerror( status );
     559  nrows = (int)naxis2;
     560
     561  // get the datatype,  names and the repeat count
     562  noms.clear();
     563  noms.reserve(nbcols);
     564  types.clear();
     565  types.reserve(nbcols);
     566  repeat.clear();
     567  repeat.reserve(nbcols);
     568  taille_des_chaines.clear();
     569  char **ttype = new char*[nbcols];
     570  for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
     571  int nfound;
     572  fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
     573  if( status ) printerror( status,"erreur lecture des noms de colonne");
     574  int rept=0;
     575  for(int ii = 0; ii <  nbcols; ii++)
     576    {
     577      int DTYPE;
     578      long width;
     579      long repete = 0;
     580      fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
     581      if( status ) printerror( status,"erreur lecture type de colonne");
     582      rept = repete;
     583      noms.push_back(string(ttype[ii]));
     584      switch (DTYPE)
     585        {
     586        case TDOUBLE :
     587          types.push_back('D');
     588          break;
     589        case TFLOAT :
     590          types.push_back('E');
     591          break;
     592        case TLONG :
     593          types.push_back('I');
     594          break;
     595        case TINT :
     596          types.push_back('I');
     597          break;
     598        case TSHORT :
     599          types.push_back('I');
     600          break;
     601        case TSTRING :
     602          types.push_back('S');
     603          taille_des_chaines.push_back(width);
     604          rept/=width;
     605          break;
     606        default :
     607          cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
     608          throw IOExc("FitsFile:: unknown type of field");
     609        }
     610      repeat.push_back(rept);
     611    }
     612}
     613
     614
     615
    514616void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const
    515617{
     
    777879}
    778880
    779 void FitsFile::printerror(int &status) const
     881
     882
     883
     884void FitsFile::printerror(int &status)
    780885  //*****************************************************/
    781886  //* Print out cfitsio error messages and exit program */
     
    790895}
    791896
    792 void FitsFile::printerror(int& status, char* texte) const
     897void FitsFile::printerror(int& status, char* texte)
    793898  //*****************************************************/
    794899  //* Print out cfitsio error messages and exit program */
Note: See TracChangeset for help on using the changeset viewer.