WHERE (mask) array-assignment-statement
The WHERE mask must be conformable with the array on the left of the assignment (which must be conformable with the expression on the right of the assignment). For all those mask elements that have the value .TRUE. the corresponding element assignments take place; where the mask is .FALSE. the assignment is not made. A typical example of the use of masked array assignment is
WHERE (C.gt.0) A = B/Cwhich suppresses the division and assignment for those elements of that have value zero (or negative, in this case). By the rules of conformability, arrays , , and are all conformable and the (array-valued) logical expression C.gt.0 is therefore a mask conformable with these arrays. It is often the case that, as in this example, a WHERE mask is the result of a logical expression involving one or more of the assignment operation operands.
Several assignments can be placed under the control of a single mask, in which case the WHERE takes a block form:
WHERE (mask) array-assignment-1 array-assignment-2 ... END WHEREAny number of array assignments can be grouped in this manner; of course, they all have to be conformable with the mask.
The forms of WHERE described above leave unassigned some elements of the array on the left hand side of the assignment statement. An extension of the block form of WHERE, the ELSEWHERE option, allows a value to be given to the left-hand-side array elements where the mask is .FALSE. This takes the form:
WHERE (mask) array-assignment-1 array-assignment-2 ... ELSEWHERE array-assignment-n+1 ... END WHEREA simple example of this last form of WHERE is
WHERE (C.gt.0) H = B/C ELSEWHERE H = B END WHEREIn this case those elements of for which is less than or equal to zero are simply assigned the corresponding value of . This is an important form of WHERE, because it results in a fully defined array that can be used in subsequent array operations. Without the ELSEWHERE the array H might end up not being fully defined, in which case it cannot be used in other array expressions.