# Array Sections

An array section is a portion of an array that is an array itself. It is an array subobject. A section subscript list (appended to the array or array component) determines which portion is being referred to. A reference to an array section takes the following form:

array(sect-subscript-list)

array | Is the name of the array.
sect-subscript-list | Is a list of one or more section subscripts (subscripts, subscript triplets, or vector subscripts) indicating a set of elements along a particular dimension. At least one of the items in the section subscript list must be a subscript triplet or vector subscript. A subscript triplet specifies array elements in increasing or decreasing order at a given stride. A vector subscript specifies elements in any order. Each subscript and subscript triplet must be a scalar integer (or other numeric) expression. Each vector subscript must be a rank-one integer expression.

## Description

If no section subscript list is specified, the rank and shape of the array section is the same as the parent array.

Otherwise, the rank of the array section is the number of vector subscripts and subscript triplets that appear in the list. Its shape is a rank-one array where each element is the number of integer values in the sequence indicated by the corresponding subscript triplet or vector subscript.

If any of these sequences is empty, the array section has a size of zero. The subscript order of the elements of an array section is that of the array object that the array section represents.

Each array section inherits the type, kind type parameter, and certain attributes (INTENT, PARAMETER, and TARGET) of the parent array. An array section cannot inherit the POINTER attribute.

If an array (or array component) is of type character, it can be followed by a substring range in parentheses. Consider the following declaration:

      CHARACTER(LEN=15) C(10,10)

In this case, an array section referenced as C(:,:) (1:3) is an array of shape (10,10), whose elements are substrings of length 3 of the corresponding elements of C.

The following shows valid references to array sections. Note that the syntax (/.../) denotes an array constructor.

      REAL, DIMENSION(20) :: B
      ...
      PRINT *, B(2:20:5)  ! The section consists of elements
                          !    B(2), B(7), B(12), and B(17)

      K = (/3, 1, 4/)
      B(K) = 0.0    ! Section B(K) is a rank-one array with shape (3) and
                    !   size 3. (0.0 is assigned to B(1), B(3), and B(4).)

Parent topic: Arrays

## See Also

INTENT attribute
PARAMETER attribute
TARGET attribute
Array constructors
Character Substrings
Structure components for details on array sections as structure components