- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm running into some oddities with formatted stream access (is that supported??). The attached dies when run under the VS debugger with a heap corruption report from the C library. When compiled and run from the command prompt (/check:all /warn:all) it appears to get a little confused. Larger versions of the code descend into merry chaos before going belly up.
(Compiled with 11.1.054 under VS2005. Change the filename in the open statement to be any text file that has more than two characters in the first line to see the problem).
[fortran]PROGRAM FormattedStream
IMPLICIT NONE
INTEGER, PARAMETER :: unit = 10
CHARACTER :: c
INTEGER :: stat
!****
OPEN( UNIT=unit, FILE='FormattedStream.f90', ACTION='READ', &
FORM='FORMATTED', ACCESS='STREAM', STATUS='OLD', IOSTAT=stat )
IF (stat /= 0) STOP "Couldn't open the file :("
READ(unit, 100, IOSTAT=stat, ADVANCE='NO') c
IF (stat /= 0) STOP "Couldn't read the first char :("
WRITE (*, 100) 'The first char was a "' // c // '" :)'
READ(unit, 100, IOSTAT=stat, ADVANCE='NO') c
IF (stat /= 0) STOP "Couldn't read the second char :("
WRITE (*, 100) 'The second char was a "' // c // '" :)'
CLOSE(unit)
100 FORMAT(A)
END PROGRAM FormattedStream
[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
I don't particularly want to read character by character - I was just looking for a common (in compiler and platform sense) solution to the files that have an incomplete final record (as per recent discussion on c.l.f). Ideally I'd be reading into a buffer of some arbitrary size, and concatenating buffers together if they weren't big enough to hold the text in a particular record.
I think unformatted stream then means I have to deal with different line termination characters/sequences for different platforms?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suppose so, but the standard says:
36 (1) Some file storage units of the file may contain record markers; this imposes a record structure37 on the file in addition to its stream structure. There might or might not be a record marker
38 at the end of the file. If there is no record marker at the end of the file, the final record is
39 incomplete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page