Using the earlier declarations, references can be made to:
A = 0
-- sets whole array A to zero; scalars always
conform with arrays.B = C + 1
-- adds one to all elements,
of C and then assigns each element to the
corresponding elements of B.
For this to be legal Fortran 90
both arrays in the RHS expression must conform (B and C must
be same shape
and size). The assignment could have been written B(:) = C(:) + 1
demonstrating how a whole array can be
referenced by subscripting it with a colon. (This is shorthand for
lower_bound:upper_bound and is exactly equivalent to using only its
name with no subscripts or parentheses.)
A(1) = 0.0
sets one element to zero, B = A(3) + C(5,1)
sets whole array B to the sum of
two elements.
A particular element of an array is accessed by subscripting the array name with an integer which is within the bounds of the declared extent. Subscripting directly with a REAL, COMPLEX, CHARACTER, DOUBLE PRECISION or LOGICAL is an error. This, and indeed the previous example, demonstrates how scalars (literals and variables) conform to arrays; scalars can be used in many contexts in place of an array.
A(2:6) = 0
sets section of A to zero,B(-1:0,1:2)=C(1:2,2:3)+1
adds one to the subsection of
C
and assigns to the subsection of B.
Care must be taken when referring to different sections of the same array on both sides of an assignment statement, for example,
DO i = 2,15 A(i) = A(i) + A(i-1) END DO
is not the same as
A(2:15) = A(2:15) + A(1:14)
in the first case, a general element i of A has the value,
A(i) = A(i) + A(i-1) + ... + A(2) + A(1)
but in the vectorised statement it has the value,
A(i) = A(i) + A(i-1)
In summary both scalars and arrays can be thought of as objects. (More or less) the same operations can be performed on each with the array operations being performed in parallel. It is not possible to have a scalar on the LHS of an assignment and a non scalar array reference on the RHS unless that section is an argument to a reduction function.