- Masked Array Assignment
- A ``mask" is an
array of type logical. A masked
array operation is one in which a mask conformable to the
result of the operation is used to specify that only a
subset of the parallel element operations are to be
performed. This functionality is available in some of the
intrinsic functions and for array assignment. In the latter
case an array-valued assignment is placed under mask control
in a WHERE statement, the general form of which is:
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/C

which 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 WHERE

Any 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 WHERE

A simple example of this last form of WHERE isWHERE (C.gt.0) H = B/C ELSEWHERE H = B END WHERE

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