EPICS Record Reference Manual

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

The Calc record has the standard fields for specifying under what circumstances the record will be processed. These fields are listed in

```
I/O
Intr
```

.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.

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor |
---|---|---|---|---|---|---|---|

INPA | Input Link A | INLINK | Yes | 0 | No | No | N/A |

INPB | Input Link B | INLINK | Yes | 0 | No | No | N/A |

INPC | Input Link C | INLINK | Yes | 0 | No | No | N/A |

INPD | Input Link D | INLINK | Yes | 0 | No | No | N/A |

INPE | Input Link E | INLINK | Yes | 0 | No | No | N/A |

INPF | Input Link F | INLINK | Yes | 0 | No | No | N/A |

INPG | Input Link G | INLINK | Yes | 0 | No | No | N/A |

INPH | Input Link H | INLINK | Yes | 0 | No | No | N/A |

INPI | Input Link I | INLINK | Yes | 0 | No | No | N/A |

INPJ | Input Link J | INLINK | Yes | 0 | No | No | N/A |

INPK | Input Link K | INLINK | Yes | 0 | No | No | N/A |

INPL | Input Link L | INLINK | Yes | 0 | No | No | N/A |

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.

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

CALC | Calculation | DBF_STRING | Yes | 0 | Yes | Yes | Yes | Yes |

RPCL | Reverse Polish | DBF_NOACCESS | No | 0 | No | No | N/A | No |

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

A | Input Value A | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

B | Input Value B | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

C | Input Value C | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

D | Input Value D | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

E | Input Value E | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

F | Input Value F | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

G | Input Value G | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

H | Input Value H | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

I | Input Value I | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

J | Input Value J | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

K | Input Value K | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

L | Input Value L | DOUBLE | No | 0 | Yes | Yes/No | Yes | Yes |

- ABS: Absolute value (unary)
- SQR: Square root (unary)
- MIN: Minimum (binary function)
- MAX: Maximum (binary function)
- CEIL: Ceiling (unary)
- FLOOR: Floor (unary)
- LOG: Log base 10 (unary)
- LOGE: Natural log (unary)
- EXP: Exponential function (unary)
- ^: Exponential (binary)
- ** : Exponential (binary)
- + : Addition (binary)
- - : Subtraction (binary)
- * : Multiplication (binary)
- / : Division (binary)
- % : Modulo (binary)
- NOT: Negate (unary)

- SIN: Sine
- SINH: Hyperbolic sine
- ASIN: Arc sine
- COS: Cosine
- COSH: Hyperbolic cosine
- ACOS: Arc cosine
- TAN: Tangent
- TANH: Hyperbolic tangent
- ATAN: Arc tangent

- >= : Greater than or equal to
- > : Greater than
- <= : Less than or equal to
- <: Less than
- # : Not equal to
- = : Equal to

- && : And
- || : Or
- ! : Not

- | : Bitwise Or
- & : Bitwise And
- OR : Bitwise Or
- AND: Bitwise And
- XOR: Bitwise Exclusive Or
- ~ : One's Complement
- << : Left shift
- >> : Right shift

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

(condition)? True result : False result

A + B + 10

- Result is A + B

(A + B) < (C + D)

- Result is 1 if (A+B) < (C+D)
- Result is 0 if (A+B) >= (C+D)

(A+B)<(C+D)?E:F+L+10

- Result is E if (A+B) < (C+D)
- Result is F+L+10 if (A+B) >= (C+D)

(A+B)<(C+D)?E

- Result is E if (A+B) < (C+D)
- Result is unchanged if (A+B) >= (C+D)

A&B

- Causes the following to occur:
- Convert A to integer
- Convert B to integer
- Bit-wise And A and B
- Convert result to floating point

- Convert A to integer

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.

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

EGU | Engineering Units | STRING [16] | Yes | Null | Yes | Yes | No | No |

PREC | Display Precision | SHORT | Yes | 0 | Yes | Yes | No | No |

HOPR | High Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |

LOPR | Low Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |

NAME | Record Name | STRING [29] | Yes | 0 | Yes | No | No | No |

DESC | Description | STRING [29] | Yes | Null | Yes | Yes | No | No |

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.

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

HIHI | Hihi Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |

HIGH | High Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |

LOW | Low Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |

LOLO | Lolo Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |

HHSV | Severity for a Hihi Alarm | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |

HSV | Severity for a High Alarm | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |

LSV | Severity for a Low Alarm | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |

LLSV | Severity for a Lolo Alarm | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |

HYST | Alarm Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |

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

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

ADEL | Archive Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |

MDEL | Monitor, i.e. value change, Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |

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.

Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|

LALM | Last Alarmed Value | DOUBLE | No | 0 | Yes | No | No | No |

ALST | Archive Last Value | DOUBLE | No | 0 | Yes | No | No | No |

MLST | Monitor Last Value | DOUBLE | No | 0 | Yes | No | No | No |

LA | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LB | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LC | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LD | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LE | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LF | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LG | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LH | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LI | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LJ | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LK | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

LL | Previous Input Value for A | DOUBLE | No | 0 | Yes | No | No | No |

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

upper_alarm_limit = HIHI

upper_warning_limit = HIGH

lower_warning_limit = LOW

lower_alarm_limit = LOLO

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.
- Alarm monitors are invoked if the alarm status or severity has
changed.
- Archive and value change monitors are invoked if ADEL and
MDEL conditions are met.
- Monitors for A-L are checked whenever other monitors are
invoked.
- NSEV and NSTA are reset to 0.

- Alarm monitors are invoked if the alarm status or severity has
changed.
- 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- Algebraic
- Relational
- Question Mark
- Logical
**5.**- Operator Display Parameters**6.**- Alarm Parameters**7.**- Monitor Parameters**8.**- Run-time Parameters**9.**- Record Support Routines- init_record
- process
- special
- get_value
- get_units
- get_precision
- get_graphic_double
- get_control_double
- get_alarm_double
**10.**- Record Processing

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

Generated with Harlequin WebMaker