Re: Index of array from mask



Michael Metcalf wrote:
"dpb" <none@xxxxxxx> wrote in message news:fvad2l$tmh$3@xxxxxxxxxxx
Thomas Koenig wrote:

I think he was looking for an intrinsic on the order of COUNT() or
MAXLOC() but that would return the locations of array elements meeting the
mask conditions...

That isn't available directly...

Maybe:

program main
implicit none
integer, dimension(5) :: v
integer :: a, b, i
v = (/103,102,103,104,105/)
a = 102
b = 105
write (*,*) pack(v, mask = v > 102 .and. v <105)
end program main

Instead, how about:

program blah
implicit none
integer, dimension(5) :: v
integer :: a, b, i
v = (/103,102,103,104,105/)
a = 102
b = 105
write (*,*) pack((/(i,i=1,5)/), mask = v > 102 .and. v <105)
end program blah


?

lnx:scratch : gfortran blah.f90
lnx:scratch : a.out
1 3 4



cheers,

paulv
.