beautypg.com

Arrays – MTS Series 793 User Manual

Page 377

background image

Variables are local to a particular signal’s expression. Multiple signals can use the same name in their
expressions without any conflict.

Using variables to remember history

Variables that are defined as shown in the preceding example remember their value from one pass to the
next. The following expression does a two-point running average:

real oldValue;
“My Average Signal” = (“My Signal” + oldValue)/2;
oldValue = “My Signal”;

//Remember the previous value.

When an expression is loaded into the machine (either when the configuration is loaded, or when a new
expression is applied), the values of all variables are set to zero. Thereafter, they keep the last value that
was set into them.

Arrays

An array is a variable that holds multiple values of the same data type. Arrays are declared in much the same
way as normal variables. The only difference is that a size is specified.

For example, the following declares an array “A” of 10 elements:

real A[10];

The elements of an array are indexed from zero.

The array in the preceding example contains elements:

A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], and A[9]

One declaration statement can declare multiple array and non-array variables. For example:

real A[100], a, B[20], x;
int counts[10], i;

The elements of an array can be individually referenced or assigned. Arrays can be used to conveniently
store more history.

For example, here is a four-point running average:

real old[4];
old[3] = old[2];
old[2] = old[1];
old[1] = old[0];
old[0] = “My Signal”;

//Remember the previous value.

“My Average Signal” = (old[0] + old[1] + old[2] + old[3])/4;

The language supports the following built-in array functions:

int ishift(int x[ ], int y)

int size(real x[ ])

real avg(real x[ ], int y)

int isize(int x[ ])

real shift(real x[ ], real y)

The function shift (Array, value) performs the same operation as shown in the preceding example (the function
ishift(iarray, value) works the same for integer arrays). The shift function shifts every element up to the next
higher index and puts the specified value into element zero. It returns the value that shifted out of the last
element in the array.

MTS Series 793 Control Software 377

Calculated Signals