next up previous contents
Next: Vector-valued Subscripts Up: Arrays Previous: Masked Assignment - Where

 

Masked Assignment - Where Construct

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 nestedgif.

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.

Now try this question gif


next up previous contents
Next: Vector-valued Subscripts Up: Arrays Previous: Masked Assignment - Where

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.