Changeset 1334 in Sophya


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

modifs returns de autoreader

Location:
trunk/SophyaExt/FitsIOServer
Files:
6 edited

Legend:

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

    r1301 r1334  
    2525}
    2626
     27int FITS_AutoReader::NbBlocks()
     28{
     29  return inFits_->NbBlocks();
     30}
    2731
    2832AnyDataObj* FITS_AutoReader::ReadObject(int hdunum) const
    2933{
     34  if (hdunum<=0)
     35    {
     36      throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive");
     37    }
    3038  inFits_->ReadHeader(hdunum);
     39  if (inFits_->IsFitsEOF()) return NULL;
     40  if (inFits_->IsFitsERROR())
     41    {
     42      throw IOExc("FITS_AutoReader::ReadObject: FITSIO error in reading");
     43    }
    3144  DVList dvl=inFits_->DVListFromFits();
    3245  string nameObj = dvl.GetS("CONTENT");
    33   cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
     46  //    cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
    3447  if (nameObj == string("TArray") )
    3548    {
     
    8396  else
    8497    {
    85       throw IOExc("FITS_AutoReader::ReadObject : object not recognized as a  SOPHYA object");
     98      cout << " WARNING ( FITS_AutoReader::ReadObject) : object not recognized as a  SOPHYA object" << endl;
     99      return new DVList(dvl);
    86100    }
    87101 
  • trunk/SophyaExt/FitsIOServer/fitsautoreader.h

    r1301 r1334  
    2929FITS_AutoReader(string const & inputfile);
    3030virtual ~FITS_AutoReader();
    31 AnyDataObj* ReadObject(int hdunum = 0) const;
     31 int NbBlocks();
     32AnyDataObj* ReadObject(int hdunum) const;
    3233
    3334
  • 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
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1300 r1334  
    5555
    5656   enum FitsExtensionType {
     57     FitsExtensionType_NULL,
    5758     FitsExtensionType_IMAGE,
    5859     FitsExtensionType_ASCII_TBL,
    59      FitsExtensionType_BINARY_TBL
     60     FitsExtensionType_BINARY_TBL,
     61     FitsExtensionType_EOF,
     62     FitsExtensionType_ERROR
    6063   };
    6164   enum FitsDataType {
     
    8184   static  void printerror(int&) ;
    8285   static  void printerror(int&,char* texte) ;
    83    inline void  InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 0;
     86   inline void  InitNull() {fptr_ = NULL; hdutype_= FitsExtensionType_NULL; hdunum_ = 0;
    8487   fits_status_ = 0; imageOnPrimary_ = true;}
    8588   fitsfile *fptr_;     /**<  pointer to the FITS file, defined in fitsio.h */
    86    int hdutype_;        /**<  image or bintable ? */
     89   FitsExtensionType hdutype_;        /**<  image or bintable ? */
    8790   int hdunum_;         /**<   index of header to be read/written */
    8891   int fits_status_;    /**< last status returned by fitsio library. updated only by several methods */
     
    102105
    103106   static int  NbBlocks(char flnm[]);
     107   int  NbBlocks();
    104108   static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl  );
    105109   void        ReadHeader(int hdunum);
     
    126130
    127131/*! \return true if the current header  corresponds to a FITS image extension */
    128 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
     132inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);}
    129133
    130134
     
    152156
    153157/*! \return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
    154 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
     158inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
    155159
    156160
     
    176180////////////////////////////////////////////////////////
    177181
     182/*! \return true if the current header  is beyond the maximum */
     183inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
     184/*! \return true if the current header  is incorrect, following a cfitsio, movavs error */
     185inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
     186
    178187  int     NbColsFromFits() const;
    179188  int     NentriesFromFits(int nocol) const;
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc

    r1300 r1334  
    203203  //
    204204  dobj_->Info()  = is.DVListFromFits();
    205   cout << " end of file reading " << endl;
    206205}
    207206
  • trunk/SophyaExt/FitsIOServer/fitstarray.cc

    r1300 r1334  
    7373    }
    7474  int dimension = is.nbDimOfImage();
    75   cout << " dimension de l'image a lire: " << dimension << endl;
    76    
    7775  sa_size_t * siz = new sa_size_t[dimension];
    7876  for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
Note: See TracChangeset for help on using the changeset viewer.