Keywords and Functions
From SysCAD Documentation
Navigation: PGMs
Contents |
Keywords
The following keywords are recognised by the PGM Language.
All keywords are NOT case sensitive.
Class, EndClass Keywords
Function, StrFunction, Return, EndFunct Keywords
If, ElseIf, Else, EndIf Keywords
Syntax:
If ( expression1 )
statements1
ElseIf ( expression2 )
statements2
ElseIf ( expression3 )
statements3
etc...
Else
statementsN
EndIf
All expressions must resolve into a single Boolean (true or false) result.
statements1 : are executed if expression1 is True, otherwise they are ignored.
statements2 : are executed if expression1 is False and expression2 is True, otherwise they are ignored.
statements3 : are executed if both expression1 and expression2 are False and expression3 is True, otherwise they are ignored.
statementsN : is executed if all preceding expressions are false.
- ElseIf and hence the associated expression2 and statements2 etc - are optional.
- numerous ElseIfs are allowed, before the Else/EndIf.
- else and hence the associated statementsN - are optional.
- If, EndIf keywords (and their associated ElseIf, Else keywords ) can be nested (included within other If-EndIf statements.
See also: IIf function.
Example
If (a > b) c = b ElseIf (a < d) c = -b if (c + b >= 0) a = 2 * b EndIf Else a = d - b EndIf
While, EndWhile Keywords
Syntax:
While (expression)
Statements
EndWhile
expression : must eventually resolve into a single boolean (true or false) result.
statements : will repeatedly be executed while the expression is true (non zero).
If the expression is false, the statements will be ignored.
- A While ... EndWhile block is an excellent way of implementing a loop.
- While instructions can be nested.
- There is no limit to the number of statements inside the While ... EndWhile block.
Example
Long LoopCount* LoopCount = 5 while (LoopCount>0) ; *** do loop logic here *** LoopCount = LoopCount - 1 ; *** or do loop logic here *** EndWhile
Watch Keywords
Watch
Syntax:
Watch variable Watch Class instance Watch Class instance.data Member
The Watch function allows any variable to be displayed in the permanent PGM data watch window. This is equivalent to appending a ' * ' to the end of the variable in the Variable declaration.
Similarly, the Watch function allows any instance of a class to be displayed in the permanent PGM data watch window. This will add all the data members for the class to the permanent PGM data watch window.
The Watch function also allows one to selectively add data members of an instance of a class to the permanent PGM data watch window. The Dot Notation would be used to access the required data member.
Any number of variables, class instances or class data members can be watched using a single watch command if each one is separated by a comma.
Examples: DOUBLE a PID2 b, c WATCH a, b, c.output
ExcludeWatch
Syntax:
ExcludeWatch UserClass[index]
This is used to make variables of a class not visible in the access window.
For Example: ExcludeWatch C[0]
SetConcealed
Same as SetConcealedState.
SetConcealedState
Syntax: SetConcealedState(Variable, bit value)
Variable : a valid variable or class for which the Concealed state must be set.
bit value : this may be either be a single bit value (true or false) or an expression which resolves into a single true or false result.
The SetConcealedState function is used to change the Concealed state of data variables based on the specified bit value. By changing the Concealed state the variables become visible or concealed on the Access window. Concealed variables are still accessible as tags in the flowsheet (for example from Excel, etc). The Variable can be a data variable or a class. If it is a class, all the variables for that class will have the state changed.
Only watched variables that are defined as inputs or outputs can have the state set. It is meaningless to use SetConcealedState on variables that are not declared as input or output to make them visible as tags.
Example: Bit UseSetSplit{i,s} Double RequiredSplit{i,Cnv("Frac","%"),Range(0,100)} if (OnInitialise) SetConcealedState(RequiredSplit, (UseSetSplit==false)) ;Only want variable visible if option is chosen where this is used else if (UseSetSplit) SetTag("X_001.GM.IOs.[P_002].Split (%)", RequiredSplit) endif endif
Using SetConcealedState with Classes:
It is possible to set the concealed state of a variable in a class, for example SetConcealedState(T.d1, true). It is also possible to set the concealed state of a variable in an array of classes as long as the index is specified directly, for example SetConcealedState(T[3].d1, true). But it is not possible to specify the index pragmatically, for example SetConcealedState(T[i].d1, true).
When writing a function within a class definition, it is possible to use SetConcealedState to change the concealed status of variables within the class. This is useful for a class to adjust visible variables as a function of it's parameters. You can set the concealed state of all variables within the class by specifying this as the Variable parameter. For example, SetConcealedState(this, false)
Predefined Functions
GetTag Functions
SetTag Functions
IIf
Syntax: variable = IIf(expression, truePart , falsePart)
expression : must eventually resolve into a single boolean (true or false) result.
truePart : Value or expression.
falsePart : Value or expression.
The IIf function, returns one of two parts depending on the evaluation of an expression. The expression is evaluated, if the expression result is true then truePart is evaluated and returned as the result of the IIf function. If the expression result is false then falsePart is evaluated and returned as the result of the IIf function. Note that only one of the two parts is evaluated.
Example : Double a*,b*,r@ r = iif(b==0, 0, a/b) this is equivalent to ... if (b==0) r = 0 else r = a/b endif
Time Functions
DeltaTime
Syntax: variable = DeltaTime()
The DeltaTime() function returns the current SysCAD value of Delta Time (simulation step size) in seconds.
Time
Syntax: variable = Time()
The Time() function, returns the SysCAD time in seconds.
Conversion (Cnv) Functions
Cnv
Syntax: variable = Cnv(variable1, unit)
The Cnv function converts variable1 to the conversion units specified by unit and returns the result. Conversion information must have been specified for variable1. An expression cannot be used instead of supplying variable1. The unit must be a valid conversion unit belonging to the conversion family for variable1. The conversion units ARE case sensitive.
Example: Double len("L","m")*, d*, r1*, r2* CnvInfo(d, "Qm","kg/s") d = GetTag("P_11.Qm kg/s") r1 = Cnv(len, "ft") r2 = Cnv(d, "t/h")
CnvVal
Syntax: variable = CnvVal(variable1, family, unit, ReqdUnit)
The CnvVal function converts variable1 from the conversion units specified by unit to the conversion units specified by ReqdUnit for the specified conversion family and returns the result. The unit and ReqdUnit must be a valid conversion units belonging to the specified conversion family. The conversion family and conversion units ARE case sensitive.
Example: Double len, d1, d2, r1*, r2* d1 = GetTag("P_11.Qm kg/s") d2 = GetTag("P_12.Qm kg/s") r1 = CnvVal(len, "L", "m", "ft") r2 = CnvVal(d1 + d2, "Qm", "kg/s", "t/h")
CnvInfo
Syntax: CnvInfo(variable, family, unit)
The CnvInfo function allows conversions (engineering units) to be assigned to a variable. Conversion information can only be assigned to double and long variable types. This conversion information can also be supplied when a variable is declared. See Variable declaration. The conversion family and conversion units ARE case sensitive.
The variable is the PGM variable that has already been declared for which you wish to specify conversion information. The family is the name of the conversion family or group. The unit is the conversion (or engineering) unit the variable represents.
This conversion information is especially useful if the variable is watched. When it is accessed in a trend or in an access window, the number is more meaningful because it has an engineering unit and the user can change the conversion unit as required for display purposes. This conversion information is also used by the Cnv function.
Example: Double len*, d*, c3b* Cnvinfo(len,"L", "km") ;family length, unit km CnvInfo(c3b,"Time","h" ) ;family time, unit h CnvInfo(d, M, kg ) ;family mass, unit kg
Random
Syntax: variable = Random(Number)
The Random function, returns a random number between 0 and Number.
Beep
Syntax: Beep(n)
The Beep function sounds the internal speaker n number of times.
User Defined Messages and Errors
LogError
Syntax: LogError(msg)
msg : A string or STR variable.
The LogError function displays the supplied message in the SysCAD message window and logs it to the log file. If the sound is enabled in SysCAD a beep will be sounded.
ConditionError
Syntax: ConditionError(Index, Boolean expression, message)
Index: A number from 0 to 7. That is, only 8 error messages can be reported per PGM/General Controller. Boolean expression: Any logic that evaluates to true/false message: A string or STR variable.
If the Boolean expression is true, then the message specified is displayed in the Condition part of the Message Window. If the sound is enabled in SysCAD a beep will be sounded.
LogNote
Syntax: LogNote(msg)
msg : A string or STR variable.
The LogNote function displays the supplied message in the SysCAD message window and logs it to the log file.
ConditionNote
Syntax: ConditionNote(Index, Boolean expression, message)
Index: A number from 0 to 7. That is, only 8 notes can be reported per PGM/General Controller. Boolean expression: Any logic that evaluates to true/false message : A string or STR variable.
If the Boolean expression is true, then the message specified is displayed in the Condition part of the Message Window. If the sound is enabled in SysCAD a beep will be sounded.
MsgBox
Syntax: MsgBox(msg)
msg: A string or STR variable.
The MsgBox function displays the supplied message in the SysCAD message window and logs it to the log file in exactly the same way as LogNote.
