Technical Tips

Real Time eXecutives, Inc.

Technical Tips


Using Calculated Variables in Client Applications

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:

  1. Define the variables in a calculated variable definition file called ‘EXPRESS.TXT
  2. Define one or more database subsets (sometimes called ‘sources’) as EXPRESSION type; Add calculated variables to the Index Files with names, descriptions, units, etc.; Create a calculated variable definition file (same syntax as the EXPRESS.TXT file); and add a configuration statement to the RTX.INI file connecting the file name to the subset name.

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.

Setting up a Calculated Variable Definition File

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:

FLOWSUM = FLOW1+FLOW2+FLOW3
PRESSUM = PRESS1+PRESS2+PRESS3
TEST1 = FLOW1+FLOW2+FLOW3
TEST2 = SQRT(PRESS1+PRESS2+PRESS3)
TEST3 = TEMP1+TEMP2+TEMP3+TEMP4
TEST4 = FLOW1+FLOW2+FLOW3)/SQRT(PRESS1+PRESS2+PRESS3) +\
TEMP1+TEMP2+TEMP3+TEMP4
TEST5 = FLOWSUM/SQRT(PRESSUM)+TEMP1+TEMP2+TEMP3+TEMP4
ARTEST1 = (AR1112 * AR1212 / AR1312) + \
SQRT (AVG (AR1412, AR1506, ARC2112, ARC2212)) /  SQRT (ARC612 * ARC712^2)
ARTEST2 = ARTEST1
FRTEST1 = AVG (FR0009, FR0012, FR0029, FR0030, FR0034, FR0040, FR0043, FR0100, FR0101, FR0170)
FRTEST2 = FRTEST1 / STD (FR0009, FR0012, FR0029, FR0030, FR0034,\
FR0040, FR0043, FR0100, FR0101, FR0170)
FRTEST3 = CLAMP (FR0100, P_AVG (FR0100) - P_STD (FR0100), P_AVG (FR0100) + P_STD (FR0100))
FRTEST4 = CLIP (FR0100, P_AVG (FR0100) - P_STD (FR0100), P_AVG (FR0100) +\
P_STD (FR0100))

Configuration Parameters

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 application’s 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 application’s working directory.  To change the file name and the directory name, use the following configuration statements:

Constant File = filename
Constant File Directory = dir

Technique 1: Using EXPRESS.TXT

Create a calculated variable definition file called EXPRESS.TXT (or use the name specified by the configuration statement DEFAULT EXPRESSION FILE) in the program’s 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.

Technique 2: Using Expression Subsets

Create a calculated variable definition text file.  For purposes of demonstration, we’ll 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
etc        

Add the following section to the SUBSET.INI file:

[EFFICIENCY]
Database = database name
Subset = Efficiency
Subset Type = Expression
 

In the RTX.INI file add the following configuration statement:

[RTX]
EXPRESSION1 = Efficiency (EFFLIST.TXT)

Run AUTO_ADD32 to add the calculated variables to the Index Files for the specified database:

AUTO_ADD32 /C=SUBSET /S=EFFICIENCY

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.


RTX Home Page Back Home
Real Time eXecutives, Inc. 1996 - 2007
Page constructed by
RTX Web Services