Array bounds and errors with implied do loop.

Array bounds and errors with implied do loop.

I am modifying an old program written for a main frame in Fortran 77. I am having trouble with this implied do loop:

WRITE (6,7600) (TI(NDPLET,J),J=1,10), NAM(ISO), NDPLET, ISO,
(TABLEX(NDPLET,ISO,I),I=1,12), (TABLEY(NDPLET,ISO,I),I=1,12)
WRITE (9,7600) (TI(NDPLET,J),J=1,10), NAM(ISO),NDPLET, ISO,
(TABLEX(NDPLET,ISO,I),I=1,12), (TABLEY(NDPLET,ISO,I),I=1,12)

The arrays are dimensioned as follows: TI(20,1) ; NAM (20) ; TABLEX(30,20,12)
TABLEY(30,20,12)

It seems that the do loop isn't stopping. When i used the debugger the check the values, it gave all the I values as 13, but all the J values as 1. If I set the value of I equal to one or zero before this write statement, I still get the same error message.

Suggestions?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

One problem is that you have dimensioned TI(20,1) but are then trying to write out (TI(NDPLET,J),J=1,10). Since the second dimension is set to 1, this will cause an array bounds error since J is going from 1 to 10. I haven't looked at the other arrays, but this is certainly one problem.

Tom

Thanks fto Tom for pointing this out. I entered the dimensions wrong here. These is the right one:

TI(30,10)

I've been trouble-shooting some more and still can't find the problem. Andy helo would be appreciated.

It would help to know what the error message says.
I wouldn't read too much into the values of I and J that you are seeing
in the debugger. If you are single-stepping through the program you can
only see the values of the variables before the implied do loop gets
executed or after it is done, not while it is actually looping.
It is a fairly common thing to see the value of a loop counter equal to 1 more than the end value of a loop after it is done, although you should never assume that this always going to be true. You really can't count
on any particular result for a loop counter outside of its scope.

The easiest way to find out where the problem is occurring is to rewrite the code eliminating the implied DO loops - make them explicit. Then, when debugging, the debugger will stop on the offending line and you can examine the values of the indices and the arrays that use the indices. It shouldn't take more than a few minutes to find the problem.

Tom

Login to leave a comment.