.Modelica.Utilities.Streams

Information

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;

Contents

NameDescription
 printPrint string to terminal or file
 readFileRead content of a file and return it in a vector of strings
 readLineRead a line of text from a file and return it in a string
 countLinesReturn the number of lines in a file
 errorPrint error message and cancel all actions - in case of an unrecoverable error
 closeClose file
 readMatrixSizeRead dimensions of a Real matrix from a MATLAB MAT file
 readRealMatrixRead Real matrix from MATLAB MAT file
 writeRealMatrixWrite Real matrix to a MATLAB MAT file

Generated at 2024-11-20T19:25:51Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos