Cicode Programming Reference > Cicode Function Categories > Table (Array) Functions Introduction > TableMath

TableMath

Performs mathematical operations on a table of real (floating-point) numbers. This function supports minimum, maximum, average, standard deviation, and total operations on a table of values. Use this function for operating on tables returned from the trend system with the TrnGetTable() function. You can set the Mode to either accept or ignore invalid or gated data returned from TrnGetTable().

Notes:
This function cannot check the length of any arrays passed to it. If the array is shorter than the size argument, unpredictable results can occur, such as data in memory being overwritten, or a general protection fault.

This function only supports arrays declared in Cicode and not variable tag arrays.

 

UNINTENDED EQUIPMENT OPERATION

Always confirm that arrays are of appropriate length before passing them to the TableMath function.

Failure to follow these instructions can result in death, serious injury, or equipment damage.

Syntax

TableMath(Table, Size, Command [, Mode] )

Table:

Any table of floating-point numbers.

Size:

The maximum number of items in the table.

Command:

The mathematical operation to perform on the table:

0 - Minimum

1 - Maximum

2 - Average

3 - Standard deviation

4 - Total

Mode:

The mode of the operation:

0 - Operate on all data - default

1 - Ignore invalid or gated data returned from the TrnGetTable() function

Return Value

Returns the value related to the requested mathematical operation performed on the table (Minimum, Maximum, Average, Standard deviation or Total).\

Related Functions

TableLookup TrnGetTable

Example

REAL Array[5]=10,15,50,100,200;
REAL Min,Avg;
! Get the minimum value.
Min=TableMath(Array, 5, 0, 0); ! Sets Min to 10.
! Get the average value.
Avg=TableMath(Array, 5, 2, 0); ! Sets Avg to 75.

See Also

Table (Array) Functions