Skip to content

Instantly share code, notes, and snippets.

@tbeu
Last active January 13, 2016 17:13

Revisions

  1. tbeu revised this gist Jan 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Streams.mo
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,6 @@
    input Boolean append = false "Append values to file";
    input String vs = "4" "MATLAB MAT-file version: \"4\" -> v4, \"6\" -> v6, \"7\" -> v7, \"7.3\" -> v7.3";
    output Boolean status "true if successful";
    external "C" status=ModelicaIO_writeRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), append, Version) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    external "C" status=ModelicaIO_writeRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), append, vs) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Save a 2D Real array in a MATLAB MAT-file.</p></html>"));
    end writeRealMatrix;
  2. tbeu revised this gist Jan 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Streams.mo
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@
    input String matrixName "Name / identifier of the 2D Real array on the file";
    input Real matrix[:,:] "2D Real array";
    input Boolean append = false "Append values to file";
    input String vs = 4 "MATLAB MAT-file version: \"4\" -> v4, \"6\" -> v6, \"7\" -> v7, \"7.3\" -> v7.3";
    input String vs = "4" "MATLAB MAT-file version: \"4\" -> v4, \"6\" -> v6, \"7\" -> v7, \"7.3\" -> v7.3";
    output Boolean status "true if successful";
    external "C" status=ModelicaIO_writeRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), append, Version) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Save a 2D Real array in a MATLAB MAT-file.</p></html>"));
  3. tbeu revised this gist Jan 13, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Streams.mo
    Original file line number Diff line number Diff line change
    @@ -11,9 +11,8 @@
    extends Modelica.Icons.Function;
    input String fileName "File where external data is stored" annotation(Dialog(loadSelector(filter="MATLAB MAT-files (*.mat)", caption="Open MATLAB MAT-file")));
    input String matrixName "Name / identifier of the 2D Real array on the file";
    input Integer dim[2] = readMatrixSize(fileName, matrixName) "Number of rows and columns of the 2D Real array";
    output Real matrix[dim[1], dim[2]] "2D Real array";
    protected
    constant Integer dim[2] = readMatrixSize(fileName, matrixName) "Number of rows and columns of the 2D Real array";
    external "C" ModelicaIO_readRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2)) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Read a 2D Real array from a binary MATLAB MAT-file.</p></html>"));
    end readRealMatrix;
  4. tbeu created this gist Jan 13, 2016.
    31 changes: 31 additions & 0 deletions Streams.mo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    function readMatrixSize "Read dimensions of a 2D Real array from file"
    extends Modelica.Icons.Function;
    input String fileName "File where external data is stored" annotation(Dialog(loadSelector(filter="MATLAB MAT-files (*.mat)", caption="Open MATLAB MAT-file")));
    input String matrixName "Name / identifier of the 2D Real array on the file";
    output Integer dim[2] "Number of rows and columns of the 2D Real array";
    external "C" ModelicaIO_readMatrixSizes(fileName, matrixName, dim) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Read the 2D dimensions from a binary MATLAB MAT-file.</p></html>"));
    end readMatrixSize;

    function readRealMatrix "Read 2D Real values from file"
    extends Modelica.Icons.Function;
    input String fileName "File where external data is stored" annotation(Dialog(loadSelector(filter="MATLAB MAT-files (*.mat)", caption="Open MATLAB MAT-file")));
    input String matrixName "Name / identifier of the 2D Real array on the file";
    output Real matrix[dim[1], dim[2]] "2D Real array";
    protected
    constant Integer dim[2] = readMatrixSize(fileName, matrixName) "Number of rows and columns of the 2D Real array";
    external "C" ModelicaIO_readRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2)) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Read a 2D Real array from a binary MATLAB MAT-file.</p></html>"));
    end readRealMatrix;

    function writeRealMatrix "Write 2D Real values to file"
    extends Modelica.Icons.Function;
    input String fileName "File where external data is to be stored" annotation(Dialog(saveSelector(filter="MATLAB MAT-files (*.mat)", caption="Save MATLAB MAT-file")));
    input String matrixName "Name / identifier of the 2D Real array on the file";
    input Real matrix[:,:] "2D Real array";
    input Boolean append = false "Append values to file";
    input String vs = 4 "MATLAB MAT-file version: \"4\" -> v4, \"6\" -> v6, \"7\" -> v7, \"7.3\" -> v7.3";
    output Boolean status "true if successful";
    external "C" status=ModelicaIO_writeRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), append, Version) annotation(Library={"ModelicaIO", "ModelicaMatIO", "zlib"});
    annotation(Documentation(info="<html><p>Save a 2D Real array in a MATLAB MAT-file.</p></html>"));
    end writeRealMatrix;