Changeset 1334 in Sophya
- Timestamp:
- Nov 15, 2000, 4:29:11 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsautoreader.cc
r1301 r1334 25 25 } 26 26 27 int FITS_AutoReader::NbBlocks() 28 { 29 return inFits_->NbBlocks(); 30 } 27 31 28 32 AnyDataObj* FITS_AutoReader::ReadObject(int hdunum) const 29 33 { 34 if (hdunum<=0) 35 { 36 throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive"); 37 } 30 38 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 } 31 44 DVList dvl=inFits_->DVListFromFits(); 32 45 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; 34 47 if (nameObj == string("TArray") ) 35 48 { … … 83 96 else 84 97 { 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); 86 100 } 87 101 -
trunk/SophyaExt/FitsIOServer/fitsautoreader.h
r1301 r1334 29 29 FITS_AutoReader(string const & inputfile); 30 30 virtual ~FITS_AutoReader(); 31 AnyDataObj* ReadObject(int hdunum = 0) const; 31 int NbBlocks(); 32 AnyDataObj* ReadObject(int hdunum) const; 32 33 33 34 -
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1333 r1334 250 250 fits_get_num_hdus(fileptr, &nbhdu, &status); 251 251 fits_close_file(fileptr,&status); 252 return nbhdu; 253 } 254 int FitsInFile::NbBlocks() 255 { 256 int status = 0; 257 int nbhdu = 0; 258 fits_get_num_hdus(fptr_, &nbhdu, &status); 252 259 return nbhdu; 253 260 } … … 304 311 // InitNull(); 305 312 int status = 0; 306 313 if (hdunum<0) 314 { 315 throw PException(" FITS_AutoReader::ReadObject : hdu number must be not negative"); 316 } 307 317 if (hdunum != 0 ) hdunum_ = hdunum; 308 318 … … 321 331 } 322 332 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 } 324 345 } 325 346 … … 328 349 { 329 350 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; 331 352 int status= 0; 332 353 … … 398 419 if (naxis > 0 ) // there is an image 399 420 { 400 hdutype_ = IMAGE_HDU;421 hdutype_ = FitsExtensionType_IMAGE; 401 422 GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_); 402 423 nbData_ = 1; … … 407 428 else 408 429 { 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_); 416 432 } 417 433 } … … 420 436 int hdutype; 421 437 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; 426 459 GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_); 427 460 nbData_ = 1; … … 430 463 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 431 464 } 432 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL) 433 { 465 else if(hdutype == ASCII_TBL) 466 { 467 hdutype_= FitsExtensionType_ASCII_TBL; 434 468 GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_); 435 469 KeywordsIntoDVList(fptr_, dvl_, hdunum_); 436 470 } 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 } 437 482 } 438 483 } … … 444 489 hdunum_++; 445 490 getHeader(); 491 if ( hdutype_ == FitsExtensionType_NULL ) 492 { 493 cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl; 494 495 } 446 496 } 447 497 … … 455 505 int FitsInFile::NbColsFromFits() const 456 506 { 457 if(hdutype_ == 507 if(hdutype_ == FitsExtensionType_BINARY_TBL) return nbcols_; 458 508 else 459 if(hdutype_ == ASCII_TBL || hdutype_ == IMAGE_HDU) return 1;509 if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_IMAGE) return 1; 460 510 else 461 511 { 462 512 cout << " hdutype= " << hdutype_ << endl; 463 throw PException("FitsFile::NbColsFromFits, this HDU is unknown");513 throw PException("FitsFile::NbColsFromFits, HDU not supported"); 464 514 } 465 515 } … … 471 521 int FitsInFile::NentriesFromFits(int nocol) const 472 522 { 473 if(hdutype_ == BINARY_TBL) return nrows_*repeat_[nocol];523 if(hdutype_ == FitsExtensionType_BINARY_TBL) return nrows_*repeat_[nocol]; 474 524 else 475 if(hdutype_ == ASCII_TBL) return nrows_;525 if(hdutype_ == FitsExtensionType_ASCII_TBL) return nrows_; 476 526 else 477 if(hdutype_ == IMAGE_HDU) return nbData_;527 if(hdutype_ == FitsExtensionType_IMAGE) return nbData_; 478 528 else 479 529 { 480 530 cout << "hdutype= " << hdutype_ << endl; 481 throw PException("FitsFile::NentriesFromFits, this HDU is unknown");531 throw PException("FitsFile::NentriesFromFits, this HDU is not supported"); 482 532 } 483 533 } … … 499 549 FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const 500 550 { 501 if(hdutype_ != ASCII_TBL && hdutype_ !=BINARY_TBL)551 if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL) 502 552 { 503 553 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); … … 514 564 string FitsInFile::ColNameFromFits(int nocol) const 515 565 { 516 if(hdutype_ != ASCII_TBL && hdutype_ !=BINARY_TBL)566 if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL) 517 567 { 518 568 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); … … 528 578 int FitsInFile::ColStringLengthFromFits(int nocol) const 529 579 { 530 if(hdutype_ != ASCII_TBL && hdutype_ !=BINARY_TBL)580 if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL) 531 581 { 532 582 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); … … 806 856 { 807 857 int status = 0; 808 if(hdutype_ == IMAGE_HDU)858 if(hdutype_ == FitsExtensionType_IMAGE) 809 859 { 810 860 … … 824 874 } 825 875 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 888 same as above with float data 889 */ 890 void 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) 827 910 { 828 911 GetBinTabFCol(map,nentries, 0); … … 835 918 } 836 919 837 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( float* map, int nentries) const838 same as above with float data839 */ 840 void FitsInFile::GetSingleColumn( float* map, int nentries) const841 { 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 */ 923 void 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 "; 848 931 cout << " Conversion to float achieved by cfitsio lib" << endl; 849 932 } … … 853 936 854 937 long nels= nentries; 855 fits_read_img(fptr_,T FLOAT,1,nels,&fnull,map,&anull,&status);938 fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status); 856 939 if( status ) printerror( status ); 857 940 } 858 941 else 859 if(hdutype_ == ASCII_TBL || hdutype_ ==BINARY_TBL)942 if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL) 860 943 { 861 944 GetBinTabFCol(map,nentries, 0); … … 868 951 } 869 952 870 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const871 same as above with int data872 */873 void FitsInFile::GetSingleColumn( int* map, int nentries) const874 {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 pixels884 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 else892 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)893 {894 GetBinTabFCol(map,nentries, 0);895 }896 else897 {898 cout << " hdutype= " << hdutype_ << endl;899 throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");900 }901 }902 903 953 void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows, 904 954 vector<int>& repeat, … … 917 967 throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table"); 918 968 } 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; 923 973 924 974 // get the number of columns -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1300 r1334 55 55 56 56 enum FitsExtensionType { 57 FitsExtensionType_NULL, 57 58 FitsExtensionType_IMAGE, 58 59 FitsExtensionType_ASCII_TBL, 59 FitsExtensionType_BINARY_TBL 60 FitsExtensionType_BINARY_TBL, 61 FitsExtensionType_EOF, 62 FitsExtensionType_ERROR 60 63 }; 61 64 enum FitsDataType { … … 81 84 static void printerror(int&) ; 82 85 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; 84 87 fits_status_ = 0; imageOnPrimary_ = true;} 85 88 fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */ 86 inthdutype_; /**< image or bintable ? */89 FitsExtensionType hdutype_; /**< image or bintable ? */ 87 90 int hdunum_; /**< index of header to be read/written */ 88 91 int fits_status_; /**< last status returned by fitsio library. updated only by several methods */ … … 102 105 103 106 static int NbBlocks(char flnm[]); 107 int NbBlocks(); 104 108 static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl ); 105 109 void ReadHeader(int hdunum); … … 126 130 127 131 /*! \return true if the current header corresponds to a FITS image extension */ 128 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}132 inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);} 129 133 130 134 … … 152 156 153 157 /*! \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);}158 inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);} 155 159 156 160 … … 176 180 //////////////////////////////////////////////////////// 177 181 182 /*! \return true if the current header is beyond the maximum */ 183 inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);} 184 /*! \return true if the current header is incorrect, following a cfitsio, movavs error */ 185 inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);} 186 178 187 int NbColsFromFits() const; 179 188 int NentriesFromFits(int nocol) const; -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
r1300 r1334 203 203 // 204 204 dobj_->Info() = is.DVListFromFits(); 205 cout << " end of file reading " << endl;206 205 } 207 206 -
trunk/SophyaExt/FitsIOServer/fitstarray.cc
r1300 r1334 73 73 } 74 74 int dimension = is.nbDimOfImage(); 75 cout << " dimension de l'image a lire: " << dimension << endl;76 77 75 sa_size_t * siz = new sa_size_t[dimension]; 78 76 for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
Note:
See TracChangeset
for help on using the changeset viewer.