Dear Colleagues
Working with WSMCreate model has giving me some problems. For instance, could you help me to understand why the Mathematica code rises a syntax error in the following statement?
Thank you for reporting this. The syntax error arises since “if” is a reserved keyword in Modelica, denoting if-statements. Thus you cannot have variables named “if” (or other reserved keywords). The easiest work-around is to use another name for your variable. The code below, where I renamed “if”, “x” should work.
Thank you for reporting this. The syntax error arises since “if” is a reserved keyword in Modelica, denoting if-statements. Thus you cannot have variables named “if” (or other reserved keywords). The easiest work-around is to use another name for your variable. The code below, where I renamed “if”, “x” should work.
No, it is case sensitive so creating a model directly in SystemModeler using “If” as a variable name would be ok, but I would highly advice against it since it is easy to mix up with the reserved keyword. You will not be able to create a variable called “If” from Mathematica since If[] is a built-in function in Mathematica and cannot be used as a symbol. (Well, cannot is a strong word, you could always Unprotect the it and remove the built-in function from the session).
In SystemModeler the “if” will be colored to show that it is a reserved keyword:
The error you got is the same you would have gotten in SystemModeler when trying to validate the model:
[2] 10:28 Syntax errors in model APFModel
APFModel(2): No viable alternative near token: RealOutput
The if-statement should be followed by expression, and it throws an error since it is only followed by a semicolon. You can have if-statements in component declarations, so it is not wholly out of place. See for example Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort.
In the future, we will try and make the error message clearer from Mathematica when you are trying to use a reserved keyword as a component name. Hopefully, this will make it easier to diagnose similar problems!