02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

WHERE (statement and construct)<br />

The first two assignment statements are processed for elements corresponding to true<br />

elements of the mask. The second two assignment statements are processed for elements<br />

corresponding to false elements of the mask. Unlike the ELSE clause of an IF statement, the<br />

assignment statements in both the WHERE and ELSEWHERE parts are processed.<br />

Note the different behavior of the calls to ABS. In evaluating the mask expression, the entire<br />

VALUES array is passed to ABS, producing an array result whose elements are then compared<br />

to 10. In the assignment statement, however, ABS is only invoked for those particular<br />

elements of VALUES corresponding to true elements of the mask. Also, note the mixed use of<br />

arrays and scalars in the assignment statement expressions.<br />

The mask expression must have the same shape as the arrays in the assignment statements,<br />

but it might involve completely separate arrays. In the following example, A, B, andC can be<br />

independent of D and E, as long as they are all conformable:<br />

WHERE (a+b .EQ. c) d = SIN(e)<br />

The following example illustrates why the order of processing is important for dependency<br />

reasons:<br />

REAL a(100)<br />

REAL b(100)<br />

EQUIVALENCE b, a<br />

WHERE(a(1:20:1) .GT. 0) a(20:1:-1) = -1.0<br />

WHERE(a(61:100:2) .LT. 1) b(20:1:-1) = a(1:20:1) * 100.0<br />

In the first WHERE statement, changing elements of a in the assignment might be thought to<br />

affectthemaskexpression.However,becausethemaskisevaluatedbeforetheassignmentis<br />

processed, the behavior of this statement is well defined. A similar situation arises in the<br />

second WHERE statement. Assignment values to elements of the assignment variable b alter<br />

the elements of the assignment expression a * 100.0. Because the assignment expression is<br />

evaluated for all true elements of the mask before any transfer of values to B, the behavior is<br />

again well defined.<br />

It is important to note that assignment statements in a WHERE construct are processed<br />

sequentially. In the next example, the second assignment is not processed until the first is<br />

completely finished. This means that the values of b used in the second assignment have been<br />

modified by the first statement:<br />

WHERE (SQRT(ABS(a)) .gt. 3.0)<br />

b = SIN(a)<br />

c = SQRT(b)<br />

ENDWHERE<br />

Related statements<br />

END (construct) and ELSEWHERE<br />

460<br />

Chapter 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!