Masked assignment may also be performed by a WHERE construct:
WHERE(A > 0.0) B = LOG(A) C = SQRT(A) ELSEWHERE B = 0.0 ENDWHERE
the effect of this code block is to perform the assignments
B(j,k)
= LOG(A(j,k))
and
C(j,k)
= SQRT(A(j,k)
wherever (A(j,k)
>
0.0)
is .TRUE.. For the cases where the mask is .FALSE. the assignments in
the ELSEWHERE block are made instead. Note that the WHERE ...
END WHERE is not a control construct
and cannot currently be nested.
In all the above examples the mask, (the logical expression,) must conform to the implied shape of each assignment in the body, in other words, in the above example all arrays must all conform.
The execution sequence is as follows: evaluate the mask, execute the WHERE block (in full) then execute the ELSEWHERE block. The separate assignment statements are executed sequentially but the individual elemental assignments within each statement are (conceptually) executed in parallel. It is not possible to have a scalar on the LHS in a WHERE and all statements must be array assignments.