WOLFRAM SYSTEM MODELER

Streams

Read from files and write to files

Package Contents

print

Print string to terminal or file

readFile

Read content of a file and return it in a vector of strings

readLine

Read a line of text from a file and return it in a string

countLines

Return the number of lines in a file

error

Print error message and cancel all actions - in case of an unrecoverable error

close

Close file

readMatrixSize

Read dimensions of a Real matrix from a MATLAB MAT file

readRealMatrix

Read Real matrix from MATLAB MAT file

writeRealMatrix

Write Real matrix to a MATLAB MAT file

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Library content

Package Streams contains functions to input and output strings to a message window or on files, as well as reading matrices from file and writing matrices to file. Note that a string is interpreted and displayed as html text (e.g., with print(..) or error(..)) if it is enclosed with the Modelica html quotation, e.g.,

string = "<html> first line <br> second line </html>".

It is a quality of implementation, whether (a) all tags of html are supported or only a subset, (b) how html tags are interpreted if the output device does not allow to display formatted text.

In the table below an example call to every function is given:

Function/typeDescription
print(string)
print(string,fileName)
Print string "string" or vector of strings to message window or on file "fileName".
stringVector = readFile(fileName) Read complete text file and return it as a vector of strings.
(string, endOfFile) = readLine(fileName, lineNumber) Returns from the file the content of line lineNumber.
lines = countLines(fileName) Returns the number of lines in a file.
error(string) Print error message "string" to message window and cancel all actions
close(fileName) Close file if it is still open. Ignore call if file is already closed or does not exist.
readMatrixSize(fileName, matrixName) Read dimensions of a Real matrix from a MATLAB MAT file.
readRealMatrix(fileName, matrixName, nrow, ncol) Read a Real matrix from a MATLAB MAT file.
writeRealMatrix(fileName, matrixName, matrix, append, format) Write Real matrix to a MATLAB MAT file.

Use functions scanXXX from package Strings to parse a string.

If Real, Integer or Boolean values shall be printed or used in an error message, they have to be first converted to strings with the builtin operator ModelicaReference.Operators.'String()'(...). Example:

  if x < 0 or x > 1 then
     Streams.error("x (= " + String(x) + ") has to be in the range 0 .. 1");
  end if;

Wolfram Language

In[1]:=
SystemModel["Modelica.Utilities.Streams"]
Out[1]:=