functionreadRealParameter
Read the value of a Real parameter from file
Extends from Modelica.Icons.Function (Icon for functions).
Information
Syntax
result = readRealParameter(fileName, name);
Description
This function demonstrates how a function can be implemented that reads the value of a parameter from file. The function performs the following actions:
- It opens file "fileName" and reads the lines of the file.
- In every line, Modelica line comments ("// ... end-of-line") are skipped
- If a line consists of "name = expression" and the "name" in this line is identical to the second argument "name" of the function call, the expression calculator Examples.expression is used to evaluate the expression after the "=" character. The expression can optionally be terminated with a ";".
- The result of the expression evaluation is returned as the value of the parameter "name".
Example
On file "test.txt" the following lines might be present:
// Motor data J = 2.3 // inertia w_rel0 = 1.5*2; // relative angular velocity phi_rel0 = pi/3
The function returns the value "3.0" when called as:
readRealParameter("test.txt", "w_rel0")
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| String | fileName | Name of file | |
| String | name | Name of parameter | |
| Boolean | useDefaultValue | false | If true, then the default value is returned if parameter not found in file, else an error is printed |
| Real | defaultValue | 0 | Return value if parameter not found in file |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real | result | Actual value of parameter on file |