Changeset 4029 in Sophya for trunk/SophyaExt/FitsIOServer/fabtcolread.cc
- Timestamp:
- Oct 22, 2011, 1:15:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fabtcolread.cc
r4025 r4029 1 /* Lecteur de colonne de table Fits (binaire ou ASCII) avec buffer*/1 /* Lecteur de colonne de table Fits (binaire ou ASCII) */ 2 2 #include "sopnamsp.h" 3 3 #include "machdefs.h" … … 307 307 \param collabel : label of the column to be read 308 308 \param ihdu : number of the HDU where the column is. 309 \param blen : read buffer length310 \param bsens : buffer reading direction311 309 \param lp : debug level 312 310 \verbatim 313 311 - if ihdu<=0 first BINARY or ASCII table is taken 314 312 - if ihdu>nhdu ihdu is set to nhdu 315 - bsens>0 read forward316 bsens<0 read backward317 bsens==0 read centered318 313 \endverbatim 319 314 \warning ihdu = [1,nhdu] 320 315 */ 321 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel 322 ,int ihdu,long blen,long bsens,int lp) 323 { 324 Init(fof,collabel.c_str(),-1,ihdu,blen,bsens,lp); 316 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu,int lp) 317 { 318 Init(fof,collabel.c_str(),-1,ihdu,lp); 325 319 } 326 320 … … 331 325 \warning col = [0,ncol[ 332 326 */ 333 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum 334 ,int ihdu,long blen,long bsens,int lp) 335 { 336 Init(fof,"",colnum,ihdu,blen,bsens,lp); 327 FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu,int lp) 328 { 329 Init(fof,"",colnum,ihdu,lp); 337 330 } 338 331 … … 340 333 FitsABTColRd::FitsABTColRd(FitsABTColRd& fbt) 341 334 { 342 Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str() 343 ,fbt.GetColNum(),fbt.HDU() 344 ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel); 335 Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str(),fbt.GetColNum(),fbt.HDU(),fbt.DbgLevel); 345 336 } 346 337 … … 355 346 NFitsRead = 0; 356 347 FitsOF = NULL; 357 LineDeb = LineFin = -1;358 Buffer = NULL;359 348 } 360 349 361 350 /*! Init routine called by the constructor */ 362 void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum 363 ,int ihdu,long blen,long bsens,int lp) 351 void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum,int ihdu,int lp) 364 352 { 365 353 // Initialisation des Parametres Generaux … … 371 359 NFitsRead = 0; 372 360 FitsOF = NULL; 373 LineDeb = LineFin = -1;374 Buffer = NULL;375 361 376 362 // Caracteristiques du FitsOpenFile … … 475 461 fits_get_col_display_width(GetFitsPtr(),ColNum+1,&ColDispWidth,&sta); 476 462 477 // Set the buffer for reading478 ChangeBuffer(blen,bsens);479 480 463 if(DbgLevel) 481 464 cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel … … 497 480 { 498 481 if(StrBuff!=NULL) {delete [] StrBuff; StrBuff=NULL;} 499 if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}500 LineDeb = LineFin = -1;501 482 //--- Surtout on ne "fits_close_file" pas le fichier FITS !!! 502 }503 504 //////////////////////////////////////////////////////////////505 /*! Change the buffer caracteristiques (see creator) */506 void FitsABTColRd::ChangeBuffer(long blen,long bsens)507 {508 long oldnbuffer = NBuffer;509 510 // Compute buffer caracteristics511 BuffLen = (blen<=0 || ColRepeat!=1)? 1: blen;512 BuffSens = bsens;513 NBuffer = BuffLen;514 if(bsens==0 && NBuffer%2==0) NBuffer++;515 516 // De-allocate if necessary517 if(Buffer!=NULL) {518 // On des-alloue si pas assez de place519 // ou si l'ancienne place est beaucoup trop grande (>25%)520 if(oldnbuffer<NBuffer || (oldnbuffer>NBuffer+long(0.25*NBuffer)) )521 {delete [] Buffer; Buffer=NULL;}522 }523 524 // Re-allocate525 if(Buffer==NULL) Buffer = new double[NBuffer];526 527 // Tell program that nothing is into buffer528 LineDeb = LineFin = -1;529 483 } 530 484 … … 576 530 \return value in double 577 531 \param n : number of the row to be read. 578 \verbatim 579 usebuffer == true : use read optimisation with bufferisation 580 == false : no optimisation with bufferisation 581 just read one value 582 \endverbatim 583 */ 584 double FitsABTColRd::Read(LONGLONG n,long nfirstel,bool usebuffer) 532 */ 533 double FitsABTColRd::Read(LONGLONG n,long nfirstel) 585 534 // Attention: n=nline [0,NBline[, cfistio veut [1,NBline] 586 535 // Attention: colnum [0,NBcol[ , cfistio veut [1,NBcol] … … 593 542 throw RangeCheckError("FitsABTColRd::Read try to read outside element range: nfirstel>repeat\n"); 594 543 595 // Pas de bufferisation (ou repeat=1), on lit betement 596 if(NBuffer==1 || !usebuffer || ColRepeat!=1) { 597 NFitsRead++; 598 double val; 599 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta); 600 if(sta) { 601 FitsOpenFile::printerror(sta); 602 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 603 } 604 // On ne remplit Buffer[0] que si on a choisit 605 // un mode de lecture non bufferise (n==1) DES LE DEBUT. 606 // Si on a initialement choisit un mode bufferise (avec n>1), 607 // Buffer contient les valeurs chargees auparavent. 608 // Il ne faut pas faire {Buffer[0]=val; LineDeb=LineFin=n;} 609 // car on perd l'info de ces valeurs. 610 if(NBuffer==1) {Buffer[0]=val; LineDeb=LineFin=n;} 611 return val; 612 } 613 614 // Gestion avec bufferisation (uniquement dans le cas repeat=1) 615 if(!Buffer) 616 throw RangeCheckError("FitsABTColRd::Read: Buffer not allocated\n"); 617 if(n<LineDeb || n>LineFin) { 618 NFitsRead++; 619 LONGLONG row1,row2,nrow; 620 if(BuffSens>0) { // Cas remplissage forward 621 row1 = n+1; 622 row2 = row1+NBuffer-1; if(row2>NBline) row2 = NBline; 623 } else if(BuffSens<0) { // Cas remplissage backward 624 row2 = n+1; 625 row1 = row2-NBuffer+1; if(row1<1) row1 = 1; 626 } else { // Cas remplissage centre 627 row1 = n+1 - NBuffer/2; if(row1<1) row1 = 1; 628 row2 = n+1 + NBuffer/2; if(row2>NBline) row2 = NBline; 629 } 630 nrow = row2 - row1 + 1; 631 LineDeb = row1-1; LineFin = row2-1; 632 //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow 633 // <<" LineDeb,Fin="<<LineDeb<<","<<LineFin<<endl; 634 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer,NULL,&sta); 635 if(sta) { 636 FitsOpenFile::printerror(sta); 637 LineDeb = LineFin = -1; 638 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 639 } 640 } 641 642 long ibuf = n-LineDeb; 643 return Buffer[ibuf]; 544 double val; 545 fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta); 546 if(sta) { 547 FitsOpenFile::printerror(sta); 548 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 549 } 550 NFitsRead++; 551 return val; 552 } 553 554 /*! 555 Read row "n" element "nfirstel" and return a long long int 556 */ 557 int_8 FitsABTColRd::ReadLL(LONGLONG n,long nfirstel) 558 { 559 int sta=0; 560 if(n<0 || n>=NBline) 561 throw RangeCheckError("FitsABTColRd::ReadLL try to read outside line range\n"); 562 if(nfirstel<0 || nfirstel>=ColRepeat) 563 throw RangeCheckError("FitsABTColRd::ReadLL try to read outside element range: nfirstel>repeat\n"); 564 565 int_8 val; 566 fits_read_col(GetFitsPtr(),TLONGLONG,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta); 567 if(sta) { 568 FitsOpenFile::printerror(sta); 569 throw NotAvailableOperation("FitsABTColRd::ReadLL: Error Reading Fits file\n"); 570 } 571 NFitsRead++; 572 return val; 644 573 } 645 574 … … 661 590 throw NotAvailableOperation("FitsABTColRd::ReadComplex: Error Reading Fits file\n"); 662 591 } 592 NFitsRead++; 663 593 return complex<r_8>(val[0],val[1]); 664 594 } … … 678 608 char nullstr[]=""; 679 609 680 NFitsRead++;681 610 fits_read_col(GetFitsPtr(),TSTRING,ColNum+1,n+1,nfirstel+1,1,nullstr,&StrBuff,NULL,&sta); 682 611 if(sta) { … … 684 613 throw NotAvailableOperation("FitsABTColRd::ReadInStr: Error Reading Fits file\n"); 685 614 } 615 NFitsRead++; 686 616 687 617 return StrBuff; … … 741 671 throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n"); 742 672 } 673 NFitsRead += nread; 743 674 744 675 return nread; … … 767 698 throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n"); 768 699 } 700 NFitsRead += nread; 769 701 770 702 return nread; … … 792 724 throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n"); 793 725 } 726 NFitsRead += nread; 794 727 795 728 return nread; … … 819 752 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n"); 820 753 } 754 NFitsRead += nread; 821 755 822 756 return nread; … … 845 779 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n"); 846 780 } 781 NFitsRead += nread; 847 782 848 783 return nread; … … 870 805 LONGLONG row = -1; 871 806 if(NBline==0) return row; 872 // Change buffer for efficiency873 long bsens=BuffSens; bool bchange=false;874 if(bsens<=0) {ChangeBuffer(BuffLen,1); bchange=true;}875 807 if(rowstart<0) rowstart = 0; 876 808 if(rowstart>=NBline) rowstart = NBline-1; … … 881 813 break; 882 814 } 883 if(bchange) ChangeBuffer(BuffLen,bsens);884 815 return row; 885 816 } … … 902 833 LONGLONG row = -1; 903 834 if(NBline==0) return row; 904 // Change buffer for efficiency905 long bsens=BuffSens; bool bchange=false;906 if(bsens>=0) {ChangeBuffer(BuffLen,-1); bchange=true;}907 835 if(rowstart<0 || rowstart>=NBline) rowstart = NBline-1; 908 836 for(LONGLONG i=rowstart;i>=0;i--) { … … 912 840 break; 913 841 } 914 if(bchange) ChangeBuffer(BuffLen,bsens);915 842 return row; 916 843 } … … 919 846 void FitsABTColRd::Print(ostream& os,int lp) const 920 847 { 921 os<<"FitsABTColRd:Print ("<< BuffLen<<","<<BuffSens<<","<<NulVal<<")"848 os<<"FitsABTColRd:Print ("<<NulVal<<")" 922 849 <<" ncols="<<NBcol<<" nrows="<<NBline; 923 850 if(lp>0) os<<" NRead="<<NFitsRead; … … 971 898 \param collabel : label of the column to be read 972 899 \param ihdu : number of the HDU where the column is. 973 \param blen : read buffer length974 \param bsens : buffer reading direction975 900 \param lp : debug level 976 901 \verbatim 977 902 - if ihdu<=0 first BINARY or ASCII table is taken 978 903 - if ihdu>nhdu ihdu is set to nhdu 979 - bsens>0 read forward980 bsens<0 read backward981 bsens==0 read centered982 904 \endverbatim 983 905 \warning ihdu = [1,nhdu] 984 906 */ 985 FitsABTColRead::FitsABTColRead(string fname,string collabel 986 ,int ihdu,long blen,long bsens,int lp) 987 : FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,blen,bsens,lp) 907 FitsABTColRead::FitsABTColRead(string fname,string collabel,int ihdu,int lp) 908 : FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,lp) 988 909 { 989 910 } … … 995 916 \warning col = [0,ncol[ 996 917 */ 997 FitsABTColRead::FitsABTColRead(string fname,int colnum 998 ,int ihdu,long blen,long bsens,int lp) 999 : FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,blen,bsens,lp) 918 FitsABTColRead::FitsABTColRead(string fname,int colnum,int ihdu,int lp) 919 : FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,lp) 1000 920 { 1001 921 } 1002 922 1003 923 /*! Constructor. see below */ 1004 FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel 1005 ,int ihdu,long blen,long bsens,int lp) 1006 : FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,blen,bsens,lp) 924 FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel,int ihdu,int lp) 925 : FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,lp) 1007 926 { 1008 927 } 1009 928 1010 929 /*! Constructor. see below */ 1011 FitsABTColRead::FitsABTColRead(const char * cfname,int colnum 1012 ,int ihdu,long blen,long bsens,int lp) 1013 : FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,blen,bsens,lp) 930 FitsABTColRead::FitsABTColRead(const char * cfname,int colnum,int ihdu,int lp) 931 : FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,lp) 1014 932 { 1015 933 } … … 1026 944 // FitsABTColRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile 1027 945 FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile()); 1028 Init(fof,fbt.GetColLabel().c_str() 1029 ,fbt.GetColNum(),fbt.HDU() 1030 ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel); 946 Init(fof,fbt.GetColLabel().c_str(),fbt.GetColNum(),fbt.HDU(),fbt.DbgLevel); 1031 947 } 1032 948 … … 1239 1155 \return value in double 1240 1156 \param n : number of the row to be read. 1241 \verbatim1242 usebuffer == true : use read optimisation with bufferisation1243 == false : no optimisation with bufferisation1244 just read one value1245 \endverbatim1246 1157 */ 1247 1158 double FitsABTColRd1F::Read(int ColNum,LONGLONG n,long nfirstel) … … 1269 1180 1270 1181 /*! 1182 Read row "n" element "nfirstel" and return a long long int 1183 */ 1184 int_8 FitsABTColRd1F::ReadLL(int ColNum,LONGLONG n,long nfirstel) 1185 { 1186 int sta=0; 1187 if(ColNum<0 || ColNum>=NBcol) 1188 throw RangeCheckError("FitsABTColRd1F::ReadLL try to read outside column range\n"); 1189 if(n<0 || n>=NBline) 1190 throw RangeCheckError("FitsABTColRd1F::ReadLL try to read outside line range\n"); 1191 if(nfirstel<0 || nfirstel>=ColRepeat[ColNum]) 1192 throw RangeCheckError("FitsABTColRd1F::ReadLL try to read outside element range: nfirstel>repeat\n"); 1193 1194 int_8 val; 1195 fits_read_col(GetFitsPtr(),TLONGLONG,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta); 1196 if(sta) { 1197 FitsOpenFile::printerror(sta); 1198 throw NotAvailableOperation("FitsABTColRd1F::ReadLL: Error Reading Fits file\n"); 1199 } 1200 return val; 1201 } 1202 1203 1204 /*! 1271 1205 Read row "n" element "nfirstel" and return a complex value 1272 1206 */ … … 1311 1245 throw NotAvailableOperation("FitsABTColRd::ReadInStr: Error Reading Fits file\n"); 1312 1246 } 1313 1314 1247 return StrBuff[ColNum]; 1315 1248 }
Note:
See TracChangeset
for help on using the changeset viewer.