HP Fortran Programmer's Reference (September 2007)

Arrays
Array expressions
Chapter 3 77
Array expressions
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;