Changeset e69e5c6 in tol


Ignore:
Timestamp:
Jun 21, 2009, 5:12:39 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
cd6c317
Parents:
5390012
Message:

New argument to select format in MatReadFile

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

File:
1 edited

Legend:

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

    r5390012 re69e5c6  
    520520//--------------------------------------------------------------------
    521521DeclareContensClass(BMat, BMatTemporary, BMatReadFile);
    522 DefExtOpr(1, BMatReadFile, "MatReadFile", 1, 1, "Text",
    523   I2("(Text filename)",
    524      "(Text nombreFichero)"),
    525   I2("Reads a matrix from a file in binary format",
    526      "Lee una matriz de un fichero en formato binario"),
     522DefExtOpr(1, BMatReadFile, "MatReadFile", 1, 2, "Text Text",
     523  "(Text filename [, Text format=\"BINARY\"])",
     524  I2("Reads a matrix from a file in the specified format",
     525     "Lee una matriz de un fichero en el formato especificado")+":\n"+
     526     "BINARY: "+
     527     I2("Standard TOL binary format",
     528        "Formato estándar binario de TOL")+
     529     "WGRIB2TXT: "+
     530     I2("Result of command", "Resultado del comando")+
     531     " wgrib2 ... -text file\n"+
     532     " rows cols\n"+
     533     " datum[1,1]\n" +
     534     " datum[1,2]\n" +
     535     " ...\n" +
     536     " datum[rows,cols]\n"+
     537     I2("View more on ", "Ver más en ")+
     538     "http://www.cpc.noaa.gov/products/wesley/wgrib2/",
    527539    BOperClassify::MatrixAlgebra_);
    528540//--------------------------------------------------------------------
    … …  
    530542//--------------------------------------------------------------------
    531543{
    532   BBM_BinRead(Text(Arg(1)),contens_);
    533 }
     544  BText fileName = Text(Arg(1));
     545  BText format = "BINARY";
     546  if(Arg(2)) { format = Text(Arg(2)); }
     547  if(format=="BINARY")
     548  {
     549    BBM_BinRead(fileName,contens_);
     550  }
     551  else if(format=="WGRIB2TXT")
     552  {
     553    FILE* file = fopen(fileName.String(),"r");
     554    int i, j, rows, cols;
     555    fscanf(file, "%ld %ld", &rows, &cols);
     556    contens_.Alloc(rows, cols);
     557    double* x = (double*)contens_.GetData().GetBuffer();
     558    for(i=0; !feof(file) && (i<rows); i++)
     559    {
     560      for(j=0; j<cols; j++, x++)
     561      {
     562        fscanf(file, "%lf",x);
     563      }
     564    }
     565  }
     566}
     567
    534568
    535569//--------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.