The WHERE statement is used when an array assignment is to be performed on a non-regular section of the LHS array elements, in other words, the whole array assignment is masked so that it only applies to specified elements. Masked array assignment is achieved using the WHERE statement:
WHERE (I .NE. 0) A = B/I
the effect of this statement is to perform the assignment
A(j,k) = B(j,k)/I(j,k)
for all values of j and k
where the mask,
(I(j,k) .NE. 0)
, is .TRUE..
In the cases where the mask is .FALSE. no action is taken.
For example, if
and,
then
Only the indicated elements, corresponding to the non-zero elements of I, have been assigned to.
Conformable array sections may be used in place of the whole arrays, for example,
WHERE (I(j:k,j:k) .NE. 0) A(j+1:k+1,j-1:k-1) = B(j:k,j:k)/I(j:k,j:k)is perfectly valid.
Return to corresponding overview page