Calculation Output Record (calcout)

The Calculation Output or "Calcout" record is similar to the Calc record with the added feature of having outputs (an "output link" and an "output event") which are conditionally executed based on the result of the calculation. This feature allows conditional branching to be implemented within an EPICS database (e.g. process Record_A only if Record_B has a value of 0). The Calcout record is also similar to the Wait record (with additional features) but uses EPICS standard INLINK and OUTLINK fields rather than the DBF_STRING fields used in the Wait record. For new databases, it is recommended that the Calcout record be used instead of the Wait record.

Parameter Fields

The fields in this record fall into these categories:

Scan Parameters

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

Read Parameters

The read parameters for the Calcout record consists 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. If they are constants, they will be initialized with the value they are configured with and can be changed via dbPuts. These fields cannot be hardware addresses. In addition, the Calcout record contains the INAV, INBV, ... INLV fields which indicate the status of the link fields, for example, whether or not the specified PV was found and a link to it established. See "Operator Display Parameters" for an explanation of these fields.

See "Address Specification" for information on how to specify database links.

FieldSummaryTypeDCT DefaultReadWriteCA PP
INPAInput AINLINKYes YesYesNo
INPBInput BINLINKYes YesYesNo
INPCInput CINLINKYes YesYesNo
INPDInput DINLINKYes YesYesNo
INPEInput EINLINKYes YesYesNo
INPFInput FINLINKYes YesYesNo
INPGInput GINLINKYes YesYesNo
INPHInput HINLINKYes YesYesNo
INPIInput IINLINKYes YesYesNo
INPJInput JINLINKYes YesYesNo
INPKInput KINLINKYes YesYesNo
INPLInput LINLINKYes YesYesNo

Expression

Like the Calc record, the Calcout record has a CALC field in which the developer can enter an infix expression which the record routine will evaluate when it processes the record. The resulting value is placed in the VAL field. This value can then be used by the OOPT field (see "Output Parameters") to determine whether or not to write to the output link or post an output event. It can also be the value that is written to the output link. The CALC expression is actually converted to opcode and stored 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 changes at run-time, and a special record routine will call a function to convert it to Reverse Polish Notation.

The infix expressions that can be used are very similar to the C expression syntax, but with some additions and subtle differences in operator meaning and precedence. The string may contain a series of expressions separated by a semi-colon character ';' any one of which may actually provide the calculation result; however all of the other expressions included must assign their result to a variable. All alphabetic elements described below are case independent, so upper and lower case letters may be used and mixed in the variable and function names as desired. Spaces may be used anywhere within an expression except between the characters that make up a single expression element.

The range of expressions supported by the calculation record are separated into literals, constants, operands, algebraic operators, trigonometric operators, relational operators, logical operator, the assignment operator, parentheses and commas, and the question mark or '?:' operator.

FieldSummaryTypeDCT DefaultReadWriteCA PP
CALCCalculationSTRING [80]Yes YesYesYes
VALResultDOUBLEYes YesYesNo
RPCLReverse Polish CalcNOACCESSNo NoNoNo

Literals

Constants

Operands

The expression can use 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 simple references by the field letter. For instance, the value obtained from the INPA link is stored in field A, and the values obtained from the INPB link is stored in the field B. The names can be included in the expression will operate on their respective values, as in A+B.

FieldSummaryTypeDCT DefaultReadWriteCA PP
AValue of Input ADOUBLENo YesYesYes
BValue of Input BDOUBLENo YesYesYes
CValue of Input CDOUBLENo YesYesYes
DValue of Input DDOUBLENo YesYesYes
EValue of Input EDOUBLENo YesYesYes
FValue of Input FDOUBLENo YesYesYes
GValue of Input GDOUBLENo YesYesYes
HValue of Input HDOUBLENo YesYesYes
IValue of Input IDOUBLENo YesYesYes
JValue of Input JDOUBLENo YesYesYes
KValue of Input KDOUBLENo YesYesYes
LValue of Input LDOUBLENo YesYesYes

The keyword VAL returns the current contents of the expression's result field, i.e. the VAL field for the CALC expression and the OVAL field for the OCAL expression. (These fields can be written to by CA put, so it might not be the result from the last time the expression was evaluated).

Algebraic Operations

Trigonometric Operators

Relational Operators

Logical Operators

Bitwise Operators

Assignment Operator

Parantheses, Comma, and Semicolon

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

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

The semicolon is used to separate expressions. Although only one traditional calculation expression is allowed, multiple assignment expressions are allowed.

Conditional Expression

The C language's question mark operator is supported. The format is: condition ? True result : False result

Expression Examples

Algebraic

A + B + 10

Relational

(A + B) < (C + D)

Question Mark

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

Prior to Base 3.14.9 it was legal to omit the : and the second (else) part of the conditional, like this:

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

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

From 3.14.9 onwards, this expresion must be written as (A + B) < (C + D) ? E : VAL

Logical

A & B

Assignment

sin(a); a:=a+D2R

Output Parameters

These parameters specify and control the output capabilities of the Calcout record. They determine when to write the output, where to write it, and what the output will be. The OUT link specifies the Process Variable to which the result will be written.

The OOPT field determines the condition that causes the output link to be written to. It's a menu field that has six choices:

IndexIdentifierChoice String
0 calcoutOOPT_Every_Time Every Time
1 calcoutOOPT_On_Change On Change
2 calcoutOOPT_When_Zero When Zero
3 calcoutOOPT_When_Non_zero When Non-zero
4 calcoutOOPT_Transition_To_Zero Transition To Zero
5 calcoutOOPT_Transition_To_Non_zero Transition To Non-zero

The DOPT field determines what data is written to the output link when the output is executed. The field is a menu field with two options:

IndexIdentifierChoice String
0 calcoutDOPT_Use_VAL Use CALC
1 calcoutDOPT_Use_OVAL Use OCAL

If Use CALC is specified, when the record writes its output it will write the result of the expression in the CALC field, that is, it will write the value of the VAL field. If Use OCAL is specified, the record will instead write the result of the expresion in the OCAL field, which is contained in the OVAL field. The OCAL field is exactly like the CALC field and has the same fuctionality it can contain the string representation of an expression which is evaluated at run-time. Thus, if necessary, the record can use the result of the CALC expression to determine if data should be written and can use the result of the OCAL expression as the data to write.

If the OEVT field specifies a non-zero integer and the condition in the OOPT field is met, the record will post a corresponding event. If the ODLY field is non-zero, the record pauses for the specified number of seconds before executing the OUT link or posting the output event. During this waiting period the record is "active" and will not be processed again until the wait is over. The field DLYA is equal to 1 during the delay period. The resolution of the delay entry system dependent.

The IVOA field specifies what action to take with the OUT link if the Calcout record eneters an INVALID alarm status. The options are Continue normally, Don't drive outputs, and Set output to IVOV. If the IVOA field is Set output to IVOV, the data entered into the IVOV field is written to the OUT link if the record alarm severity is INVALID.

FieldSummaryTypeDCT DefaultReadWriteCA PP
OUTOutput SpecificationOUTLINKYes YesYesNo
OOPTOutput Execute OptMENU (calcoutOOPT)Yes YesYesNo
DOPTOutput Data OptMENU (calcoutDOPT)Yes YesYesNo
OCALOutput CalculationSTRING [80]Yes YesYesYes
OVALOutput ValueDOUBLENo YesYesNo
OEVTEvent To IssueSTRING [40]Yes YesYesNo
ODLYOutput Execute DelayDOUBLEYes YesYesNo
IVOAINVALID output actionMENU (menuIvoa)Yes YesYesNo
IVOVINVALID output valueDOUBLEYes YesYesNo

Operator Display Parameter

These parameters are used to present meaningful data to the operator. Some are also meant to represent the status of the record at run-time.

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 on;y refer to the limits if the VAL, HIHI, HIGH, LOW, and LOLO fields. PREC controls the precision of the VAL field.

The INAV-INLV fields indicate the status of the link to the PVs specified in the INPA-INPL fields, respectfully. These field can have four possible values:

IndexIdentifierChoice String
0 calcoutINAV_EXT_NC Ext PV NC
1 calcoutINAV_EXT Ext PV OK
2 calcoutINAV_LOC Local PV
3 calcoutINAV_CON Constant

The OUTV field indicates the status of the OUT link. If has the same possible values as the INAV-INLV fields.

The CLCV and OLCV fields indicate the validity of the expression in the CALC and OCAL fields respectfully. If the expression in invalid, the field is set to one.

The DYLA field is set to one during the delay specified in ODLY.

See "Fields Common to All Record Types" for more information on the record name (NAME) and description (DESC) fields.

FieldSummaryTypeDCT DefaultReadWriteCA PP
EGUEngineering UnitsSTRING [16]Yes YesYesNo
PRECDisplay PrecisionSHORTYes YesYesNo
HOPRHigh Operating RngDOUBLEYes YesYesNo
LOPRLow Operating RangeDOUBLEYes YesYesNo
INAVINPA PV StatusMENU (calcoutINAV)No1YesNoNo
INBVINPB PV StatusMENU (calcoutINAV)No1YesNoNo
INCVINPC PV StatusMENU (calcoutINAV)No1YesNoNo
INDVINPD PV StatusMENU (calcoutINAV)No1YesNoNo
INEVINPE PV StatusMENU (calcoutINAV)No1YesNoNo
INFVINPF PV StatusMENU (calcoutINAV)No1YesNoNo
INGVINPG PV StatusMENU (calcoutINAV)No1YesNoNo
INHVINPH PV StatusMENU (calcoutINAV)No1YesNoNo
INIVINPI PV StatusMENU (calcoutINAV)No1YesNoNo
INJVINPJ PV StatusMENU (calcoutINAV)No1YesNoNo
INKVINPK PV StatusMENU (calcoutINAV)No1YesNoNo
INLVINPL PV StatusMENU (calcoutINAV)No1YesNoNo
OUTVOUT PV StatusMENU (calcoutINAV)No YesNoNo
CLCVCALC ValidLONGNo YesYesNo
OCLVOCAL ValidLONGNo YesYesNo
DLYAOutput Delay ActiveUSHORTNo YesNoNo
NAMERecord NameSTRING [61]No YesNoNo
DESCDescriptorSTRING [41]Yes YesYesNo

Alarm Parameters

The possible alarm conditions for the Calcout 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 parametersi, 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" for a complete explanation of alarms and these fields. Alarm Fields lists other fields related to alarms that are common to all record types.

FieldSummaryTypeDCT DefaultReadWriteCA PP
HIHIHihi Alarm LimitDOUBLEYes YesYesYes
HIGHHigh Alarm LimitDOUBLEYes YesYesYes
LOWLow Alarm LimitDOUBLEYes YesYesYes
LOLOLolo Alarm LimitDOUBLEYes YesYesYes
HHSVHihi SeverityMENU (menuAlarmSevr)Yes YesYesYes
HSVHigh SeverityMENU (menuAlarmSevr)Yes YesYesYes
LSVLow SeverityMENU (menuAlarmSevr)Yes YesYesYes
LLSVLolo SeverityMENU (menuAlarmSevr)Yes YesYesYes
HYSTAlarm DeadbandDOUBLEYes YesYesNo

Monitor Parameters

These parameters are used to determine when to send monitors for the value fields. These 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 aother types of monitors. If these fields have a value of zero, every time the value changes, monitors are triggered; if they have a value of -1, every time the record is scanned, monitors are triggered. See "Monitor Specification" for a complete explanation of monitors.

FieldSummaryTypeDCT DefaultReadWriteCA PP
ADELArchive DeadbandDOUBLEYes YesYesNo
MDELMonitor DeadbandDOUBLEYes YesYesNo

Run-time Parameters

These fields are not configurable using a configuration tool 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 ALST fields are used in the same manner for the VAL field.

FieldSummaryTypeDCT DefaultReadWriteCA PP
LALMLast Value AlarmedDOUBLENo YesNoNo
ALSTLast Value ArchivedDOUBLENo YesNoNo
MLSTLast Val MonitoredDOUBLENo YesNoNo
LAPrev Value of ADOUBLENo YesNoNo
LBPrev Value of BDOUBLENo YesNoNo
LCPrev Value of CDOUBLENo YesNoNo
LDPrev Value of DDOUBLENo YesNoNo
LEPrev Value of EDOUBLENo YesNoNo
LFPrev Value of FDOUBLENo YesNoNo
LGPrev Value of GDOUBLENo YesNoNo
LHPrev Value of HDOUBLENo YesNoNo
LIPrev Value of IDOUBLENo YesNoNo
LJPrev Value of JDOUBLENo YesNoNo
LKPrev Value of KDOUBLENo YesNoNo
LLPrev Value of LDOUBLENo YesNoNo

Record Support

Record Support Routines

init_record

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 and OCAL to Reverse Polish Notation. The result is stored in RPCL and ORPC, respectively.

process

See next section.

special

This is called id CALC or OCAL is changed. special calls postfix.

get_units

Retrieves EGU.

get_precision

Retrieves PREC.

get_graphic_double

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 macimum values for the field type will be used.

get_control_double

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

get_alarm_double

Sets the following values:

Record Processing

process()

The process() routine implements the following algorithm:

1. Fetch all arguments.
2. Call routine calcPerform(), which calculates VAL from the prefix 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. If also honors the alarm hysteresis factor (HYST). Thus the value must change by at least HYST before the alarm status and severity changes.
4. Determin if the Output Execution Option (OOPT) is met. If it met, either execute the output link (and output event) immediately (if ODLY = 0), or schedule a callback after the specified interval. See the explanation for the execOutput() routine below.
5. 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

6. If no output delay was specified, scan forwark link if necessaru, set PACT FALSE, and return.

execOutput()

1. If DOPT field specifies the use of OCAL, call the routine calcPerform() for the postfix version of the expression in OCAL. Otherwise, use VAL.
2. If the Alarm Severity is INVALID, follow the option as designated by the field IVOA.
3. The Alarm Severity is not INVALID or IVOA specifies "Continue Normally", put the value of OVAL to the OUT link and post the event in OEVT (if non-zero).
4. If an output delay was implemented, process the forwark link.