Array operations areperformed in parallel. That is, an operation
is performed on each element independently and in any order. The
practical effect of this is that, because an assignment statement
may have the same array on both the left and right-hand sides, the
right-hand side is fully evaluated before any assignment takes place.
This means that in some cases the compiler may create temporary
space to hold intermediate results of the computation.
A scalar may appear in an array expression. If the scalar
is used in an expression containing whole array references—for
example
a = b + 2.0 ! a and b are conformable arrays of type real |
then the effect is as if the scalar were evaluated and then
broadcast to form a conformable array of elements, each having the
value of the scalar. Thus, a scalar used in an array context is
conformable with the array or arrays involved.
Zero-sized arrays may also appear in an array expression.
Although they have no elements, they do have a shape and must therefore
follow the rule of conformable arrays. Because scalars are conformable
with any array, they may therefore appear in an operation involving
a zero-sized array.
The following illustrates valid and invalid array expressions.
 |
SUBROUTINE foo(a,b,c) ! a is an assumed-shape array with rank-one REAL :: a(:) ! b is a pointer to a rank-two array REAL, POINTER :: b(:,:) ! c is an assumed-size array REAL :: c(*) ! d is an allocatable array; its shape can only be defined in an ! ALLOCATE statement REAL, ALLOCATABLE :: d(:) ! create the array d with the same size as a; a and d have ! the same shape and are therefore conformable ALLOCATE(d(SIZE(a))) ! copy the array a into d d = a ! sets each element of the array associated with b to 0.0; ! the effect is as if the scalar were broadcast into a ! temporary array, with the same shape as b; b is then assigned ! to theleft-hand side b = 0.0 ! corresponding elements of a and d are added together and then ! stored back into the corresponding array element of d d = a + d ! conceptually the operand SQRT(d) is evaluated into an ! intermediate array with the same shape as d; each element of ! the intermediate array will be added to the corresponding ! element of a and stored into the corresponding element of d d = a + SQRT(d) DEALLOCATE(d) ! examples of illegal uses of arrays: ! ILLEGAL - c is an assumed-size array and so has no shape; ! an assumed-size array may not be used as a whole array ! operand(except in an argument list) a = c ! ILLEGAL - the arrays a and b do not have the same shape and are ! therefore not conformable a = a + b ! ILLEGAL - d was previously deallocated and must not be ! referenced subsequently a = a + d END SUBROUTINE foo |
 |