<Example Program>
Program impure_example
Integer :: a(7) = [ 1, 0, 0, -2, -3, 0, 4 ]
Integer :: count = 0
Where (a/=0) a = f(a)
Print *, a
Print *, count, 'elements were nonzero'
Contains
Impure Elemental Integer Function f(i)
Integer, Intent(In) :: i
f = 2*i**2 - i**3 + i
count = count + 1
End Function
End Program
|
|
Execution Results2 0 0 14 42 0 -28 4 elements were nonzero |
|