Changeset 3184 in Sophya for trunk/SophyaLib/HiStats
- Timestamp:
- Feb 13, 2007, 3:28:00 PM (19 years ago)
- Location:
- trunk/SophyaLib/HiStats
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/hist2err.cc
r3147 r3184 261 261 } 262 262 263 /********* Methode *********/ 264 /*! 265 Write to an ASCII file 266 */ 267 int Histo2DErr::WriteASCII(string fname) 268 { 269 FILE *file = fopen(fname.c_str(),"w"); 270 if(file==NULL) { 271 cout<<"Histo2DErr::WriteASCII_Error: error opening "<<fname<<endl; 272 return -1; 273 } 274 275 if(NBinX()<=0 || NBinY()<=0) { 276 cout<<"Histo2DErr::WriteASCII_Error: wrong number of bins"<<endl; 277 return -2; 278 } 279 280 fprintf(file,"%ld %.17e %.17e %.17e %ld %.17e %.17e %.17e %d\n" 281 ,(long)NBinX(),XMin(),XMax(),WBinX() 282 ,(long)NBinY(),YMin(),YMax(),WBinY() 283 ,NMean()); 284 for(long i=0;i<NBinX();i++) for(long j=0;j<NBinY();j++) { 285 // ligne = i*NY+j 286 fprintf(file,"%d %d %.17e %.17e %.0f\n" 287 ,i,j,(*this)(i,j),Error2(i,j),NEntBin(i,j)); 288 } 289 290 fclose(file); 291 return 0; 292 } 293 294 /*! 295 Read from an ASCII file 296 */ 297 #define __LENLINE_Histo2DErr_ReadASCII__ 2048 298 int Histo2DErr::ReadASCII(string fname) 299 { 300 FILE *file = fopen(fname.c_str(),"r"); 301 if(file==NULL) { 302 cout<<"Histo2DErr::ReadASCII_Error: error opening "<<fname<<endl; 303 return -1; 304 } 305 306 char line[__LENLINE_Histo2DErr_ReadASCII__]; 307 long n=0, nbinx=0, nbiny=0; 308 309 while ( fgets(line,__LENLINE_Histo2DErr_ReadASCII__,file) != NULL ) { 310 311 if(n==0) { 312 313 r_8 xmin,xmax,wx, ymin,ymax,wy; long mnmean=1; 314 sscanf(line,"%d %lf %lf %lf %d %lf %lf %lf %d" 315 ,&nbinx,&xmin,&xmax,&wx 316 ,&nbiny,&ymin,&ymax,&wy 317 ,&mnmean); 318 if(nbinx<=0 || nbiny<=0) { 319 cout<<"Histo2Err::ReadASCII_Error: wrong number of bins"<<endl; 320 return -2; 321 } 322 CreateOrResize(xmin,xmax,nbinx,ymin,ymax,nbiny); 323 SetMean(mnmean); 324 325 } else { 326 327 long i,j; r_8 v,e2,nb; 328 sscanf(line,"%d %d %lf %lf %lf",&i,&j,&v,&e2,&nb); 329 SetBin(i,j,v); 330 SetErr2(i,j,e2); 331 SetNentB(i,j,nb); 332 333 } 334 335 n++; 336 } 337 338 fclose(file); 339 return 0; 340 } 341 263 342 /////////////////////////////////////////////////////////// 264 343 // -------------------------------------------------------- -
trunk/SophyaLib/HiStats/hist2err.h
r3147 r3184 153 153 void Show() const { Show(cout); } 154 154 155 // Write ASCII 156 int WriteASCII(string fname); 157 int ReadASCII(string fname); 158 155 159 protected: 156 160 void CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx,r_8 ymin,r_8 ymax,int_4 ny);
Note:
See TracChangeset
for help on using the changeset viewer.