Changeset a0156d8 in tol
- Timestamp:
- Nov 24, 2008, 12:58:37 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- fb63c68
- Parents:
- 5eda391
- File:
-
- 1 edited
-
tol/btol/matrix_type/matgra.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/btol/matrix_type/matgra.cpp
r5eda391 ra0156d8 355 355 356 356 //-------------------------------------------------------------------- 357 void BBM_BinReadRows(const BText& fileName, BMat& M, int i, int r) 357 void BBM_BinReadRows(const BText& fileName, BMat& M, 358 int i, int r, int t=1) 358 359 //-------------------------------------------------------------------- 359 360 { … … 361 362 BInt fs = GetFileSize(fileName); 362 363 #endif 364 int k, tr = t*r; 363 365 //Std(BText("\nBBM_BinRead ")+fileName+" bytes "+fs); 364 366 FILE* fil = fopen(fileName.String(),"rb"); … … 381 383 if(i==-1) 382 384 { 383 i = m- r;384 } 385 if((0> i)||(i>=m)||386 (0>= r)||(i+r-1>=m) )385 i = m-tr; 386 } 387 if((0> i)||(i >=m)|| 388 (0>=tr)||(i+tr-1>=m) ) 387 389 { 388 390 fclose(fil); … … 399 401 int pos = 2*sizeof(BInt)+(i*n)*sizeof(BDat); 400 402 fseek(fil,pos,SEEK_SET); 401 fread(M.GetData().GetBuffer(), sizeof(BDat), M.Data().Size(), fil); 403 BDat* ptr = M.GetData().GetBuffer(); 404 if(t==1) 405 { 406 fread(ptr, sizeof(BDat), M.Data().Size(), fil); 407 } 408 else 409 { 410 for(k=0; k<r; k++) 411 { 412 if(k>0) 413 { 414 pos = 2*sizeof(BInt)+((i+k*t)*n)*sizeof(BDat); 415 fseek(fil,pos,SEEK_SET); 416 } 417 fread(ptr, sizeof(BDat), n, fil); 418 ptr += n; 419 } 420 } 402 421 } 403 422 if(fclose(fil)) … … 444 463 445 464 //-------------------------------------------------------------------- 465 void BBM_BinReadDimensions(const BText& fileName, 466 int& rows, int& columns) 467 //-------------------------------------------------------------------- 468 { 469 BInt fs = GetFileSize(fileName); 470 //Std(BText("\nBBM_BinRead ")+fileName+" bytes "+fs); 471 FILE* fil = fopen(fileName.String(),"rb"); 472 if(!fil) 473 { 474 Error(I2("Cannot open for read BBM file ", 475 "No se pudo abrir para lectura el fichero BBM ")+ 476 fileName); 477 return; 478 } 479 fread(&rows, sizeof(BInt),1,fil); 480 fread(&columns,sizeof(BInt),1,fil); 481 } 482 483 //-------------------------------------------------------------------- 446 484 DeclareContensClass(BMat, BMatTemporary, BMatWriteFile); 447 485 DefExtOpr(1, BMatWriteFile, "MatWriteFile", 2, 2, "Text Matrix", … … 490 528 491 529 //-------------------------------------------------------------------- 530 DeclareContensClass(BSet, BSetTemporary, BMatReadDimensions); 531 DefExtOpr(1, BMatReadDimensions, "MatReadDimensions", 1, 1, "Text", 532 "(Text filename)", 533 I2("Returns rows and columns of the matrix stored in a file with " 534 "binary format", 535 "Devuelve el número de filas y columnas de la matriz almacenada " 536 "en un fichero con formato binario"), 537 BOperClassify::MatrixAlgebra_); 538 //-------------------------------------------------------------------- 539 void BMatReadDimensions::CalcContens() 540 //-------------------------------------------------------------------- 541 { 542 BText& f = Text(Arg(1)); 543 int rows, cols; 544 BBM_BinReadDimensions(f,rows, cols); 545 BUserDat* r_ = BContensDat::New("",rows,"Number of stored rows"); 546 BUserDat* c_ = BContensDat::New("",cols,"Number of stored columns."); 547 r_->PutName("Rows"); 548 c_->PutName("Columns"); 549 contens_.PrepareStore(2); 550 contens_.AddElement(r_); 551 contens_.AddElement(c_); 552 } 553 //-------------------------------------------------------------------- 492 554 DeclareContensClass(BMat, BMatTemporary, BMatReadRows); 493 DefExtOpr(1, BMatReadRows, "MatReadRows", 3, 3, "Text Real Real", 494 I2("(Text filename, Real firstRow, Real numRows)", 495 "(Text nombreFichero, Real primeraFila, Real numFilas)"), 555 DefExtOpr(1, BMatReadRows, "MatReadRows", 3, 4, "Text Real Real Real", 556 "(Text filename, Real firstRow, Real numRows [, Real thinning=1])", 496 557 I2("Reads a range of rows of a matrix from a file in binary format", 497 558 "Lee un rango de filas de una matriz de un fichero en formato binario"), … … 504 565 int i = (int)Real(Arg(2))-1; 505 566 int r = (int)Real(Arg(3)); 506 BBM_BinReadRows(f,contens_,i,r); 567 int t = 1; 568 if(Arg(4)) { t = (int)Real(Arg(4)); } 569 BBM_BinReadRows(f,contens_,i,r,t); 507 570 } 508 571 //--------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.
