5 ARRAYS AND SUBSTRINGS

An array is a nonempty sequence of data. An array element is one member of the sequence of data. An array name is the symbolic name of an array. An array element name is an array name qualified by a subscript ( 5.3).

An array name not qualified by a subscript identifies the entire sequence of elements of the array in certain forms where such use is permitted ( 5.6); however, in an EQUIVALENCE statement, an array name not qualified by a subscript identifies the first element of the array ( 8.2.4).

An array element name identifies one element of the sequence. The subscript value (Table 1) specifies the element of the array being identified. A different array element may be identified by changing the subscript value of the array element name.

An array name is local to a program unit ( 18.1.2).

A substring is a contiguous portion of a character datum.

5.1 Array Declarator

An array declarator specifies a symbolic name that identifies an array within a program unit and specifies certain properties of the array. Only one array declarator for an array name is permitted in a program unit.

5.1.1 Form of an Array Declarator.

The form of an array declarator is:
a (d [,d]...)

The number of dimensions of the array is the number of dimension declarators in the array declarator. The minimum number of dimensions is one and the maximum is seven.

5.1.1.1 Form of a Dimension Declarator.

The form of a dimension declarator is:
[d :] d
                            1    2

The lower and upper dimension bounds are arithmetic expressions, called dimension bound expressions, in which all constants, symbolic names of constants, and variables are of type integer. The upper dimension bound of the last dimension may be an asterisk in assumed-size array declarators ( 5.1.2). A dimension bound expression must not contain a function or array element reference. Integer variables may appear in dimension bound expressions only in adjustable array declarators ( 5.1.2).

If the symbolic name of a constant or variable that appears in a dimension bound expression is not of default implied integer type ( 4.1.2), it must be specified as integer by an IMPLICIT statement or a type-statement prior to its appearance in a dimension bound expression.

5.1.1.2 Value of Dimension Bounds.

The value of either dimension bound may be positive, negative, or zero; however, the value of the upper dimension bound must be greater than or equal to the value of the lower dimension bound. If only the upper dimension bound is specified, the value of the lower dimension bound is one. An upper dimension bound of an asterisk is always greater than or equal to the lower dimension bound.

5.1.2 Kinds and Occurrences of Array Declarators.

Each array declarator is either a constant array declarator, an adjustable array declarator, or an assumed-size array declarator. A constant array declarator is an array declarator in which each of the dimension bound expressions is an integer constant expression ( 6.1.3.1). An adjustable array declarator is an array declarator that contains one or more variables. An assumed-size array declarator is a constant array declarator or an adjustable array declarator, except that the upper dimension bound of the last dimension is an asterisk.

Each array declarator is either an actual array declarator or a dummy array declarator.

5.1.2.1 Actual Array Declarator.

An actual array declarator is an array declarator in which the array name is not a dummy argument. Each actual array declarator must be a constant array declarator. An actual array declarator is permitted in a DIMENSION statement, type-statement, or COMMON statement (Section 8).

5.1.2.2 Dummy Array Declarator.

A dummy array declarator is an array declarator in which the array name is a dummy argument. A dummy array declarator may be either a constant array declarator, an adjustable array declarator, or an assumed-size array declarator. A dummy array declarator is permitted in a DIMENSION statement or a type-statement but not in a COMMON statement. A dummy array declarator may appear only in a function or subroutine subprogram.

5.2 Properties of an Array

The following properties of an array are specified by the array declarator: the number of dimensions of the array, the size and bounds of each dimension, and therefore the number of array elements.

The properties of an array in a program unit are specified by the array declarator for the array in that program unit.

5.2.1 Data Type of an Array and an Array Element.

An array name has a data type ( 4.1.1). An array element name has the same data type as the array name.

5.2.2 Dimensions of an Array.

The number of dimensions of an array is equal to the number of dimension declarators in the array declarator.

The size of a dimension is the value:

d  - d  + 1
                         2    1

Note that if the value of the lower dimension bound is one, the size of the dimension is d 2 .

The size of a dimension whose upper bound is an asterisk is not specified.

The number and size of dimensions in one array declarator may be different from the number and size of dimensions in another array declarator that is associated by common, equivalence, or argument association.

5.2.3 Size of an Array.

The size of an array is equal to the number of elements in the array. The size of an array is equal to the product of the sizes of the dimensions specified by the array declarator for that array name. The size of an assumed-size dummy array ( 5.5) is determined as follows:
  1. If the actual argument corresponding to the dummy array is a noncharacter array name, the size of the dummy array is the size of the actual argument array.
  2. If the actual argument corresponding to the dummy array name is a noncharacter array element name with a subscript value of r in an array of size x , the size of the dummy array is x + 1 - r .
  3. If the actual argument is a character array name, character array element name, or character array element substring name and begins at character storage unit t of an array with c character storage units, then the size of the dummy array is INT((c + 1 - t) / ln) , where ln is the length of an element of the dummy array.

If an assumed-size dummy array has n dimensions, the product of the sizes of the first n - 1 dimensions must be less than or equal to the size of the array, as determined by one of the immediately preceding rules.

5.2.4 Array Element Ordering.

The elements of an array are ordered in a sequence ( 2.1). An array element name contains a subscript ( 5.4.1) whose subscript value ( 5.4.3) determines which element of the array is identified by the array element name. The first element of the array has a subscript value of one; the second element has a subscript value of two; the last element has a subscript value equal to the size of the array.

Whenever an array name unqualified by a subscript is used to designate the whole array ( 5.6), the appearance of the array name implies that the number of values to be processed is equal to the number of elements in the array and that the elements of the array are to be taken in sequential order.

5.2.5 Array Storage Sequence.

An array has a storage sequence consisting of the storage sequences of the array elements in the order determined by the array element ordering. The number of storage units in an array is x*z , where x is the number of the elements in the array and z is the number of storage units for each array element.

5.3 Array Element Name

The form of an array element name is:
a (s [,s]...)

The number of subscript expressions must be equal to the number of dimensions in the array declarator for the array name.

5.4 Subscript

5.4.1 Form of a Subscript.

The form of a subscript is:
(s [,s]...)
where s is a subscript expression.

Note that the term "subscript" includes the parentheses that delimit the list of subscript expressions.

5.4.2 Subscript Expression.

A subscript expression is an integer expression. A subscript expression may contain array element references and function references. Note that a restriction in the evaluation of expressions ( 6.6) prohibits certain side effects. In particular, evaluation of a function must not alter the value of any other subscript expression within the same subscript.

Within a program unit, the value of each subscript expression must be greater than or equal to the corresponding lower dimension bound in the array declarator for the array. The value of each subscript expression must not exceed the corresponding upper dimension bound declared for the array in the program unit. If the upper dimension bound is an asterisk, the value of the corresponding subscript expression must be such that the subscript value does not exceed the size of the dummy array.

5.4.3 Subscript Value.

The subscript value of a subscript is specified in Table 1. The subscript value determines which array element is identified by the array element name. Within a program unit, the subscript value depends on the values of the subscript expressions in the subscript and on the dimensions of the array specified in the array declarator for the array in the program unit. If the subscript value is r , the r th element of the array is identified.

Table_1

Subscript Value

____________________________________________________________
|  |                      |              |                 |
|n |       Dimension      |   Subscript  |    Subscript    |
|  |      Declarator      |              |      Value      |
|__|______________________|______________|_________________|
|  |                      |              |                 |
|1 |  (j :k )             |  (s )        | 1+(s -j )       |
|  |    1  1              |    1         |     1  1        |
|__|______________________|______________|_________________|
|  |                      |              |                 |
|2 |  (j1:k1,j2:k2)       |  (s1,s2)     | 1+(s1-j1)       |
|  |                      |              |  +(s2-j2)*d1    |
|__|______________________|______________|_________________|
|  |                      |              |                 |
|3 |  (j :k ,j :k ,j :k ) |  (s ,s ,s )  | 1+(s -j )       |
|  |    1  1  2  2  3  3  |    1  2  3   |  +(s1-j1)*d     |
|  |                      |              |  +(s2-j2)*d1*d  |
|  |                      |              |     3  3   2  1 |
|__|______________________|______________|_________________|
|  |                      |              |                 |
|__|______________________|______________|_________________|
|  |                      |              |                 |
|n |  (j :k ,...,j :k )   |  (s ,...,s ) | 1+(s -j )       |
|  |    1  1      n  n    |    1      n  |  +(s1-j1)*d     |
|  |                      |              |  +(s2-j2)*d1*d  |
|  |                      |              |  +..3  3   2  1 |
|  |                      |              |  +(s -j )*d     |
|  |                      |              |   *dn  n...n-1  |
|  |                      |              |     n-2      1  |
|__|______________________|______________|_________________|

Notes for Table 1:

  1. n is the number of dimensions, 1 <= n <= 7 .
  2. j i is the value of the lower bound of the ith dimension.
  3. k i is the value of the upper bound of the ith dimension.
  4. If only the upper bound is specified, then j % = 1 i .
  5. s i is the integer value of the ith subscript expression.
  6. d = k -j +1 i i i is the size of the ith dimension. If the value of the lower bound is 1, then d = k i i .

Note that a subscript of the form (j ,...j ) 1 n has a subscript value of one and identifies the first element of the array. A subscript of the form (k ,...,k ) 1 n identifies the last element of the array; its subscript value is equal to the number of elements in the array.

The subscript value and the subscript expression value are not necessarily the same, even for a one-dimensional array. In the example:

  1. DIMENSION A(-1:8),B(10,10)
  2. A(2) = B(1,2)

A(2) identifies the fourth element of A, the subscript is (2) with a subscript value of four, and the subscript expression is 2 with a value of two. B(1,2) identifies the eleventh element of B, the subscript is (1,2) with a subscript value of eleven, and the subscript expressions are 1 and 2 with values of one and two.

5.5 Dummy and Actual Arrays

A dummy array is an array for which the array declarator is a dummy array declarator. An assumed-size dummy array is a dummy array for which the array declarator is an assumed-size array declarator. A dummy array is permitted only in a function or subroutine subprogram (Section 15).

An actual array is an array for which the array declarator is an actual array declarator. Each array in the main program is an actual array and must have a constant array declarator. A dummy array may be used as an actual argument.

5.5.1 Adjustable Arrays and Adjustable Dimensions.

An adjustable array is an array for which the array declarator is an adjustable array declarator. In an adjustable array declarator, those dimension declarators that contain a variable name are called adjustable dimensions.

An adjustable array declarator must be a dummy array declarator. At least one dummy argument list of the subprogram must contain the name of the adjustable array. A variable name that appears in a dimension bound expression of an array must also appear as a name either in every dummy argument list that contains the array name or in a common block in that subprogram.

At the time of execution of a reference to a function or subroutine containing an adjustable array in its dummy argument list, each actual argument that corresponds to a dummy argument appearing in a dimension bound expression for the array and each variable in common appearing in a dimension bound expression for the array must be defined with an integer value. The values of those dummy arguments or variables in common, together with any constants and symbolic names of constants appearing in the dimension bound expression, determine the size of the corresponding adjustable dimension for the execution of the subprogram. The sizes of the adjustable dimensions and of any constant dimensions appearing in an adjustable array declarator determine the number of elements in the array and the array element ordering. The execution of different references to a subprogram or different executions of the same reference determine possibly different properties (size of dimensions, dimension bounds, number of elements, and array element ordering) for each adjustable array in the subprogram. These properties depend on the values of any actual arguments and variables in common that are referenced in the adjustable dimension expressions in the subprogram.

During the execution of an external procedure in a subprogram containing an adjustable array, the array properties of dimension size, lower and upper dimension bounds, and array size (number of elements in the array) do not change. However, the variables involved in an adjustable dimension may be redefined or become undefined during execution of the external procedure with no effect on the above-mentioned properties.

5.6 Use of Array Names

In a program unit, each appearance of an array name must be in an array element name except in the following cases:
  1. In a list of dummy arguments
  2. In a COMMON statement
  3. In a type-statement
  4. In an array declarator. Note that although the form of an array declarator may be identical to that of an array element name, an array declarator is not an array element name.
  5. In an EQUIVALENCE statement
  6. In a DATA statement
  7. In the list of actual arguments in a reference to an external procedure
  8. In the list of an input/output statement if the array is not an assumed-size dummy array
  9. As a unit identifier for an internal file in an input/output statement if the array is not an assumed-size dummy array
  10. As the format identifier in an input/output statement if the array is not an assumed-size dummy array
  11. In a SAVE statement

5.7 Character Substring

A character substring is a contiguous portion of a character datum and is of type character. A character substring is identified by a substring name and may be assigned values and referenced.

5.7.1 Substring Name.

The forms of a substring name are:
v ( [e ] : [e ] )
                           1      2
a (s [,s]...)( [e ] : [e ] )
                                 1      2

The value e 1 specifies the leftmost character position of the substring, and the value e 2 specifies the rightmost character position. For example, A(2:4) specifies characters in positions two through four of the character variable A, and B(4,3)(1:6) specifies characters in positions one through six of the character array element B(4,3).

The values of e 1 and e 2 must be such that:

1 <= e  <= e  <= len
                        1        2

where len is the length of the character variable or array element ( 8.4.2). If e 1 is omitted, a value of one is implied for e 1 . If e 2 is omitted, a value of len is implied for e 2 . Both e and e 1 2 may be omitted; for example, the form v(:) is equivalent to v , and the form a(s [,s]...)(:) is equivalent to a(s [,s]...) . The length of a character substring is e - e + 1 2 1 .

5.7.2 Substring Expression.

A substring expression may be any integer expression. A substring expression may contain array element references and function references. Note that a restriction in the evaluation of expressions ( 6.6) prohibits certain side effects. In particular, evaluation of a function must not alter the value of any other expression within the same substring name.

'




[Contents] [Previous] [Next] [Home]

NDP77
http://www.ndp77.net
webmaster MFA (main)
webmaster@ndp77.net