next up previous contents index
Next: Size casting Up: Variables and Expressions Previous: Implicit Loops   Contents   Index

Conditional Assignment

Another convenient function is to assign to an array new values only in for some parts of the array, based on a logical mask or logical expression. The option /WHERE of command LET allows such operations. For example

      DEFINE REAL A[10,10]
      LET A[I,J] = EXP(-((I-5)|2)**2-((J-6)|3)**2) /WHERE (I+J).LT.10
will set only a part of the A array (note that I and J are ``implicit variables'').

The preceding expression is equivalent to the following commands

      DEFINE REAL A[10,10]
      FOR J 1 TO 10      
      FOR I 1 TO 10
        IF (I+J).LT.10 THEN
          LET A[I,J] = EXP(-((I-5)|2)**2-((J-6)|3)**2)
        ENDIF
      NEXT
      NEXT
but it executes thousands of times faster...

Conditional assignment can be mixed with implicit loops, as shown above, but there are some syntax restrictions: please refer to the internal help for more details.



Gildas manager 2014-07-01