Changeset a0156d8 in tol


Ignore:
Timestamp:
Nov 24, 2008, 12:58:37 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
fb63c68
Parents:
5eda391
Message:

New thinnig parameter for BinReadRows
New built-in function MatReadDimensions

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@215 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    r5eda391 ra0156d8  
    355355
    356356//--------------------------------------------------------------------
    357 void BBM_BinReadRows(const BText& fileName, BMat& M, int i, int r)
     357void BBM_BinReadRows(const BText& fileName, BMat& M,
     358                     int i, int r, int t=1)
    358359//--------------------------------------------------------------------
    359360{
    … …  
    361362  BInt fs = GetFileSize(fileName);
    362363#endif
     364  int k, tr = t*r;
    363365//Std(BText("\nBBM_BinRead ")+fileName+" bytes "+fs);
    364366  FILE* fil = fopen(fileName.String(),"rb");
    … …  
    381383  if(i==-1)
    382384  {
    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) )
    387389  {
    388390    fclose(fil);
    … …  
    399401    int pos = 2*sizeof(BInt)+(i*n)*sizeof(BDat);
    400402    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    }
    402421  }
    403422  if(fclose(fil))
    … …  
    444463
    445464//--------------------------------------------------------------------
     465void 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//--------------------------------------------------------------------
    446484DeclareContensClass(BMat, BMatTemporary, BMatWriteFile);
    447485DefExtOpr(1, BMatWriteFile, "MatWriteFile", 2, 2, "Text Matrix",
    … …  
    490528
    491529//--------------------------------------------------------------------
     530DeclareContensClass(BSet, BSetTemporary, BMatReadDimensions);
     531DefExtOpr(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//--------------------------------------------------------------------
     539void 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//--------------------------------------------------------------------
    492554DeclareContensClass(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)"),
     555DefExtOpr(1, BMatReadRows, "MatReadRows", 3, 4, "Text Real Real Real",
     556  "(Text filename, Real firstRow, Real numRows [, Real thinning=1])",
    496557  I2("Reads a range of rows of a matrix from a file in binary format",
    497558     "Lee un rango de filas de una matriz de un fichero en formato binario"),
    … …  
    504565  int    i = (int)Real(Arg(2))-1;
    505566  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);
    507570}
    508571//--------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.