﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
4210	Modelica.Utilities.Streams.readRealMatrix not working	anonymous	somebody	"The function `Modelica.Utilities.Streams.readRealMatrix` raises an error when used in the example `Modelica.Utilities.Examples.ReadRealMatrixFromFile` from standard Modelica, and fails to build when used in a minimal example.

Error from example in standard Modelica:


> [/build/openmodelica-WGhRBY/openmodelica-1.10.0~dev-710-g833bf4b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo:537:5-537:146:writable] Error: Internal error function createSimCode failed [Transformation from optimised DAE to simulation code structure failed]
> 

Output when used in a minimal example:

{{{
$ omc run_mos.mos
true
true
""""
record SimulationResult
resultFile = """",
simulationOptions = ""startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ReadRealMatrixFromFile', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''"",
messages = ""Failed to build model: ReadRealMatrixFromFile"",
timeFrontend = 0.0,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0
end SimulationResult;
""[/usr/lib/omlibrary/Modelica 3.2.2/Utilities/Streams.mo:210:5-210:61:readonly] Warning: Unused input variable nrow in function .Modelica.Utilities.Streams.readRealMatrix.
[/usr/lib/omlibrary/Modelica 3.2.2/Utilities/Streams.mo:211:5-211:64:readonly] Warning: Unused input variable ncol in function .Modelica.Utilities.Streams.readRealMatrix.
[/tmp/asd/readRealMatrixFromFile_min.mo:6:5-6:116:writable] Warning: Failed to deduce dimensions of A due to unknown dimensions of modifier Modelica.Utilities.Streams.readRealMatrix(file, matrixName, dim[1], dim[2], true)[1].
""

}}}
The first 2 warnings occur because in `Modelica.Utilities.Streams.readRealMatrix` the dimensions inputs (nrow and ncol) are not used in the call to the external function.

{{{#!modelica
function readRealMatrix ""Read Real matrix from MATLAB MAT 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 nrow ""Number of rows of the 2D Real array"";
input Integer ncol ""Number of columns of the 2D Real array"";
input Boolean verboseRead = true
""= true: Print info message; = false: No info message"";
output Real matrix[nrow, ncol] ""2D Real array"";
external ""C"" ModelicaIO_readRealMatrix(fileName, matrixName, matrix, size(matrix, 1), size(matrix, 2), verboseRead)
annotation(...)
annotation(...);
end readRealMatrix;
}}}

The example from standard Modelica was tested from omc and OMEdit. The minimal example was tested only in omc.

Platform and OpenModelica version:
{{{
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty
$ uname -a
Linux <user>-desktop 3.13.0-49-generic #81-Ubuntu SMP Tue Mar 24 19:29:48 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ omc --version
OpenModelica 1.10.0~dev-700-gcaa32ec
}}}''
"	defect	closed	normal	1.19.0	Run-time	v1.10.0-dev-nightly	fixed		
