Changeset 2449 in Sophya
- Timestamp:
- Oct 29, 2003, 12:17:48 AM (22 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fabtcolread.cc
r2174 r2449 5 5 #include "pexceptions.h" 6 6 #include "fabtcolread.h" 7 8 /////////////////////////////////////////////////////////////////// 9 /////////////////////////////////////////////////////////////////// 10 /////////////////////////////////////////////////////////////////// 11 /////////////////////////////////////////////////////////////////// 12 13 //! Class for opening a FITS file for reading 14 15 /*! 16 \class SOPHYA::FitsOpenFile 17 \ingroup FitsIOServer 18 Class for opening a FITS file for reading 19 */ 20 21 /*! 22 Constructor. 23 \param fname : FITS file name to be opened for reading 24 */ 25 FitsOpenFile::FitsOpenFile(string fname) 26 { 27 Init(fname.c_str()); 28 } 29 30 /*! 31 Constructor. 32 \param cfname : FITS file name to be opened for reading 33 */ 34 FitsOpenFile::FitsOpenFile(const char *cfname) 35 { 36 Init(cfname); 37 } 38 39 /*! 40 Constructor by default. 41 */ 42 FitsOpenFile::FitsOpenFile() 43 { 44 FitsFN = ""; 45 NHdu = -1; 46 FitsPtr = NULL; 47 } 48 49 /*! 50 Constructor by copy. 51 */ 52 FitsOpenFile::FitsOpenFile(FitsOpenFile& fof) 53 { 54 Init(fof.GetFileName().c_str()); 55 } 56 57 /*! 58 Destructor. 59 */ 60 FitsOpenFile::~FitsOpenFile() 61 { 62 Delete(); 63 FitsFN = ""; 64 NHdu = 0; 65 } 66 67 /*! 68 Delete routine called by the destructor. 69 */ 70 void FitsOpenFile::Delete(void) 71 { 72 if(FitsPtr != NULL) { 73 int sta = 0; 74 if(fits_close_file(FitsPtr,&sta)) printerror(sta); 75 FitsPtr = NULL; 76 } 77 } 78 79 /*! Init routine called by the constructor */ 80 void FitsOpenFile::Init(const char* fname) 81 { 82 // Parametres Generaux 83 FitsFN = fname; 84 NHdu = 0; 85 FitsPtr = NULL; 86 87 // Ouverture du fichier 88 if(FitsFN.size() <= 0 ) 89 throw ParmError("FitsOpenFile::Init: Fits file name error\n"); 90 91 int sta = 0; 92 if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) { 93 printerror(sta); 94 FitsPtr = NULL; 95 throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n"); 96 } 97 98 // Get number of hdu 99 if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) { 100 printerror(sta); 101 NHdu = 0; 102 Delete(); 103 throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n"); 104 } 105 if(NHdu<=0) { 106 Delete(); 107 throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n"); 108 } 109 110 } 111 112 void FitsOpenFile::printerror(int sta) const 113 { 114 int stat = sta; 115 fits_report_error(stdout,stat); 116 fflush(stdout); 117 return; 118 } 119 120 /////////////////////////////////////////////////////////////////// 121 /////////////////////////////////////////////////////////////////// 122 /////////////////////////////////////////////////////////////////// 123 /////////////////////////////////////////////////////////////////// 124 125 /////////////////////////////////////////////////////////////////// 7 126 //! Class for reading a column in a FITS ASCII or BINARY table 8 127 9 128 /*! 10 \class SOPHYA::FitsABTColR ead129 \class SOPHYA::FitsABTColRd 11 130 \ingroup FitsIOServer 12 131 Class for reading a column in a FITS ASCII or BINARY table 13 132 \verbatim 14 133 -- Exemple: 15 FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3); 134 // Open the fits file with FitsOpenFile 135 FitsOpenFile fof = new FitsOpenFile("myfits.fits"); 136 // Select the column to be read 137 FitsABTColRd fbt(fof,"BoloMuv_28",0,1000,1,3); 16 138 fbt.SetDebug(3); 17 139 fbt.Print(3); … … 28 150 n = fbt.Read(10,-1,data); 29 151 cout<<"Number of values read: "<<n<<endl; 152 // Close the fits file 153 delete fof; 30 154 \endverbatim 31 155 */ … … 34 158 /*! 35 159 Constructor. 36 \param f name : FITS file name to be read160 \param fof : Pointer to the Class for opening the FITS file 37 161 \param collabel : label of the column to be read 38 162 \param ihdu : number of the HDU where the column is. … … 48 172 \warning ihdu = [1,nhdu] 49 173 */ 50 FitsABTColR ead::FitsABTColRead(string fname,string collabel51 52 { 53 Init(fname.c_str(),collabel.c_str(),-1,ihdu,blen,bsens,lp);174 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel 175 ,int ihdu,long blen,long bsens,int lp) 176 { 177 Init(fof,collabel.c_str(),-1,ihdu,blen,bsens,lp); 54 178 } 55 179 … … 60 184 \warning col = [0,ncol[ 61 185 */ 62 FitsABTColRead::FitsABTColRead(string fname,int colnum 63 ,int ihdu,long blen,long bsens,int lp) 64 { 65 Init(fname.c_str(),"",colnum,ihdu,blen,bsens,lp); 66 } 67 68 /*! Constructor. see below */ 69 FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel 70 ,int ihdu,long blen,long bsens,int lp) 71 { 72 Init(cfname,collabel,-1,ihdu,blen,bsens,lp); 73 } 74 75 /*! Constructor. see below */ 76 FitsABTColRead::FitsABTColRead(const char * cfname,int colnum 77 ,int ihdu,long blen,long bsens,int lp) 78 { 79 Init(cfname,"",colnum,ihdu,blen,bsens,lp); 186 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum 187 ,int ihdu,long blen,long bsens,int lp) 188 { 189 Init(fof,"",colnum,ihdu,blen,bsens,lp); 80 190 } 81 191 82 192 /*! Constructor by copy */ 83 FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt) 84 { 85 Init(fbt.GetFileName().c_str(),fbt.GetColLabel().c_str() 86 ,fbt.GetColNum(),fbt.GetHDU() 87 ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel); 193 FitsABTColRd::FitsABTColRd(FitsABTColRd& fbt) 194 { 195 Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str() 196 ,fbt.GetColNum(),fbt.GetHDU() 197 ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel); 198 } 199 200 /*! Constructor by default */ 201 FitsABTColRd::FitsABTColRd() 202 { 203 FitsFN = ""; 204 ColLabel = ""; ColTUnit = ""; ColTForm = ""; 205 ColNum = -1; ColTypeCode = 0; 206 IHdu = 0; NHdu = 0; HduType = 0; 207 NBcol = 0; NBline = 0; 208 SetNulVal(); SetDebug(0); 209 NFitsRead = 0; 210 FitsOF = NULL; FitsPtr = NULL; 211 LineDeb = LineFin = -1; 212 Buffer = NULL; 88 213 } 89 214 90 215 /*! Init routine called by the constructor */ 91 void FitsABTColR ead::Init(const char* fname,const char* collabel,int colnum216 void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum 92 217 ,int ihdu,long blen,long bsens,int lp) 93 218 { 94 // Parametres Generaux95 FitsFN = fname;219 // Initialisation des Parametres Generaux 220 FitsFN = ""; 96 221 ColLabel = collabel; 97 222 ColTUnit = ""; … … 107 232 SetDebug(lp); 108 233 NFitsRead = 0; 234 FitsOF = NULL; 109 235 FitsPtr = NULL; 110 236 LineDeb = LineFin = -1; … … 112 238 ChangeBuffer(blen,bsens); 113 239 114 ////////////////////////// 115 // Ouverture du fichier // 116 ////////////////////////// 117 118 int sta=0; 119 if(FitsFN.size() <= 0 ) { 120 IHdu = -1; Delete(); 121 throw ParmError("FitsABTColRead::Init: Fits file name error\n"); 122 } 123 const char * cfitsfn = FitsFN.c_str(); 124 125 // Open fits 126 if(fits_open_file(&FitsPtr,cfitsfn,READONLY,&sta)) { 127 printerror(sta); Delete(); 128 throw NullPtrError("FitsABTColRead::Init: Error opening Fits file\n"); 129 } 130 131 // Get number of hdu 132 if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) { 133 printerror(sta); Delete(); 134 throw NotAvailableOperation("FitsABTColRead::Init: Error getting NHdu\n"); 135 } 136 if(DbgLevel>1) cout<<"FitsABTColRead::Init NHdu="<<NHdu<<endl; 240 // Caracteristiques du FitsOpenFile 241 FitsOF = fof; 242 if(FitsOF==NULL) { 243 Delete(); 244 throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n"); 245 } 246 FitsPtr = FitsOF->GetFitsPtr(); 247 if(FitsPtr==NULL) { 248 Delete(); 249 throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n"); 250 } 251 NHdu = FitsOF->GetNHdu(); 252 if(DbgLevel>1) cout<<"FitsABTColRd::Init NHdu="<<NHdu<<endl; 137 253 if(NHdu<=0) { 138 254 Delete(); 139 throw SzMismatchError("FitsABTColRead::Init: Bad NHdu\n"); 140 } 255 throw SzMismatchError("FitsABTColRd::Init: Bad NHdu\n"); 256 } 257 FitsFN = FitsOF->GetFileName(); 258 if(FitsFN.size() <= 0 ) { 259 Delete(); 260 throw ParmError("FitsABTColRd::Init: Fits file name error\n"); 261 } 262 263 int sta = 0; 141 264 142 265 // Get HDU for bin/ascii table … … 153 276 cout<<"NO BINARY or ASCII hdu found"<<endl; 154 277 IHdu = 0; Delete(); 155 throw TypeMismatchExc("FitsABTColR ead::Init: NO BINARY or ASCII hdu found\n");278 throw TypeMismatchExc("FitsABTColRd::Init: NO BINARY or ASCII hdu found\n"); 156 279 } 157 280 if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) { 158 281 printerror(sta); Delete(); 159 throw RangeCheckError("FitsABTColR ead::Init: Error moving to requested HDU\n");282 throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n"); 160 283 } 161 284 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) { 162 285 Delete(); 163 throw TypeMismatchExc("FitsABTColR ead::Init: HDU not ASCII/BINARY table\n");286 throw TypeMismatchExc("FitsABTColRd::Init: HDU not ASCII/BINARY table\n"); 164 287 } 165 288 … … 167 290 if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) { 168 291 printerror(sta); Delete(); 169 throw NotAvailableOperation("FitsABTColR ead::Init: Error getting number of columns\n");292 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n"); 170 293 } 171 294 if(DbgLevel>1) cout<<"...Init NBcol="<<NBcol<<endl; 172 295 if(NBcol<1) { 173 296 Delete(); 174 throw RangeCheckError("FitsABTColR ead::Init: Bad number of colums\n");297 throw RangeCheckError("FitsABTColRd::Init: Bad number of colums\n"); 175 298 } 176 299 … … 178 301 if(fits_get_num_rows(FitsPtr,&NBline,&sta)) { 179 302 printerror(sta); Delete(); 180 throw NotAvailableOperation("FitsABTColR ead::Init: Error getting number of rows\n");303 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n"); 181 304 } 182 305 if(DbgLevel>1) cout<<"...Init NBline="<<NBline<<endl; 183 306 if(NBline<1) { 184 307 Delete(); 185 throw RangeCheckError("FitsABTColR ead::Init: Bad number of rows\n");308 throw RangeCheckError("FitsABTColRd::Init: Bad number of rows\n"); 186 309 } 187 310 … … 192 315 if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) { 193 316 printerror(sta); Delete(); 194 throw NotAvailableOperation("FitsABTColR ead::Init: Error getting column name\n");317 throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n"); 195 318 } 196 319 ColNum--; // Convention [0,ncol[ … … 199 322 if(ColNum<0 || ColNum>=NBcol) { 200 323 Delete(); 201 throw RangeCheckError("FitsABTColR ead::Init: Bad column number\n");324 throw RangeCheckError("FitsABTColRd::Init: Bad column number\n"); 202 325 } 203 326 … … 205 328 if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) { 206 329 printerror(sta); Delete(); 207 throw ParmError("FitsABTColR ead::Init: Error getting column type\n");330 throw ParmError("FitsABTColRd::Init: Error getting column type\n"); 208 331 } 209 332 if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl; … … 211 334 || ColTypeCode<0 ) { 212 335 Delete(); 213 throw ParmError("FitsABTColR ead::Init: Selected column is not Numerical\n");336 throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n"); 214 337 } 215 338 … … 227 350 if(rc) { 228 351 printerror(sta); Delete(); 229 throw RangeCheckError("FitsABTColR ead::Init: Error getting the column caracteristics\n");352 throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n"); 230 353 } 231 354 ColLabel = labelcol; … … 234 357 235 358 if(DbgLevel) 236 cout<<"FitsABTColR ead::Init Num="<<ColNum<<" Label="<<ColLabel359 cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel 237 360 <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl; 238 361 if(DbgLevel>1) … … 243 366 244 367 /*! Destructor. */ 245 FitsABTColR ead::~FitsABTColRead()368 FitsABTColRd::~FitsABTColRd() 246 369 { 247 370 Delete(); 248 371 } 249 372 250 ////////////////////////////////////////////////////////////// 251 double FitsABTColRead::ReadKey(char *keyname) 252 { 253 if(keyname==NULL) return 0.; 254 int sta=0; double val=0.; 255 if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta)) 256 printerror(sta); 257 return val; 373 /*! Delete called by the destructor */ 374 void FitsABTColRd::Delete(void) 375 { 376 if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;} 377 LineDeb = LineFin = -1; 378 //--- Surtout on ne "fits_close_file" pas le fichier FITS !!! 258 379 } 259 380 260 381 ////////////////////////////////////////////////////////////// 261 382 /*! Change the buffer caracteristiques (see creator) */ 262 void FitsABTColR ead::ChangeBuffer(long blen,long bsens)383 void FitsABTColRd::ChangeBuffer(long blen,long bsens) 263 384 { 264 385 long oldnbuffer = NBuffer; … … 285 406 } 286 407 287 / *! Delete called by the destructor */288 void FitsABTColRead::Delete()289 { 290 if( Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}291 LineDeb = LineFin = -1;292 i nt sta = 0;293 if(fits_close_file(FitsPtr,&sta))printerror(sta);294 FitsPtr = NULL;408 ////////////////////////////////////////////////////////////// 409 double FitsABTColRd::ReadKey(char *keyname) 410 { 411 if(keyname==NULL) return 0.; 412 int sta=0; double val=0.; 413 if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta)) 414 printerror(sta); 415 return val; 295 416 } 296 417 … … 307 428 \endverbatim 308 429 */ 309 double FitsABTColR ead::Read(long n,bool usebuffer)430 double FitsABTColRd::Read(long n,bool usebuffer) 310 431 // Attention: n=nline [0,NBline[, cfistio veut [1,NBline] 311 432 // Attention: colnum [0,NBcol[ , cfistio veut [1,NBcol] … … 313 434 int sta=0; 314 435 if(n<0 || n>=NBline) 315 throw RangeCheckError("FitsABTColR ead::Read try to read outside line range\n");436 throw RangeCheckError("FitsABTColRd::Read try to read outside line range\n"); 316 437 317 438 // Pas de bufferisation, on lit betement … … 322 443 if(sta) { 323 444 printerror(sta); 324 throw NotAvailableOperation("FitsABTColR ead::Read: Error Reading Fits file\n");445 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 325 446 } 326 447 // On ne remplit Buffer[0] que si on a choisit … … 336 457 // Gestion avec bufferisation 337 458 if(!Buffer) 338 throw RangeCheckError("FitsABTColR ead::Read: Buffer not allocated\n");459 throw RangeCheckError("FitsABTColRd::Read: Buffer not allocated\n"); 339 460 if(n<LineDeb || n>LineFin) { 340 461 NFitsRead++; … … 358 479 printerror(sta); 359 480 LineDeb = LineFin = -1; 360 throw NotAvailableOperation("FitsABTColR ead::Read: Error Reading Fits file\n");481 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 361 482 } 362 483 } … … 398 519 \endverbatim 399 520 */ 400 long FitsABTColR ead::Read(long n1,long n2,TVector<double>& data)521 long FitsABTColRd::Read(long n1,long n2,TVector<double>& data) 401 522 { 402 523 if(n1<0 || n1>=NBline) 403 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 1srt line \n");524 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n"); 404 525 if(data.Size()<=0 && n2<n1) 405 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 2sd line \n");526 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n"); 406 527 if(n2<0) n2 = n1 + data.Size()-1; 407 528 if(n2>=NBline) n2 = NBline-1; … … 415 536 if(sta) { 416 537 printerror(sta); 417 throw NotAvailableOperation("FitsABTColR ead::Read_TVector<double>: Error Reading Fits file\n");538 throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n"); 418 539 } 419 540 … … 422 543 423 544 /*! idem before but for TVector of float */ 424 long FitsABTColR ead::Read(long n1,long n2,TVector<float>& data)545 long FitsABTColRd::Read(long n1,long n2,TVector<float>& data) 425 546 { 426 547 if(n1<0 || n1>=NBline) 427 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 1srt line \n");548 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n"); 428 549 if(data.Size()<=0 && n2<n1) 429 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 2sd line \n");550 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n"); 430 551 if(n2<0) n2 = n1 + data.Size()-1; 431 552 if(n2>=NBline) n2 = NBline-1; … … 439 560 if(sta) { 440 561 printerror(sta); 441 throw NotAvailableOperation("FitsABTColR ead::Read_TVector<float>: Error Reading Fits file\n");562 throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n"); 442 563 } 443 564 … … 446 567 447 568 /*! idem before but for TVector of unsigned short */ 448 long FitsABTColR ead::Read(long n1,long n2,TVector<uint_2>& data)569 long FitsABTColRd::Read(long n1,long n2,TVector<uint_2>& data) 449 570 { 450 571 if(n1<0 || n1>=NBline) 451 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 1srt line \n");572 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n"); 452 573 if(data.Size()<=0 && n2<n1) 453 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 2sd line \n");574 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n"); 454 575 if(n2<0) n2 = n1 + data.Size()-1; 455 576 if(n2>=NBline) n2 = NBline-1; … … 462 583 if(sta) { 463 584 printerror(sta); 464 throw NotAvailableOperation("FitsABTColR ead::Read_TVector<uint_2>: Error Reading Fits file\n");585 throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n"); 465 586 } 466 587 … … 469 590 470 591 /*! idem before but for TVector of int_4 */ 471 long FitsABTColR ead::Read(long n1,long n2,TVector<int_4>& data)592 long FitsABTColRd::Read(long n1,long n2,TVector<int_4>& data) 472 593 { 473 594 if(n1<0 || n1>=NBline) 474 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 1srt line \n");595 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n"); 475 596 if(data.Size()<=0 && n2<n1) 476 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 2sd line \n");597 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n"); 477 598 if(n2<0) n2 = n1 + data.Size()-1; 478 599 if(n2>=NBline) n2 = NBline-1; … … 487 608 if(sta) { 488 609 printerror(sta); 489 throw NotAvailableOperation("FitsABTColR ead::Read_TVector<int_4>: Error Reading Fits file\n");610 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n"); 490 611 } 491 612 … … 494 615 495 616 /*! idem before but for TVector of int_8 */ 496 long FitsABTColR ead::Read(long n1,long n2,TVector<int_8>& data)617 long FitsABTColRd::Read(long n1,long n2,TVector<int_8>& data) 497 618 { 498 619 #ifdef TLONGLONG 499 620 if(n1<0 || n1>=NBline) 500 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 1srt line \n");621 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n"); 501 622 if(data.Size()<=0 && n2<n1) 502 throw RangeCheckError("FitsABTColR ead::Read TVector bad requested 2sd line \n");623 throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n"); 503 624 if(n2<0) n2 = n1 + data.Size()-1; 504 625 if(n2>=NBline) n2 = NBline-1; … … 511 632 if(sta) { 512 633 printerror(sta); 513 throw NotAvailableOperation("FitsABTColR ead::Read_TVector<int_8>: Error Reading Fits file\n");634 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n"); 514 635 } 515 636 516 637 return nread; 517 638 #else 518 throw PException("FitsABTColR ead::Read(..,TVector<int_8>&) Not in that cfitsio version");639 throw PException("FitsABTColRd::Read(..,TVector<int_8>&) Not in that cfitsio version"); 519 640 #endif 520 641 } … … 531 652 \return <0 means not found 532 653 */ 533 long FitsABTColR ead::FirstRow(double val1,double val2,long rowstart)654 long FitsABTColRd::FirstRow(double val1,double val2,long rowstart) 534 655 { 535 656 long row = -1; … … 560 681 \endverbatim 561 682 */ 562 long FitsABTColR ead::LastRow(double val1,double val2,long rowstart)683 long FitsABTColRd::LastRow(double val1,double val2,long rowstart) 563 684 { 564 685 long row = -1; … … 579 700 580 701 ///////////////////////////////////////////////// 581 void FitsABTColR ead::printerror(int sta) const702 void FitsABTColRd::printerror(int sta) const 582 703 { 583 704 int stat = sta; … … 588 709 589 710 /*! Print on stream os */ 590 void FitsABTColR ead::Print(ostream& os,int lp) const591 { 592 os<<"FitsABTColR ead:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"711 void FitsABTColRd::Print(ostream& os,int lp) const 712 { 713 os<<"FitsABTColRd:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")" 593 714 <<" ncols="<<NBcol<<" nrows="<<NBline; 594 715 if(lp>0) os<<" NRead="<<NFitsRead; … … 599 720 <<endl; 600 721 } 722 723 /////////////////////////////////////////////////////////////////// 724 /////////////////////////////////////////////////////////////////// 725 /////////////////////////////////////////////////////////////////// 726 /////////////////////////////////////////////////////////////////// 727 728 //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening 729 730 /*! 731 \class SOPHYA::FitsABTColRead 732 \ingroup FitsIOServer 733 Class for reading a column in a FITS ASCII or BINARY table with fits file opening 734 \verbatim 735 -- Exemple: 736 FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3); 737 fbt.SetDebug(3); 738 fbt.Print(3); 739 // Read element by element 740 for(long i=0;i<fbt.GetNbLine();i++) { 741 double x = fbt.Read(i); 742 if(i%lpmod==0) cout<<i<<": "<<x<<endl; 743 } 744 // Read into a vector 745 TVector<double> data; 746 long n = fbt.Read(32,50,data); 747 cout<<"Number of values read: "<<n<<endl; 748 data.ReSize(100); 749 n = fbt.Read(10,-1,data); 750 cout<<"Number of values read: "<<n<<endl; 751 \endverbatim 752 */ 753 754 755 ////////////////////////////////////////////////////////////// 756 /*! 757 Constructor. 758 \param fname : FITS file name to be read 759 \param collabel : label of the column to be read 760 \param ihdu : number of the HDU where the column is. 761 \param blen : read buffer length 762 \param bsens : buffer reading direction 763 \param lp : debug level 764 \verbatim 765 - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken 766 - bsens>0 read forward 767 bsens<0 read backward 768 bsens==0 read centered 769 \endverbatim 770 \warning ihdu = [1,nhdu] 771 */ 772 FitsABTColRead::FitsABTColRead(string fname,string collabel 773 ,int ihdu,long blen,long bsens,int lp) 774 : FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,blen,bsens,lp) 775 { 776 } 777 778 /*! 779 Constructor. 780 Same as before but the column is identified by its column number 781 \param colnum : number of the column to be read 782 \warning col = [0,ncol[ 783 */ 784 FitsABTColRead::FitsABTColRead(string fname,int colnum 785 ,int ihdu,long blen,long bsens,int lp) 786 : FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,blen,bsens,lp) 787 { 788 } 789 790 /*! Constructor. see below */ 791 FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel 792 ,int ihdu,long blen,long bsens,int lp) 793 : FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,blen,bsens,lp) 794 { 795 } 796 797 /*! Constructor. see below */ 798 FitsABTColRead::FitsABTColRead(const char * cfname,int colnum 799 ,int ihdu,long blen,long bsens,int lp) 800 : FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,blen,bsens,lp) 801 { 802 } 803 /*! Constructor by default */ 804 FitsABTColRead::FitsABTColRead() 805 { 806 } 807 808 /*! Constructor by copy */ 809 FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt) 810 { 811 // --- ATTENTION --- 812 // FitsABTColRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile 813 FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile()); 814 Init(fof,fbt.GetColLabel().c_str() 815 ,fbt.GetColNum(),fbt.GetHDU() 816 ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel); 817 } 818 819 /*! Destructor. */ 820 FitsABTColRead::~FitsABTColRead() 821 { 822 Delete(); 823 if(FitsOF!=NULL) delete FitsOF; 824 } -
trunk/SophyaExt/FitsIOServer/fabtcolread.h
r2322 r2449 14 14 namespace SOPHYA { 15 15 16 /////////////////////////////////////////////////////////////////// 17 //! Class for opening a FITS file for reading 18 class FitsOpenFile : public AnyDataObj { 19 public: 20 FitsOpenFile(string fname); 21 FitsOpenFile(const char *cfname); 22 FitsOpenFile(); 23 FitsOpenFile(FitsOpenFile& fof); 24 virtual ~FitsOpenFile(); 25 26 inline string GetFileName() {return FitsFN;} 27 inline int GetNHdu() {return NHdu;} 28 inline fitsfile* GetFitsPtr() {return FitsPtr;} 29 30 protected: 31 void Init(const char *cfname); 32 void Delete(void); 33 void printerror(int sta) const; 34 35 string FitsFN; 36 int NHdu; 37 fitsfile *FitsPtr; 38 }; 39 40 /////////////////////////////////////////////////////////////////// 16 41 //! Class for reading a column in a FITS ASCII or BINARY table 17 class FitsABTColR ead : public AnyDataObj {42 class FitsABTColRd : public AnyDataObj { 18 43 public: 19 FitsABTColRead(string fname,string collabel,int ihdu=0 20 ,long blen=100,long bsens=1,int lp=0); 21 FitsABTColRead(string fname,int colnum,int ihdu=0 22 ,long blen=100,long bsens=1,int lp=0); 23 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0 24 ,long blen=100,long bsens=1,int lp=0); 25 FitsABTColRead(const char *cfname,int colnum,int ihdu=0 26 ,long blen=100,long bsens=1,int lp=0); 27 FitsABTColRead(FitsABTColRead& fbt); 28 virtual ~FitsABTColRead(); 44 FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0 45 ,long blen=100,long bsens=1,int lp=0); 46 FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0 47 ,long blen=100,long bsens=1,int lp=0); 48 FitsABTColRd(FitsABTColRd& fbt); 49 FitsABTColRd(); 50 virtual ~FitsABTColRd(); 29 51 30 52 void ChangeBuffer(long blen=100,long bsens=1); … … 56 78 //! Get the FITS file name 57 79 inline string GetFileName(void) {return FitsFN;} 80 //! Get the pointer to FitsOpenFile 81 inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;} 58 82 //! Get the FITS file pointer (cfistio pointer) 59 83 inline fitsfile* GetFitsPointer(void) {return FitsPtr;} … … 92 116 93 117 protected: 94 void Init( const char *cfname,const char *collabel,int colnum118 void Init(FitsOpenFile* fof,const char *collabel,int colnum 95 119 ,int ihdu,long blen,long bsens,int lp); 96 120 void Delete(void); … … 106 130 107 131 unsigned long NFitsRead; 108 fitsfile *FitsPtr; 132 FitsOpenFile* FitsOF; 133 fitsfile* FitsPtr; 109 134 long LineDeb, LineFin; 110 135 double *Buffer; … … 112 137 }; 113 138 139 /////////////////////////////////////////////////////////////////// 140 //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening 141 class FitsABTColRead : public FitsABTColRd { 142 public: 143 FitsABTColRead(string fname,string collabel,int ihdu=0 144 ,long blen=100,long bsens=1,int lp=0); 145 FitsABTColRead(string fname,int colnum,int ihdu=0 146 ,long blen=100,long bsens=1,int lp=0); 147 FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0 148 ,long blen=100,long bsens=1,int lp=0); 149 FitsABTColRead(const char *cfname,int colnum,int ihdu=0 150 ,long blen=100,long bsens=1,int lp=0); 151 FitsABTColRead(FitsABTColRead& fbt); 152 FitsABTColRead(); 153 virtual ~FitsABTColRead(); 154 }; 155 114 156 } // namespace SOPHYA 115 157 #endif /* FABTCOLREAD_H_SEEN */
Note:
See TracChangeset
for help on using the changeset viewer.