Hello,
The MERGE function seems to use temporary arrays for both, tsource and fsource, arguments when the program is compiled in the Debug mode. Hence, the following simple code throws an exception:
real :: pos(3) = [.1, .2, .3] real :: neg(2) = [.8, .9] integer :: ptrs(5) = [1, 2, -1, -2, 3] ! Index in (pos) if positive, minus index in (neg) if negative real :: vals(5) vals = merge(pos(ptrs), neg(-ptrs), ptrs > 0)
forrtl: severe (408): fort: (3): Subscript #1 of the array NEG has value -1 which is less than the lower bound of 1
This modification also doesn't work:
forall (i = 1:5) vals(i) = merge(pos(ptrs(i)), neg(-ptrs(i)), ptrs(i) > 0)
In the Release mode both work fine.
Why does MERGE need to compute both arguments in the Debug mode and is there an elegant way to rewrite this code without going into dumb for-if-else-then constructions?
Thank you.