fortran run time error

when we get this error

“PGFIO-F-217/formatted attempt to read past end of file”

& what can we do to eliminate this error

Please help me,

what can we do to eliminate this error

All we know from this error is that your program tried to continue reading a file after it reach the end. What type of file is it trying to read? How is the file being accessed? What does your open statement look like? What format is the data? How was the file’s data created?

Most likely your program is expecting the file to be in one format but it’s in another.

  • Mat

If you’re doing unformatted IO then Fortran will include record indicators, and an entire record is typically consumed by each read statement whether or not you request all the data.

OPEN(unit,file=myfile.dat, form='UNFORMATTED')
WRITE(unit) foo1, foo2, foo3
WRITE(unit) bar1, bar2, bar3
CLOSE(unit)

...

OPEN(unit,file=myfile.dat, form='UNFORMATTED')
READ(unit) foo1
READ(unit) foo2 ! This will likely be bar1, not foo2!
CLOSE(unit)

In the above example the two read statements will likely consume all the data written by the two write statements. In formatted files the newline character is the marker of the end of the record, so after each read statement the file will be positioned at the next line (unless the ADVANCE=‘NO’ specifier is used.