Real Time eXecutives, Inc.
RTX Client applications (Trend Link, Hdbdde, Bldwks, ODBC, Excel Add-in) are now able to reference calculated variables using pre-defined expressions. We call a calculated variable a variable that is derived from other variables using an expression. Calculated variables have names and appear in variable lists just as other historical variables. The expression syntax is the same as that currently available to the client applications, including external functions made available through a DLL library, such as that provided by the General Physics Steam Tables.
There are two ways to define calculated variables, both of which can be used:
The first approach has the advantage of being easy to implement. It has the disadvantage that it does not integrate the calculated variables into the client applications as thoroughly as the second technique. That is, the variables do not have units, spans, etc.; the expression becomes the variable description, which can be unwieldy; and the variables appear in every variable list, regardless of name, description, or subset filtering. The advantage of the second technique is that it completely integrates the calculated variables into the client applications. That is, they will have user-assigned descriptions, units, etc.; are subject to the same filtering by tag name, description, and subset; and will only appear in databases which reference the index files containing the calculated variables.
Whether approach 1 or approach 2 is used, the files containing definitions of calculated variables use the following syntax:
The following example serves to illustrate the syntax:
The maximum number of variables that can be referenced in any one expression is 100, unless overridden by the configuration statement
- Maximum Number of Expression Variables = n
Expressions are compiled at run time and have a maximum compiled size of 256 unless explicitly overridden by the configuration statement
- Maximum Expression Depth = n
Expression compilation involves token parsing, and the maximum token size is 256 characters, unless overridden by the configuration statement
- Maximum Token Size = n
The scope of variables used in an expression is limited to the expression itself. That is, two expressions referencing the same variable will each evaluate that variable independently. A slight performance gain may be achieved by expanding the scope of expressions to encompass all currently open variables. Care should be taken when doing this, as functions such as LEAD and LAG can have side effects. Use the following configuration statement:
- Expand Expression Scope = YES
Unless otherwise specified, expression files are located in the client applications working directory. To change the default directory, use the configuration statement
- Expression File Directory = dir
The default expression file, when using technique 1 described above, is EXPRESS.TXT. Use the following configuration statement to change the file name:
- Default Expression File = filename
Specification of constants used in expressions is contained in the default constant file CONSTANT.TXT in the client applications working directory. To change the file name and the directory name, use the following configuration statements:
- Constant File = filename
- Constant File Directory = dir
Create a calculated variable definition file called EXPRESS.TXT (or use the name specified by the configuration statement DEFAULT EXPRESSION FILE) in the programs working directory (or in the directory specified by the EXPRESSION FILE DIRECTORY configuration statement), and add the calculated variables to it, as shown in the example above. The variable names contained in the file will appear in client application variable lists.
Create a calculated variable definition text file. For purposes of demonstration, well call it EFFICIENCY.TXT. Add the appropriate variable calculations to the file, as shown in the example above.
Create a calculated variable specification file containing names, descriptions, engineering units, etc. The following example serves to illustrate this file (EFFLIST.TXT):
|FLOWSUM||Sum of Flows||GPM||0||1000|
|PRESSUM||Sum of Pressures||PSI||0||100|
|TEST1||Test of Expressions||%||0||100|
Add the following section to the SUBSET.INI file:
In the RTX.INI file add the following configuration statement:
Run AUTO_ADD32 to add the calculated variables to the Index Files for the specified database:
Note that the new subset will be automatically added to propagated databases (to the HISTATUS.DAT file, not to the Index Files) when HDBPROP32 runs.
Use HDBVIEW32 to examine the newly added subset. It will show the new subset in the database. Select a database, click DB Info and Subsets to see the list of database subsets. Select the new subset and double-click the left mouse button to see a display of subset properties. Make sure that the Expression flag is set.
In the HDBVIEW Main Dialog box pull down the list of subsets and select the new subset. Pull down the list of variables and observe the list of new calculated variables. Select one and click the PV Info button and verify that the information is correct for the variable. Click the Detail button to see detailed information about the calculated variable. Click the Data button to see the calculated values.
If everything looks ok, the new calculated variables should be available to all client application programs. Make sure that the programs are using the same RTX.INI configuration file, or modify their files appropriately. Make sure the expression definition files are in a directory that can be seen by every user.