Use the array data type to store a series of numeric or text values together. All elements in an array have the same data type.

Define arrays using the following pattern:

type [] identifier

Use one of the following types as the data type:

  • intX—Signed integer
  • uintX—Unsigned integer
  • realX—Floating-Point number
  • text—Text string
  • Definition Options

    Table 55. Definition Options for Arrays
    Data Type Global Local
    int32[]
    int16[]
    int8[]
    uint32[]
    uint16[]
    uint8[]
    real64[]
    real32[]
    text

    Defining Global Arrays

    To define a global array variable in PAscript, enter the int32[] or real64[] data types in a section globals code block. Then, enter the variable name.

    Example

    program
    
      section globals
        int32[]  intArray  // int32 array
        real64[]  realArray  // real64 array
      endsection
    
      intArray[0]  = 1
      realArray[0]  = 1.2
    
    endprogram
    Note The identifier used in the global section must match a PAtools Name of type Tables. Define Tables in the test with a value table type of data type, integer, or float.

    Defining Local Arrays

    Define local arrays using the following pattern:

    type[size] identifier [=initialization]

    Defining Array Dimensions

    Select one dimension, two dimensions, or three dimensions for the array shape.

    type[n] identifier              // Array with n elements
    type[m,n] identifier              // Array with m rows and n columns
    type[p,m,n] identifier      // Array with p pages, m rows and n columns

    In this case, initialization is optional. If uninitialized, the elements in the array are set to 0 or the empty string "".

    Initializing Arrays

    Initializing arrays is optional.

    Use the following rules to initialize arrays:

    • Values in a column are separated by a comma ,
    • Values in rows are separated by a semicolon ;
    • Elements of a page are separated by square brackets [ ]
    type[n] identifier = [Element_1, ... element_n]
    
    type[m,n] identifier = [Element_11, ... element_1n;
                            Element_21, ... element_2n;
                            ...
                            Element_m1, ... element_mn]
    
    type[p,m,n] identifier = [Element_111, ... element_11n;
                              Element_121, ... element_12n;
                              ...
                              Element_1m1, ... element_1mn]
                              [...]
                              [Element_p11, ... element_p1n;
                              Element_p21, ... element_p2n;
                              ...
                              Element_pm1, ... element_pmn]
    • If you initialize the arrays, specifying the array dimensions is optional.
    • When initializing both type dimensions and arrays, the following must match:
      • Row
      • Column
      • Page counts
    • The number of columns per row must not vary.
    • The number of rows per page must not vary.

    Example

    program
      section globals
        ...
      endsection
    
      int32[2] array1  // empty integer array with two elements
      int32[2,3] array2 = [ 1,2,2; 4,5,6 ]  // integer array with two rows and three columns
      int32[2,2,2] array3 = [ 1,2; 3,4] [5,6; 7,8]  //integer array with two pages, two rows, and two columns
    
      ...
    
    endprogram

    Access to an Array Element

    Access a array element with square brackets [] and the relevant index for the corresponding column, row, and page.

    Note The indices start at 0. For example, a value of 0 is required to access the first column.

    Read and Write Arrays Example 1

    program
      int32 value
      int32[2,3] array2 = [1,2,3; 4,5,6]  // integer array with two rows and three columns
      int23[2,2,2] array3 = [1,2; 3,4][5,6; 7,8]  // integer array with two pages, two rows, and two columns
    
      value = array2[0,2];  // accesses element in first row, thrid column; value is now 3
    
      value = array2[0,1,1];  // accesses element in first page, second row, second column; value is now 4
    
      array3[0,1,1] = 10;  // array3 is now [1,2; 3,10][5,6; 7,8]
    endprogram

    You can use smaller dimensions than were defined for the array. You are not required to specify all indices. The indices include the page index, row index, and column index. For example, you can specify only the column index. You can also specify only the column and row index. In this case, 0 is used for the undefined indexes.

    Read and Write Arrays Example 2

    program
      int32 value
      int32[2,3] array2 = [1,2,3; 4,5,6]  // integer array with two rows and three columns
      int23[2,2,2] array3 = [1,2; 3,4][5,6; 7,8]  // integer array with two pages, two rows, and two columns
    
      value = array2[2]  // row index is implied as 0; accesses element in first row, third column; value is now 3
    
      value = array3[1,0];  // page index is implied as 0; accesses element in first page, second row, first column; value is now 4
    
      value = array3[1];  // page and row index are implied as 0; access element in first page, first row, second column; value is now 2
    
      array2[2] = 10;  // row index is implied as 0; accesses element in first row, third column; array2 is now [1,2,10; 4,5,6]
    endprogram

    Copying Arrays

    Use the :copyFrom() type function to copy the contents of an array to another array.

    The dimensions of the destination adapts to the dimensions of the source.

    A subsequent change to the dimension or value in one array has no effect on the dimension or value in the other array.

    Example: Copying Arrays

    int32[2,2] target=[9,8;7,6]
    int32[3] source=[1,2,3]
    target:copyFrom(source)  // target is now a 1x3 array with values [1,2,3]

    Referencing Arrays

    The = operator causes the target array to reference the source array.

    The dimension of the destination adapts to the dimension of the source.

    A subsequent change to the dimension or value in one array effects the dimension or value in the other array.

    Example: Referencing Arrays

    program
            int32[2,3] source = [1,2,3; 4,5,6]
            int32[2,2,3] target
    
            // copy the array
            target = source        // target and source now have a shape of [2,3] and a value of [1,2,3; 4,5,6]
            source[0,1] = 10        // target and source now have a value of [1,10,3; 4,5,6]
    endprogram