Next: MESSAGE Up: LET Previous: LET /UPPER   Contents   Index

### LET /WHERE

```        [SIC\]LET Variable = Expression /WHERE Condition_mask

The LET command allows setting variables only where  a  given  condition
mask  is  .TRUE.. The condition mask can be a logical array or a logical
expression (of same dimension as the result  variable).  Implicit  loops
can be used in conjunction to the /WHERE option.

For example
DEFINE REAL A[4,5] B[4,5]
LET B[I,J] = I+J
LET A[I,J] = (I-J)**2 /WHERE COS(I).GT.SIN(J)  ! 1
LET A[I,J] = SIN(I+J) /WHERE B.GT.5            ! 2
is  equivalent  (in terms of results, but about 500 times faster) to the
loops
DEFINE REAL A[4,5] B[4,5]
LET B[I,J] = I+J
! 1
FOR J 1 to 5
FOR I 1 to 4
IF (COS(I).GT.SIN(J)) THEN
LET A[I,J] = (I-J)**2
ENDIF
NEXT
NEXT
! 2
FOR J 1 to 5
FOR I 1 to 4
IF (B[I,J].GT.5) THEN
LET A[I,J] = SIN(I+J)
ENDIF
NEXT
NEXT

Note in the example above that implicit variables can be used.  However,
the following syntax is non valid,
LET A[I,J] = SIN(I+J) /WHERE B[I,J].GT.5
because  implicit variables cannot appear as indexes to an operand array
(B), but only as indexes to the result array (A) or as variables  as  in
SIN(I+J). The correct syntax would be
LET A[I,J] = SIN(I+J) /WHERE B.GT.5
The following syntax is also non valid
LET A = B /WHERE B[I,J].GT.LOG(I+J)
because  implicit  variables  cannot be defined by an operand array (B),
but only by the result array. The correct syntax would be
LET A[I,J] = B /WHERE B.GT.LOG(I+J)
```

Gildas manager 2014-07-01