NB: This manual refers to a very old version of EPICS, see the EPICS Wiki for updated record reference documentation.

[Next] [Previous] [Top] [Contents] [Index]

EPICS Record Reference Manual

Chapter 9: Calc - Calculation

1. Introduction

The calculation or "Calc" record is used to perform algebraic, relational, and logical operations on values retrieved from other records. The result of its operations can then be accessed by another record so that it can be used. The fields in this record fall into these categories:

scan parameters

read parameters

expression parameters

operator display parameters

alarm parameters

monitor parameters

run-time parameters

2. Scan Parameters

The Calc record has the standard fields for specifying under what circumstances the record will be processed. These fields are listed in Scan Fields, Chapter 2, 2. In addition, Scanning Specification, Chapter 1, 1, explains how these fields are used. Since the Calc record supports no direct interfaces to hardware, it cannot be scanned on I/O interrupt, so its SCAN field cannot be I/O Intr.

3. Read Parameters

The read parameters for the Calc record consist of 12 input links--INPA, INPB, . . . INPL. The fields can be database links, channel access links, or constants. If they are links, they must specify another record's field or a channel access link. If they are constants, they will be initialized with the value they are configured with and can be changed via dbPuts. They cannot be hardware addresses.

See Address Specification, Chapter 1, 2, for information on how to specify database links.
FieldSummaryTypeDCTInitialAccessModifyRec Proc Monitor

4. Expression

At the core of the Calc record lie the CALC and RPCL fields. The CALC field contains the infix expression which the record routine will use when it processes the record. The resulting value is placed in the VAL field and can be accessed from there. The CALC expression is actually converted to opcode and stored as in Reverse Polish Notation in the RPCL field. It is this expression which is actually used to calculate VAL. The Reverse Polish expression is evaluated more efficiently during run-time than an infix expression. CALC can be changed at run-time, and a special record routine calls a function to convert it to Reverse Polish Notation.

The range of expressions supported by the calculation record are separated into operands, algebraic operators, trigonometric operators, relational operators, logical operators, parentheses and commas, and the question mark or '?:' operator. The expression can consist of any of these operators, as well as any of the values from the input links which are the operands.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP

4.1. Operands

The expression uses the values retrieved from the INPx links as operands, though constants can be used as operands too. These values retrieved from the input links are stored in the A-L fields. The values to be used in the expression are simply referenced by the field letter. For instance, the value obtained from the INPA link is stored in the field A, and the value obtained from INPB is stored in field B. The field names can be included in the expression which will operate on their respective values, as in A+B. Also, the RNDM unary function can be included as an operand in the expression in order to generate a random number between 0 and 1.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
AInput Value ADOUBLENo0YesYes/NoYesYes
BInput Value BDOUBLENo0YesYes/NoYesYes
CInput Value CDOUBLENo0YesYes/NoYesYes
DInput Value DDOUBLENo0YesYes/NoYesYes
EInput Value EDOUBLENo0YesYes/NoYesYes
FInput Value FDOUBLENo0YesYes/NoYesYes
GInput Value GDOUBLENo0YesYes/NoYesYes
HInput Value HDOUBLENo0YesYes/NoYesYes
IInput Value IDOUBLENo0YesYes/NoYesYes
JInput Value JDOUBLENo0YesYes/NoYesYes
KInput Value KDOUBLENo0YesYes/NoYesYes
LInput Value LDOUBLENo0YesYes/NoYesYes

4.2. Algebraic Operators

4.3. Trigonometric Operators

4.4. Relational Operators

4.5. Logical Operators

4.6. Bitwise Operators

4.7. Parentheses and Comma

The open and close parentheses are supported. Nested parenthesis are supported.

The comma is supported when used to separate the arguments of a binary function.

4.8. Conditional Expression

The C language's question mark operator is supported. The format is:

 (condition)? True result : False result

4.9. Examples


A + B + 10


(A + B) < (C + D)

Question Mark





5. Operator Display Parameters

These parameters are used to present meaningful data to the operator. These fields are used to display VAL and the other parameters of the calculation record either textually or graphically.

The EGU field contains a string of up to 16 characters which is supplied by the user and which describes the values being operated upon. The string is retrieved whenever the routine get_units is called. The EGU string is solely for an operator's sake and does not have to be used.

The HOPR and LOPR fields only refer to the limits of the VAL, HIHI, HIGH, LOW, and LOLO fields. PREC controls the precision of the VAL field.

See Chapter 2, Fields Common to All Record Types, for more on the record name (NAME) and description (DESC) fields.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
EGUEngineering UnitsSTRING [16]YesNullYesYesNoNo
PRECDisplay PrecisionSHORTYes0YesYesNoNo
HOPRHigh Operating RangeFLOATYes0YesYesNoNo
LOPRLow Operating RangeFLOATYes0YesYesNoNo
NAMERecord NameSTRING [29]Yes0YesNoNoNo
DESCDescriptionSTRING [29]YesNullYesYesNoNo

6. Alarm Parameters

The possible alarm conditions for the Calc record are the SCAN, READ, Calculation, and limit alarms. The SCAN and READ alarms are called by the record support routines. The Calculation alarm is called by the record processing routine when the CALC expression is an invalid one, upon which an error message is generated.

The following alarm parameters which are configured by the user define the limit alarms for the VAL field and the severity corresponding to those conditions.

The HYST field defines an alarm deadband for each limit. See Alarm Specification, Chapter 1, 4, for a complete explanation of alarms and these fields. Alarm Fields, Chapter 2, 3, lists other fields related to a alarms that are common to all record types.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
HIHIHihi Alarm LimitFLOATYes0YesYesNoYes
HIGHHigh Alarm LimitFLOATYes0YesYesNoYes
LOWLow Alarm LimitFLOATYes0YesYesNoYes
LOLOLolo Alarm LimitFLOATYes0YesYesNoYes
HHSVSeverity for a Hihi AlarmGBLCHOICEYes0YesYesNoYes
HSVSeverity for a High AlarmGBLCHOICEYes0YesYesNoYes
LSVSeverity for a Low AlarmGBLCHOICEYes0YesYesNoYes
LLSVSeverity for a Lolo AlarmGBLCHOICEYes0YesYesNoYes
HYSTAlarm DeadbandDOUBLEYes0YesYesNoNo

7. Monitor Parameters

These parameters are used to determine when to send monitors for the value fields. The monitors are sent when the value field exceeds the last monitored field by the appropriate deadband, the ADEL for archiver monitors and the MDEL field for all other types of monitors. If these fields have a value of zero, everytime the value changes, monitors are triggered; if they have a value of -1, everytime the record is scanned, monitors are triggered. See Monitor Specification, Chapter 1, 5, for a complete explanation of monitors.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
ADELArchive DeadbandDOUBLEYes0YesYesNoNo
MDELMonitor, i.e. value change, DeadbandDOUBLEYes0YesYesNoNo

8. Run-time Parameters

These fields are not configurable using a configuration too and none are modifiable at run-time. They are used to process the record.

The LALM field is used to implement the hysteresis factor for the alarm limits.

The LA-LL fields are used to decide when to trigger monitors for the corresponding fields. For instance, if LA does not equal the value for A, monitors for A are triggered. The MLST and MLST fields are used in the same manner for the VAL field.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
LALMLast Alarmed ValueDOUBLENo0YesNoNoNo
ALSTArchive Last ValueDOUBLENo0YesNoNoNo
MLSTMonitor Last ValueDOUBLENo0YesNoNoNo
LAPrevious Input Value for ADOUBLENo0YesNoNoNo
LBPrevious Input Value for ADOUBLENo0YesNoNoNo
LCPrevious Input Value for ADOUBLENo0YesNoNoNo
LDPrevious Input Value for ADOUBLENo0YesNoNoNo
LEPrevious Input Value for ADOUBLENo0YesNoNoNo
LFPrevious Input Value for ADOUBLENo0YesNoNoNo
LGPrevious Input Value for ADOUBLENo0YesNoNoNo
LHPrevious Input Value for ADOUBLENo0YesNoNoNo
LIPrevious Input Value for ADOUBLENo0YesNoNoNo
LJPrevious Input Value for ADOUBLENo0YesNoNoNo
LKPrevious Input Value for ADOUBLENo0YesNoNoNo
LLPrevious Input Value for ADOUBLENo0YesNoNoNo

9. Record Support Routines


For each constant input link, the corresponding value field is initialized with the constant value if the input link is CONSTANT or a channel access link is created if the input link is PV_LINK.

A routine postfix is called to convert the infix expression in CALC to reverse polish notation. The result is stored in RPCL.


See next section.


This is called if CALC is changed. special calls postfix.


Fills in the values of struct valueDes so that they refer to VAL.


Retrieves EGU.


Retrieves PREC.


Sets the upper display and lower display limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.


Sets the upper control and the lower control limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.


Sets the following values:

upper_alarm_limit = HIHI

upper_warning_limit = HIGH

lower_warning_limit = LOW

lower_alarm_limit = LOLO

10. Record Processing

Routine process implements the following algorithm:

1. Fetch all arguments.

2. Call routine calcPerform, which calculates VAL from the postfix version of the expression given in CALC. If calcPerform returns success UDF is set to FALSE.

3. Check alarms. This routine checks to see if the new VAL causes the alarm status and severity to change. If so, NSEV, NSTA and LALM are set. It also honors the alarm hysteresis factor (HYST). Thus the value must change by at least HYST before the alarm status and severity changes.

4. Check to see if monitors should be invoked.

5. Scan forward link if necessary, set PACT FALSE, and return.

1. - Introduction
2. - Scan Parameters
3. - Read Parameters
4. - Expression
4.1. - Operands
4.2. - Algebraic Operators
4.3. - Trigonometric Operators
4.4. - Relational Operators
4.5. - Logical Operators
4.6. - Bitwise Operators
4.7. - Parentheses and Comma
4.8. - Conditional Expression
4.9. - Examples
Question Mark
5. - Operator Display Parameters
6. - Alarm Parameters
7. - Monitor Parameters
8. - Run-time Parameters
9. - Record Support Routines
10. - Record Processing

EPICS Record Reference Manual - 19 MAY 1998
[Next] [Previous] [Top] [Contents] [Index]

Generated with Harlequin WebMaker