Devices > Remote Devices > Device Template Files > Reference Methods > Arithmetic Examples

Arithmetic Examples

This topic provides numerous useful examples of the various ways you can use reference methods in your device template files to perform conversions with constant values and/or reference data group element values. A sample device template file using each example is available upon request; it can be loaded to a DDS and used to test your reference methods. It is called ReferenceTester.dtf.

See the following subsections for details:

For information about example data group elements and values used below, see Example Values.

Addition (A)

The following example uses two child elements to add two values. The first child element references the operation opAssignId and the value of the data group element raw10 to assign the current value of 10 as the initial value for AddConst. The second child element references the operation opAdd to add the constant value "5" to the value assigned by the first child element. The result is 15.

<AddConst desc="Add Constant Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw10"/>

<ref prec="1" refOp="opAdd" value="5"/>

</AddConst>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Addition (B)

The following example uses two child elements to add two values. The first child element references the operation opAssign and the constant value "10" to assign the current value of 10 as the initial value for AddId. The second child element references the operation opAddId to add the value of the referenced data group element raw5 to the value assigned by the first child element. The result is 15.

<AddId desc="Add DEID Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssign" value="10"/>

<ref prec="1" refOp="opAddId" deid="raw5"/>

</AddId>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Average Value (A)

The following example uses specialized child elements to select an average value from a set of defined values. The first child element references the operation opAverage to specify that its children are part of a data set from which the average value is required. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the average value from the data set is 55.

<AverageVal desc="Average value of dataset" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAverage">

<dataSet>

<item value="50"/>

<item value="60"/>

<item deid="raw10"/>

<item deid="raw100"/>

</dataSet>

</ref>

</AverageVal>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Average Value (B)

The following example uses specialized child elements to select an average value from a set of defined values where some of the values are outside the data set, but within the parent data group element. The first child element references the operation opAssignId to assign a starting value that will be compared to values in the data set. The second child element references the operation opScaleFactorId to apply a scale factor of 2 to the value 1. The result is 2. A third child element references the operation opAverage to specify that an average value is to be returned. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the value 2 is used along with the values in the data set to determine an average; the average value is assigned to the parent data group element. In this case, the average value from the data set is 29.25.

<AveValDEID desc="Average value of data group element" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw1"/>

<ref prec="1" refOp="opScaleFactorId" deid="raw2"/>

<ref prec="2" refOp="opAverage">

<dataSet>

<item value="100"/>

<item deid="raw5"/>

<item deid="raw10"/>

</dataSet>

</ref>

</AveValDEID>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Division (A)

The following example uses two child elements to divide one value by another value. The first child element references the operation opAssignId and the value of the data group element raw10 to assign the current value of 10 as the initial value for DivConst. The second child element references the operation opDiv to divide the initial value 10 by the constant value assigned by the second child element. The result is 5.

Important: Because this operation introduces the illogical possibility of division by zero (0), special attributes are available to accommodate the possibility. See divZeroAction and divZeroSentinel.

<DivConst desc="Divide Constant Value" readOnly="true" type="ui2" isRef="1" divZeroAction="returnSentinel" divZeroSentinel="000">

<ref prec="0" refOp="opAssignId" deid="raw10"/>

<ref prec="1" refOp="opDiv" value="2"/>

</DivConst>

Useful attributes to know are isRef, prec, refOp, value, deid, divZeroAction, and divZeroSentinel. A useful element to know is ref.

Division (B)

The following example uses two child elements to divide one value by another value. The first child element references the operation opAssign and the constant value "10" to assign the current value of 10 as the initial value for DivId. The second child element references the operation opDivId to divide the constant value "10" by the value of the reference data group element assigned by the second child element. The result is 5.

Important: Because this operation introduces the illogical possibility of division by zero (0), special attributes are available to accommodate the possibility. See divZeroAction and divZeroSentinel.

<DivId desc="Divide Constant Value" readOnly="true" type="ui2" isRef="1" divZeroAction="noAction">

<ref prec="0" refOp="opAssign" value="10"/>

<ref prec="1" refOp="opDivId" deid="raw2"/>

</DivId>

Useful attributes to know are isRef, prec, refOp, deid, value, divZeroAction, and divZeroSentinel. A useful element to know is ref.

Exponent/Raise to Power (A)

The following example uses two child elements to raise one value to the power of the other. The first child element references the operation opAssignId and the value of the data group element raw10 to assign the current value of 10 as the initial value for PowConst. The second child element references the operation opPow and uses a constant value to raise the initial value to the power of "2". The result is 100.

<PowConst desc="Raise Power by Constant Value (10^2)" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw10"/>

<ref prec="1" refOp="opPow" value="2"/>

</PowConst>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Exponent/Raise to Power (B)

The following example uses two child elements to raise one value to the power of the other. The first child element references the operation opAssign and the constant value "10" to assign the current value of 10 as the initial value for PowId. The second child element references the operation opPowId and uses a reference data group element value to raise the initial value to the power of "2". The result is 100.

<PowId desc="Raise Power by DEID Value (10^2)" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssign" value="10"/>

<ref prec="1" refOp="opPowId" deid="raw2"/>

</PowId>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Maximum Value (A)

The following example uses specialized child elements to select a maximum value from a set of defined values. The first child element references the operation opMax to specify that its children are part of a data set from which the maximum value is required. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the maximum value from the data set is 50.

<MaxVal desc="Maximum value of dataset" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opMax">

<dataSet>

<item value="50"/>

<item deid="raw1"/>

<item deid="raw2"/>

</dataSet>

</ref>

</MaxVal>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Maximum Value (B)

The following example uses specialized child elements to select a maximum value from a set of defined values where some of the values are outside the data set, but within the parent data group element. The first child element references the operation opAssignId to assign a starting value that will be compared to values in the data set. The second child element references the operation opScaleFactor to apply a scale factor of 10 to the value 2. The result is 200. A third child element references the operation opMax to specify that a maximum value is to be returned. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the value 200 is compared to the values in the data set; the maximum value is assigned to the parent data group element. In this case, the maximum value for the data group element is 200.

<MaxValDEID desc="Maximum value of data group element" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw2"/>

<ref prec="1" refOp="opScaleFactor" scaleFactor="10"/>

<ref prec="2" refOp="opMax">

<dataSet>

<item value="50"/>

<item deid="raw1"/>

<item deid="raw10"/>

</dataSet>

</ref>

</MaxValDEID>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Minimum Value (A)

The following example uses specialized child elements to select a minimum value from a set of defined values. The first child element references the operation opMin to specify that its children are part of a data set from which the minimum value is required. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the minimum value from the data set is 1, because the data group element referenced (raw1) contains the value 1.

<MinVal desc="Minimum value of dataset" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opMin">

<dataSet>

<item value="50"/>

<item deid="raw1"/>

<item deid="raw2"/>

</dataSet>

</ref>

</MinVal>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Minimum Value (B)

The following example uses specialized child elements to select a minimum value from a set of defined values where some of the values are outside the data set, but within the parent data group element. The first child element references the operation opAssignId to assign a starting value that will be compared to values in the data set. The second child element references the operation opScaleFactor to apply a scale factor of 10 to the value 2. The result is 200. A third child element references the operation opMin to specify that a minimum value is to be returned. Then the dataSet element is defined. Finally, child item elements are defined. Each item element specifies a value; the value can either be a constant (value) or variable (deid). In this example, the value 200 is compared to the values in the data set; the minimum value is assigned to the parent data group element. In this case, the minimum value from the data set is 1, because the data group element referenced (raw1) contains the value 1.

<MinValDEID desc="Minimum value of data group element" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw2"/>

<ref prec="1" refOp="opScaleFactor" scaleFactor="10"/>

<ref prec="2" refOp="opMin">

<dataSet>

<item value="50"/>

<item deid="raw1"/>

<item deid="raw10"/>

</dataSet>

</ref>

</MinValDEID>

Useful attributes to know are isRef, prec, refOp, deid, and value. Useful elements to know are ref, dataSet, and item.

Multiplication (A)

The following example uses two child elements to multiply values. The first child element references the operation opAssignId and the value of the data group element raw10 to assign the current value of 10 as the initial value for MultConst. The second child element references the operation opMult to multiply the constant value "5" by the value assigned by the first child element. The result is 50.

<MultConst desc="Multiply Constant Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw10"/>

<ref prec="1" refOp="opMult" value="5"/>

</MultConst>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Multiplication (B)

The following example uses two child elements to multiply values. The first child element references the operation opAssign and the constant value "10" to assign the current value of 10 as the initial value for MultId. The second child element references the operation opMultId to multiply the value of the referenced data group element raw5 by the value assigned by the first child element. The result is 50.

<MultId desc="Multiply DEID Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssign" value="10"/>

<ref prec="1" refOp="opMultId" deid="raw5"/>

</MultId>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Subtraction (A)

The following example uses two child elements to subtract one value from another value. The first child element references the operation opAssignId and the value of the data group element raw10 to assign the current value of 10 as the initial value for SubConst. The second child element references the operation opSub to subtract the constant value "5" from the value assigned by the first child element. The result is 5.

<SubConst desc="Subtract Constant Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssignId" deid="raw10"/>

<ref prec="1" refOp="opSub" value="5"/>

</SubConst>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Subtraction (B)

The following example uses two child elements to subtract one value from another value. The first child element references the operation opAssign and the constant value "10" to assign the current value of 10 as the initial value for SubId. The second child element references the operation opSubId to subtract the value of the referenced data group element raw5 from the value assigned by the first child element. The result is 5.

<SubId desc="Subtract DEID Value" readOnly="true" type="ui2" isRef="1">

<ref prec="0" refOp="opAssign" value="10"/>

<ref prec="1" refOp="opSubId" deid="raw5"/>

</SubId>

Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.

Back to top

Let us know how we can improve this topic.

CygNet at weatherford.com

© 2020 Weatherford. All rights reserved.