Can someone explain me why the following program doesn't work, and how to make it work?
In the main program I allocate a pointer, in the subroutine sub
I look for the shape of the array and get wrong values.
program test
real, pointer, dimension(:,:,:) :: arr
allocate(arr(3,5,7))
print *, "In test: ",shape(arr)
call sub(arr)
print *, "Back in test: ",shape(arr)
end program test
subroutine sub(arr)
real, pointer, dimension(:,:,:) :: arr
print *, "In sub: ",shape(arr)
end subroutine
Output:
In test: 3 5 7
In sub: 12694064 1 3
Back in test: 3 5 7
Thanks
PS: I'm using gfortran (gcc 4.4.3)
EDIT: with gfortran 4.6, this code simply doesn't compile. I get the error:
Dummy argument 'arr' of procedure 'sub' at (1) has an attribute that requires an explicit interface for this procedure