Array Variables
Array variables are single- or multi-dimensioned arrays of double precision or integer values. Unlike (scalar) numeric variables, array variables must be declared prior to their use. The declaration syntax is
DECLARE name, type, num_dimensions, dimension1 [, dimension 2 [, dimension 3 [, dimension 4] etc...]]
The name may be any legal variable name as described in the previous section. The type must be either DOUBLE or INTEGER; this value indicates the type of array variable. The integer value num_dimensions defines the number of dimensions of the array (not the size), and must be between 1 and 4, inclusive. The integers dimension1, dimension2, etc., define the size of the array in that dimension. Note that array variables start at index 1, and thus an array of size 10 has valid indices from 1 to 10.
Array variables may be defined anywhere inside the macro, they need not be declared at the beginning of the macro. To release the memory associated with an array variable, use the RELEASE keyword. The syntax is
RELEASE name
The RELEASE keyword is optional, as the memory associated with the declared variable is automatically released when the macro terminates. However the RELEASE keyword is useful for conserving memory if large arrays are only needed during a portion of the macro execution.
Array variables are assigned values using the following syntax:
name ( index1, index2, ... ) = value
The values stored in the array may be retrieved with the same basic syntax:
value = name ( index1, index2, ...)
The following sample code declares a two-dimensional array variable, assigns a value to each element, prints the values, and then releases the memory for the array:
DECLARE Z, DOUBLE, 2, 5, 5 FOR i, 1, 5, 1 FOR j, 1, 5, 1 Z(i, j) = i + j NEXT j NEXT i k = 0 FORMAT 8.0 FOR i, 1, 5, 1 FOR j, 1, 5, 1 PRINT k, i, j, Z(i,j) k = k + 1 NEXT j NEXT i RELEASE Z
Next: