next up previous contents
Next: Masked Assignment - Where Up: Arrays Previous: Deallocating Arrays

 

Masked Assignment - Where Statement

 

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

displaymath27970

and,

displaymath27971

then

displaymath27958

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.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Masked Assignment - Where Up: Arrays Previous: Deallocating Arrays

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.