Last active
January 13, 2016 17:13
-
-
Save tbeu/ec0e7760dabe9bcee17a to your computer and use it in GitHub Desktop.
New functions for Modelica.Utilities.Streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
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"; | |
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, 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment