Variables

Navigation:  Language Reference > Keywords >

Variables

Previous pageReturn to chapter overviewNext page

Variables are symbolic representations of numerical quantities that may change during simulation runs. Variables must be defined in 20-sim, using the variables keyword. After the keyword, lines with variable declarations can be entered. Every line must be finished by a semicolon (;). An example is given below:

 

variables

 real interesting V {volume, m3};                // the volume of barrel 1

 real hidden D {length, m};                        // the length of part 1

 ...

 

Types

20-sim currently supports four types of variables: boolean, integer, real and string. These types must be specified explicitly. The use of the type real is shown in the example above.

Interesting

By adding the keyword interesting after the variable type, a variable will be given special focus in the Variable Chooser. The Variable Chooser shows the complete list of variables of a model and is used to select variables for plotting. The keyword interesting is shown in the variable list, making it easier to find variables of special interest.

Hidden

To prevent users from inspecting variables or decreasing the list of variables, the keyword hidden can be applied. This keyword should follow the data type.

Global

To use the same variable in other submodels, the keyword global can be applied. This keyword should follow the data type.

Variable Names

Variable names can consist of characters and underscores. A variable name must always start with a character. Variable names are case-sensitive. No reserved words may be used for variables. If a reserved word is used, an error message will pop-up while checking the model.

Variable Values

Variables cannot be assigned default values.

Quantity and Unit

If a variable is known to represent a physical value, you can define the corresponding quantity and unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units is optional. In the example above the quantities volume and length are used with the units m3 and m.

Comment

If comment is added at the end of the variable declaration, it is shown in the Variable Chooser to facilitate the selection between variables.

Predefined Variables

20-sim has some predefined variables which have a special meaning.

Example

variables

 real interesting p1,p2,state;

 integer i;

 integer j;

 

variables

 string filename;

 integer interesting i;

 real interesting state;

 boolean t,f;