There was a bug in how the code was handling breaking out of the loops when the end of the file was reached. A quick fix is to add the backspace line I've indicated below with an arrow (please don't include the arrow in your source).
!If end of file, break out of loop.
!If some other error, abort.
!If no error, back up one line.
!Above we checked the first frame
! for whether the data was as expected.
!If there is a read error here we are
! not specific about the problem.
read(9,*,iostat=ioerror)
if (ioerror.lt.0) then
exit
else if (ioerror.gt.0) then
write(*,*) 'READ ERROR'
stop
else
backspace(9)
end if
do
read(9,*,iostat=ioerror)
if (ioerror.lt.0) then
backspace(9) <-----------------------------------------------
exit
else if (ioerror.gt.0) then
write(*,*) 'READ ERROR'
stop
end if
|