ArrayOp1

(Engine-Level Function)

Description: Performs a mathematical operation on an array with respect to a scalar value.
Returns: Nothing
Usage: Script only.
Function Groups: Array
Related to: ArrayOp2 | ArraySize | FFT| Array Functions | WhileLoop | Array Functions
Format:  ArrayOp1(ArrayElem, N, Scalar, OpCode[, MaskElement])
Parameters:  
ArrayElem
Required. Any array element giving the starting point for the array operation. The subscript for the array may be any numeric expression. If processing a multidimensional array, only the right-most subscript is used.
N
Required. Any numeric expression giving the number of array elements to compute. N will be limited to the minimum of (N, Source length, Destination length).
If the starting point given by the first parameter is not the first element, and therefore N extends past the upper bound of the lowest array dimension, this computation will "wrap-around" and resume at the first element. Because N is automatically limited by the smallest array dimension, no element will be processed twice.
Scalar
Required. Any numeric expression giving the scalar quantity used in the array computation.
OpCode

Required. Any numeric expression giving the operation number to perform as follows (note that A is the array element, and S is Scalar):

OpCode

Operation

OpCode

Operation

0

A = S (S may be invalid)

17

A = XOR(A,S)

1

A = A + S

18

A = Pow(S,A)

2

A = A - S

19

A = Exp(S*A)

3

A = S - A

20

A = S * Log(A)

4

A = A * S

21

A = S * Ln(A)

5

A = A / S

22

A = Sin(S * A)

6

A = S / A

23

A = Cos(S*A)

7

A = A % S

24

A = Tan (S*A)

8

A = Min(A,S)

25

A = S * ASin(A)

9

A = Max(A,S)

26

A = S * ACos(A)

10

A = A < S

27

A = S * ATan(A)

11

A = A <= S

28

A = S * Sqrt(A)

12

A = A==S

29

A = S * Abs(A)

13

A = A >= S

30

A = (Index of A) + S

14

A = A > S

31

A = (Index of A) * S

15

A = AND(A,S)

32

A = S * Round (A)

16

A = OR(A,S)

33

Valid(A) != Valid(S) ||

    PickValid(A != S, 0)

MaskElement
Optional. The starting element in an array of TRUE and FALSE values, specifying which elements in array, A will be operated upon. The ArrayOp function will only apply to element A[i] if Mask[starting element + i] is a valid TRUE.
Comments:

The ArrayOp1 statement is useful for large amounts of repetitive computation. While this can be done by executing a script repeatedly using WhileLoop, this ArrayOp1 statement is much faster. Complex computations may be broken down into a series of simple steps and handled by multiple ArrayOp1 and ArrayOp2 statements. If text arrays are used, each text value will be converted to a number before the numerical operations are performed. The resulting array is converted back to text.

Mode 33 will compare for differences. It does a more thorough comparison than a simple A != B.

For a multi-dimensional array such as A[X][Y], only the right-most dimension is processed. ([Y] in this example.) You must resort to loops to process the other array dimensions.

Examples:

  If Watch(1);
  [
    SomeArray = New(10)                 { create an array };
    ArrayOp1(SomeArray[0], ArraySize(SomeArray), 0, 0 { Set all elements to zero });
  ]
  If 1 Main;
  [
    ArrayOp1(pumpTrend[10] { Starting element },
             50 { Number of elements to use },
             x + y { Number to use in computation },
             0 { Assign result to the element });
    ArrayOp1(sequentNums[0] { Starting element (beginning) },
             10 { Number of elements to use },
             1 { Number to use in computation },
             30 { Assign sequential numbers });
    ArrayOp1(evenNums[0] { Starting element (beginning) },
             101 { Number of elements to use },
             2 { Number to use in computation },
             31 { Assign multiples of number });
  ]

In this example, the first statement sets elements 10 through 59 of pumpTrend to the result of x + y, the second statement sets elements 0 through 9 of sequentNums to the numbers 1 through 10, and the third statement sets elements 0 through 100 of evenNums to the even numbers from 0 to 200.