- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code below triggers the runtime error: "forrtl: severe (268): end of record during read, unit 20, file .....". Lines 11 and 13 do not produce the same outcome, is this expected?
PROGRAM P IMPLICIT NONE INTEGER :: LINE_SIZE CHARACTER(LEN=15) :: BUFFER OPEN(UNIT=20,FILE='test.txt',STATUS='REPLACE') WRITE(20,FMT='(A)') '1234567890' WRITE(20,FMT='(A)') 'abcdefghij' WRITE(20,FMT='(A)') ')(@&%*((@!' CLOSE(20) OPEN(UNIT=20,FILE='test.txt',STATUS='OLD') READ(20,FMT='(A)') BUFFER REWIND(20) READ(20,FMT='(A)',ADVANCE='NO',SIZE=LINE_SIZE) BUFFER CLOSE(20) END PROGRAM P
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok - there is probably no problem here. The modified code below works as intended, maybe this will be helpful to somebody. One simply needs to guard against the EOR condition.
PROGRAM P USE ISO_FORTRAN_ENV,ONLY : IOSTAT_EOR,IOSTAT_END IMPLICIT NONE INTEGER :: LINE_SIZE,IO_ERROR CHARACTER(LEN=15) :: BUFFER OPEN(UNIT=20,FILE='test.txt',STATUS='REPLACE') WRITE(20,FMT='(A)') '1234567890' WRITE(20,FMT='(A)') 'abcdefghij' WRITE(20,FMT='(A)') ')(@&%*((@!' CLOSE(20) OPEN(UNIT=20,FILE='test.txt',STATUS='OLD') READ(20,FMT='(A)') BUFFER REWIND(20) READ(20,FMT='(A)',ADVANCE='NO',SIZE=LINE_SIZE,IOSTAT=IO_ERROR) BUFFER IF ((IO_ERROR==IOSTAT_EOR).OR.(IO_ERROR==IOSTAT_END)) IO_ERROR = 0 IF (IO_ERROR/=0) THEN STOP END IF CLOSE(20) WRITE(*,*) LINE_SIZE END PROGRAM P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A useful chap that IOSTAT I never do a read / write / open / close without one!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page