Saul Teukolsky
03-14-2002, 09:01 AM
A reader has written to report that the absoft f90 compiler reports an array out-of-bounds error from the array section b(1+i:i+l-1) in line 20 of banbks.f90. On the first pass through the enclosing do loop, i=n and l=1, so the array section is b(n+1:n), which is a zero length array and should therefore be zero. However, b is of length n, so the compiler first reports an out-of-bounds error for b(n+1).
While I doubt that the f90 standard covers this, I nevertheless believe this is a problem with the compiler, not the code. For example, in Metcalf and Reid's book, section 6.10 in my old edition, they say:
Normally, we expect the values of both "lower" and "upper" to be within the bounds of the corresponding array subscript. However, all that is required is that each value actually used to select an element is within the bounds. Thus
A(1, 2:11:2)
is legal even if the upper bound of the second dimension of A is only 10.
Of course, a simple workaround is to do the i=n
case of the loop explicitly:
b(n)=b(n)/a(n,1)
and then let the loop start at i=n-1.
While I doubt that the f90 standard covers this, I nevertheless believe this is a problem with the compiler, not the code. For example, in Metcalf and Reid's book, section 6.10 in my old edition, they say:
Normally, we expect the values of both "lower" and "upper" to be within the bounds of the corresponding array subscript. However, all that is required is that each value actually used to select an element is within the bounds. Thus
A(1, 2:11:2)
is legal even if the upper bound of the second dimension of A is only 10.
Of course, a simple workaround is to do the i=n
case of the loop explicitly:
b(n)=b(n)/a(n,1)
and then let the loop start at i=n-1.