I had occasion to compile a program that used Lapack/BLAS routines, and needed to compile the needed BLAS routines with /check. FTN95 detects a subscript error in a situation where (I think) that it should not. In order to make the error easy to investigate, I have constructed a short reproducer.
The test program takes a 4 X 4 matrix C, and copies rows 2-4 and columns 2-4 into a 3 X 3 matrix D.
program xsubmat
implicit none
real C(4,4),D(3,3)
integer i,j,ldc,ldd,m,n
!test of copying C(2:4,2:4) into D, with subscript checking
do i=1,4
do j=1,4
C(i,j)=10*j+i
end do
end do
ldc=4; ldd=3; m=3; n=3
call sub(C(2,2),ldc,D,ldd,m,n)
print 10,(D(i,:),i=1,m)
10 format(3F6.0)
end program
subroutine sub(C,ldc,D,ldd,m,n)
implicit none
integer i,ldc,ldd,m,n
real C(ldc,*),D(ldd,*)
do i=1,m
D(1:n,i)=C(1:n,i)
end do
return
end subroutine
The Fortran 95 standard, section 12.4.1.1, says:
Except when a procedure reference is elemental (12.7), each element of an array-valued actual argument or of a sequence in a sequence association (12.4.1.4) is associated with the element of the dummy array that has the same position in array element order (6.2.2.2). My inference is that it should be OK to copy the sequence starting with C(2,2), which has 11 elements, 9 of which I wish to put into D.
In the debugger, after entering the subroutine, the variable list shows the effective dimensions of C in the subroutine as 4 X 2. It is debatable what it should show. However, there is no subscript error in the array copy. Please tell me if you do or do not agree.