PDA

View Full Version : What is wrong ?


xRay
03-08-2004, 11:54 AM
I have a data file:

===start====
3
4
2
5
3
3
3
===end====

and I want read its content to array:

open (1, file='data',status='old')

do i=1,N
read (1,*) x(i)
end do

and after four digits read the program return an error:
" an endfile record was detected in a READ statement (unit=1084227584)

My qusetsion is: WHY?, what do i wrong ?
Please help.

tzeis
03-08-2004, 06:29 PM
It is pretty hard to diagnose faults given snippets of the program. From what you have provided, I would say that you are exceeding the array bounds of array x. The only evidence I have for that is the unit number in the error report is a nonsense value, not 1. Try compiling with -chk and see if the program gives you a diagnostic.

xRay
03-08-2004, 07:00 PM
Yes, you are right. i have exccedeed array length. Thx for advice.

garyscott
03-09-2004, 03:09 PM
Still, the non-sense unit number error message is worthy of investigation relative to appropriate compiler response to exceeding array bounds.

tzeis
03-09-2004, 11:52 PM
This is a tricky question, because if the compiler always detected and diagnosed array bounds violations, it could break some programs that have been working for decades. An example is when a dummy argument is dimensioned with the value "1", which occurs quite often. There is the additional issue of penalizing people who have extremely stable code and don't want to endure the slowdown due to always checking array bounds to see if they have been exceeded.
By using the -chk option, you have the diagnostic ability to properly detect a bounds problem. When debugging code, it is among the first things I do.

garyscott
03-10-2004, 02:43 PM
Yes. In this particular case, there is list directed (formatted) I/O involved which is an inherently slow process relative to any slowdown that might result from a bounds check. I know nothing of compiler design, just a comment.