Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a5562cc

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve ModelicaIO support.
- Rename Streams_readMatrixSize => ModelicaIO_readMatrixSizes, since that's the actual name of the external function. - Implemented evaluation of ModelicaIO_readRealMatrix. Belonging to [master]: - #2975
1 parent 9656261 commit a5562cc

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Compiler/NFFrontEnd/NFEvalFunction.mo

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,10 +980,14 @@ algorithm
980980

981981
case ("ModelicaIO_readMatrixSizes", {Expression.STRING(s1), Expression.STRING(s2)})
982982
algorithm
983-
dims := ModelicaExternalC.Streams_readMatrixSize(s1, s2);
983+
dims := ModelicaExternalC.ModelicaIO_readMatrixSizes(s1, s2);
984984
then
985985
Expression.ARRAY(Type.INTEGER(), {Expression.INTEGER(dims[1]), Expression.INTEGER(dims[2])}, true);
986986

987+
case ("ModelicaIO_readRealMatrix",
988+
{Expression.STRING(s1), Expression.STRING(s2), Expression.INTEGER(i), Expression.INTEGER(i2), Expression.BOOLEAN(b)})
989+
then evaluateModelicaIO_readRealMatrix(s1, s2, i, i2, b);
990+
987991
else
988992
algorithm
989993
Error.assertion(false, getInstanceName() + ": failed to evaluate " + name, sourceInfo());
@@ -1025,6 +1029,33 @@ algorithm
10251029
end match;
10261030
end evaluateOpenModelicaRegex;
10271031

1032+
function evaluateModelicaIO_readRealMatrix
1033+
input String fileName;
1034+
input String matrixName;
1035+
input Integer nrow;
1036+
input Integer ncol;
1037+
input Boolean verboseRead;
1038+
output Expression result;
1039+
protected
1040+
Real[nrow, ncol] matrix;
1041+
list<Expression> row, rows = {};
1042+
Type ty;
1043+
algorithm
1044+
matrix := ModelicaExternalC.ModelicaIO_readRealMatrix(fileName, matrixName, nrow, ncol, verboseRead);
1045+
ty := Type.ARRAY(Type.REAL(), {Dimension.fromInteger(ncol)});
1046+
1047+
for r in 1:nrow loop
1048+
row := {};
1049+
for c in 1:ncol loop
1050+
row := Expression.REAL(matrix[r, c]) :: row;
1051+
end for;
1052+
rows := Expression.ARRAY(ty, row, literal = true) :: rows;
1053+
end for;
1054+
1055+
ty := Type.liftArrayLeft(ty, Dimension.fromInteger(nrow));
1056+
result := Expression.ARRAY(ty, rows, literal = true);
1057+
end evaluateModelicaIO_readRealMatrix;
1058+
10281059
function evaluateExternal2
10291060
input String name;
10301061
input Function fn;

Compiler/Util/ModelicaExternalC.mo

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,25 @@ function Strings_advanced_skipWhiteSpace
103103
external "C" nextIndex = ModelicaStrings_skipWhiteSpace(string,startIndex) annotation(Library = "ModelicaExternalC");
104104
end Strings_advanced_skipWhiteSpace;
105105

106-
function Streams_readMatrixSize
106+
function ModelicaIO_readMatrixSizes
107107
input String fileName;
108108
input String matrixName;
109109
output Integer[2] dim;
110110

111111
external "C" ModelicaIO_readMatrixSizes(fileName, matrixName, dim) annotation(Library = {"ModelicaIO", "ModelicaMatIO", "zlib"});
112-
end Streams_readMatrixSize;
112+
end ModelicaIO_readMatrixSizes;
113+
114+
function ModelicaIO_readRealMatrix
115+
input String fileName;
116+
input String matrixName;
117+
input Integer nrow;
118+
input Integer ncol;
119+
input Boolean verboseRead = true;
120+
output Real[nrow, ncol] matrix;
121+
122+
external "C" ModelicaIO_readRealMatrix(fileName, matrixName, matrix, nrow, ncol, verboseRead)
123+
annotation(Library = {"ModelicaIO", "ModelicaMatIO", "zlib"});
124+
end ModelicaIO_readRealMatrix;
113125

114126
annotation(__OpenModelica_Interface="util");
115127
end ModelicaExternalC;

0 commit comments

Comments
 (0)