Why does the following code not yield a mismatch error when we call the MakeAllZero
subroutine? The variable array
is initialised as a 3x3 array, but once we call the subroutine a do loop travels from index 1 to 9 where I would expect a mismatch error.
I do not understand the trick done by the assumed-size array declaration in the subroutine. I would appreciate if anyone could help me better understand it.
program main
implicit none
real, dimension(3, 3) :: array
array = reshape([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ], shape(array))
call MakeAllZero(array,9)
print*, array
end program main
subroutine MakeAllZero(R,K)
implicit real (A-H,O-Z)
dimension R(*)
do J=1,K
R(J) = 0.0
end do
return
end subroutine MakeAllZero