Ignore:
Timestamp:
Nov 15, 2000, 4:29:11 PM (25 years ago)
Author:
ansari
Message:

modifs returns de autoreader

File:
1 edited

Legend:

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

    r1333 r1334  
    250250  fits_get_num_hdus(fileptr, &nbhdu, &status);
    251251  fits_close_file(fileptr,&status);
     252  return nbhdu;
     253}
     254int FitsInFile::NbBlocks()
     255{
     256  int status = 0;
     257  int nbhdu = 0;
     258  fits_get_num_hdus(fptr_, &nbhdu, &status);
    252259  return nbhdu;
    253260}
     
    304311  //  InitNull();
    305312  int status = 0;
    306 
     313  if (hdunum<0)
     314    {
     315      throw PException(" FITS_AutoReader::ReadObject : hdu number must be not negative");
     316    }
    307317  if (hdunum != 0 ) hdunum_ = hdunum;
    308318
     
    321331    }
    322332  getHeader();
    323 
     333  if ( hdutype_ == FitsExtensionType_NULL )
     334    {
     335      if (hdunum == 0 && hdunum_ == 1)
     336        {
     337          hdunum_++;
     338          getHeader();
     339        }
     340      else
     341        {
     342          cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
     343        }
     344    }
    324345}
    325346
     
    328349{
    329350  int hdunum=0;
    330   cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
     351  //    cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
    331352  int status= 0;
    332353
     
    398419      if (naxis > 0 )       // there is an image
    399420        {
    400           hdutype_ = IMAGE_HDU;
     421          hdutype_ = FitsExtensionType_IMAGE;
    401422          GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
    402423          nbData_ =  1;
     
    407428      else
    408429        {
    409           cout << " WARNING (FitsInFile::getHeader): attempt to read data on the primary hader, which does not contain any... It may be a consequence of confusion in the HDU numbering of the application." << endl;
    410           cout << " The object to be read is supposed to be a bin or ascii table.. on the first extension" << endl;
    411           cout << " Anyway, some trouble can result... " << endl;
    412           hdunum_++;
    413           getHeader();
    414 
    415           //      throw PException(" first header : no image, probably error in hdunum");
     430          hdutype_ = FitsExtensionType_NULL;
     431          KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    416432        }
    417433    }
     
    420436      int hdutype;
    421437      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    422       if( status ) printerror( status,":FitsInFile::getHeader : erreur movabs");
    423       hdutype_= hdutype;
    424       if(hdutype_ == IMAGE_HDU)
    425         {
     438
     439      if( status )
     440        {
     441          if (status == END_OF_FILE)
     442            {
     443              hdutype_= FitsExtensionType_EOF;
     444              status =0;
     445              return;
     446            }
     447          else
     448            {
     449              cout << "WARNING (FitsInFile::getHeader) : error during movabs" << endl;
     450              hdutype_= FitsExtensionType_ERROR;
     451              status =0;
     452              return;
     453            }
     454          // printerror( status,":FitsInFile::getHeader : erreur movabs");
     455        }
     456      if(hdutype == IMAGE_HDU)
     457        {
     458          hdutype_= FitsExtensionType_IMAGE;
    426459          GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
    427460          nbData_ =  1;
     
    430463          KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    431464        }
    432       if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
    433         {
     465      else if(hdutype == ASCII_TBL)
     466        {
     467          hdutype_= FitsExtensionType_ASCII_TBL;
    434468          GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
    435469          KeywordsIntoDVList(fptr_, dvl_, hdunum_);
    436470        }
     471      else if(hdutype == BINARY_TBL)
     472        {
     473          hdutype_= FitsExtensionType_BINARY_TBL;
     474          GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
     475          KeywordsIntoDVList(fptr_, dvl_, hdunum_);
     476        }
     477      else
     478        {
     479          hdutype_= FitsExtensionType_NULL;
     480          KeywordsIntoDVList(fptr_, dvl_, hdunum_);
     481        }
    437482    }
    438483}
     
    444489  hdunum_++;
    445490  getHeader();
     491  if ( hdutype_ == FitsExtensionType_NULL )
     492    {
     493      cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
     494       
     495    }
    446496}
    447497
     
    455505int  FitsInFile::NbColsFromFits() const
    456506{
    457   if(hdutype_ ==  BINARY_TBL) return nbcols_;
     507  if(hdutype_ == FitsExtensionType_BINARY_TBL) return nbcols_;
    458508  else
    459     if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
     509    if(hdutype_ == FitsExtensionType_ASCII_TBL ||  hdutype_ == FitsExtensionType_IMAGE) return 1;
    460510    else
    461511      {
    462512        cout << " hdutype= " << hdutype_ << endl;
    463         throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
     513        throw PException("FitsFile::NbColsFromFits, HDU  not supported");
    464514      }
    465515}
     
    471521int FitsInFile::NentriesFromFits(int nocol) const
    472522{
    473   if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
     523  if(hdutype_ == FitsExtensionType_BINARY_TBL)   return nrows_*repeat_[nocol];
    474524  else
    475     if(hdutype_ == ASCII_TBL) return nrows_;
     525    if(hdutype_ == FitsExtensionType_ASCII_TBL) return nrows_;
    476526    else
    477       if(hdutype_ == IMAGE_HDU) return nbData_;
     527      if(hdutype_ == FitsExtensionType_IMAGE) return nbData_;
    478528      else
    479529        {
    480530          cout << "hdutype= " << hdutype_ << endl;
    481           throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
     531          throw PException("FitsFile::NentriesFromFits, this HDU is not supported");
    482532        }
    483533}
     
    499549FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const
    500550{
    501   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     551  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
    502552    {
    503553      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     
    514564string FitsInFile::ColNameFromFits(int nocol) const
    515565{
    516   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     566  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
    517567    {
    518568      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     
    528578int FitsInFile::ColStringLengthFromFits(int nocol) const
    529579{
    530   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     580  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
    531581    {
    532582      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     
    806856{
    807857  int status = 0;
    808   if(hdutype_ == IMAGE_HDU)
     858  if(hdutype_ == FitsExtensionType_IMAGE)
    809859    {
    810860 
     
    824874    }
    825875  else
    826     if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
     876    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
     877      {
     878        GetBinTabFCol(map,nentries, 0);
     879      }
     880    else
     881      {
     882      cout << " hdutype= " << hdutype_ << endl;
     883      throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown");
     884      }
     885}
     886
     887/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
     888same as above with float data
     889*/
     890void FitsInFile::GetSingleColumn(float* map, int nentries) const
     891{
     892  int status = 0;
     893  if(hdutype_ == FitsExtensionType_IMAGE)
     894    {
     895      if(imageDataType_ != FitsDataType_float)
     896        {
     897          cout << " The data type on fits file is not float ";
     898          cout << " Conversion to float achieved by cfitsio lib" << endl;
     899        }
     900      // no checking for undefined pixels
     901      int   anull;
     902      float fnull= 0.;
     903     
     904      long nels= nentries;
     905      fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
     906      if( status ) printerror( status );
     907    }
     908  else
     909    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
    827910      {
    828911        GetBinTabFCol(map,nentries, 0);
     
    835918}
    836919
    837 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
    838 same as above with float data
    839 */
    840 void FitsInFile::GetSingleColumn(float* map, int nentries) const
    841 {
    842   int status = 0;
    843   if(hdutype_ == IMAGE_HDU)
    844     {
    845       if(imageDataType_ != FitsDataType_float)
    846         {
    847           cout << " The data type on fits file is not float ";
     920/*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
     921 same as above with int data
     922*/
     923void FitsInFile::GetSingleColumn( int* map, int nentries) const
     924{
     925  int status = 0;
     926  if(hdutype_ == FitsExtensionType_IMAGE)
     927    {
     928      if(imageDataType_ != FitsDataType_int)
     929        {
     930          cout << " The data type on fits file is not int ";
    848931          cout << " Conversion to float achieved by cfitsio lib" << endl;
    849932        }
     
    853936     
    854937      long nels= nentries;
    855       fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
     938      fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
    856939      if( status ) printerror( status );
    857940    }
    858941  else
    859     if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
     942    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
    860943      {
    861944        GetBinTabFCol(map,nentries, 0);
     
    868951}
    869952
    870 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
    871  same as above with int data
    872 */
    873 void FitsInFile::GetSingleColumn( int* map, int nentries) const
    874 {
    875   int status = 0;
    876   if(hdutype_ == IMAGE_HDU)
    877     {
    878       if(imageDataType_ != FitsDataType_int)
    879         {
    880           cout << " The data type on fits file is not int ";
    881           cout << " Conversion to float achieved by cfitsio lib" << endl;
    882         }
    883       // no checking for undefined pixels
    884       int   anull;
    885       float fnull= 0.;
    886      
    887       long nels= nentries;
    888       fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
    889       if( status ) printerror( status );
    890     }
    891   else
    892     if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
    893       {
    894         GetBinTabFCol(map,nentries, 0);
    895       }
    896     else
    897       {
    898       cout << " hdutype= " << hdutype_ << endl;
    899       throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
    900       }
    901 }
    902 
    903953void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
    904954                                  vector<int>& repeat,
     
    917967      throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
    918968    }
    919   if(hdutype == ASCII_TBL)
    920     cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 
    921   if(hdutype == BINARY_TBL)
    922     cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
     969  //  if(hdutype == ASCII_TBL)
     970  //        cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 
     971  //  if(hdutype == BINARY_TBL)
     972  //        cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
    923973
    924974  // get the number of columns
Note: See TracChangeset for help on using the changeset viewer.