Re: How to select a subset of an array in Fortran 90



Michel OLAGNON wrote:


B = PACK (A, Mask=(A<=Range(2).AND.A >= Range(1))) M = COUNT (A<=Range(2).AND.A >= Range(1))

... and pray that your optimizing compiler is smart enough
to detect the repetition.

... or to save your prayers you may:

logical :: mask(N)
mask = (A<=Range(2)) .AND. (A>= Range(1))
M = count(mask)
! allocate(B(M)) or whatever, depending on what B is supposed to be
B = pack(A,mask)
.