I just stumbled upon the fact that the compiler allows me to use whole arrays as indices for other arrays. For instance:
implicit none
real*8 :: a(3), b(2)
integer :: idx(2)
a=1.d0
idx=(/1,2/)
b = a(idx)
print*,shape(b)
print*,b
print*
end
Given the fact that this seems to work with both gfortan and the PGI compiler, I wonder if this can use the language, not the compiler. I would appreciate if someone more knowledgeable than me could comment on if this is really a language feature.
And if this is so, then I would appreciate if someone sets out the exact language rules for how such constructions are interpreted in the multidimensional case, for example:
implicit none
real*8 :: aa(3,3), bb(2,2)
integer :: idx(2)
do i=1,3 ; do j=1,3
aa(i,j) = 1.d0*(i+j)
enddo; enddo
bb=aa(idx,idx)
print*,shape(bb)
print*,bb
end
ev-br source
share