Using the earlier declarations, references can be made to:
A = 0.0
This statement will set whole array A to zero. Each assignment is performed conceptually at the same time. Scalars always conform with arrays.
B = C + D
This adds the corresponding elements of B and C and then assigns each element if the result to the corresponding element 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(:) + D(:)
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
This statement sets one element, the first element of a (A(1)), to zero,
B(0,0) = A(3) + C(5,1)
Sets element B(0,0) 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:4) = 0.0
This assignment sets three elements of A (A(2), A(3) and A(4)) 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.
Return to corresponding overview page