Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Array bounds and errors with implied do loop.

Intel_C_Intel
Employee
530 Views
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?
0 Kudos
4 Replies
Intel_C_Intel
Employee
530 Views
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
0 Kudos
Intel_C_Intel
Employee
530 Views
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.
0 Kudos
Intel_C_Intel
Employee
530 Views
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.
0 Kudos
Intel_C_Intel
Employee
530 Views
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
0 Kudos
Reply