HP Fortran Programmer's Reference (September 2007)

Expressions and assignment
Assignment
Chapter 4 101
contents of t1 referenced through p1 through p2: 99
contents of t2(1) referenced through p1: 1
contents of t2 referenced through the array pointer p3: 1 2 3
4 5
contents of t2(2) referenced through p3 through p1: 2
p1 is disassociated.
p2 is disassociated by pointer assignment.
Masked array assignment
In a masked array assignment, a logical expression—called a mask— controls the selection of
array elements for assignment. Masked array assignment is implemented by the WHERE
statement and the WHERE construct. The syntax of the WHERE statement is:
WHERE (
array-logical-expression
)
array
=
array-expression
where
array-logical-expression
,
array
, and
array-expression
must all be conformable.
The
array-logical-expression
(the mask) is evaluated for each element and the outcome
(.TRUE. or .FALSE.) determines whether an assignment is made to the corresponding
element of
array
.
The syntax of the WHERE construct is:
WHERE (
array-logical-expression
)
array
=
array-expression
[
array
=
array-expression
] ...
[ELSEWHERE
array
=
array-expression
[
array
=
expression
] ... ]
END WHERE
The WHERE construct is similar to the WHERE statement, but more general in that several
array
=
array-expression
statements can be controlled by one
array-logical-expression
. In
addition, an optional ELSEWHERE part of the construct assigns array elements whose
corresponding
array-logical-expression
elements evaluate to .FALSE..
When a WHERE construct is executed,
array-logical-expression
is evaluated just once and
therefore any subsequent assignment in a WHERE block (the block following the WHERE
statement) or ELSEWHERE block to an entity of
array-logical-expression
has no effect on
the masking. Thereafter, successive assignments in the WHERE block are evaluated in sequence
as if they were specified in a WHERE statement, as follows:
WHERE (
array-logical-expression
)
array
=
array-expression
Each assignment in the ELSEWHERE is executed as if it were:
WHERE (.NOT.
array-logical-expression
)
array
=
array-expression
For example, the following WHERE construct: