Array elements

Array elements are the scalar data that make up an array. Each element inherits the type, type parameters, and INTENT, PARAMETER, TARGET, Fortran 2003 beginsPROTECTED, ASYNCHRONOUS, and VOLATILEFortran 2003 ends attributes from its parent array. The POINTER and ALLOCATABLE attributes are not inherited.

Syntax

You identify an array element by an array element designator, whose form is:

Read syntax diagramSkip visual syntax diagramarray_namearray_struct_comp(subscript_list)
array_name
is the name of an array
array_struct_comp
is a structure component whose rightmost comp_name is an array
subscript
is a scalar integer expression

IBM extension begins A subscript can be a scalar real expression in IBM® Open XL Fortran. IBM extension ends

Rules

  • The number of subscripts must equal the number of dimensions in the array.
  • If array_struct_comp is present, each part of the structure component except the rightmost must have rank zero (that is, must not be an array name or an array section).
  • The value of each subscript expression must not be less than the lower bound or greater than the upper bound for the corresponding dimension.
  • The subscript value depends on the value of each subscript expression and on the dimensions of the array. It determines which element of the array is identified by the array element designator.

Array element order

The elements of an array are arranged in storage in a sequence known as the array element order, in which the subscripts change most rapidly in the first dimension, and subsequently in the remaining dimensions.

For example, an array declared as A(2, 3, 2) has the following elements:
 Position of Array Element             Array Element Order
 -------------------------             -------------------
          A(1,1,1)                              1
          A(2,1,1)                              2
          A(1,2,1)                              3
          A(2,2,1)                              4
          A(1,3,1)                              5
          A(2,3,1)                              6
          A(1,1,2)                              7
          A(2,1,2)                              8
          A(1,2,2)                              9
          A(2,2,2)                             10
          A(1,3,2)                             11
          A(2,3,2)                             12

Related information