- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a program that opens short files prepared with a text editor as "formatted" and reads variables line by line using free-format reads. The program runs properly as an executable in a DO console window, however in the debugger all reads fail with iostat=-1. Have there been any previous reports of this problem, and have any fixes been posted?
The code is along the lines
integer, parameter :: input = 10
integer :: err
real :: value
open (input, file='text1.txt', form=formatted', iostat=ierr)
if (ierr .ne. 1) stop ! output some error message...
read(finput,*,iostat=ierr) avalue
The code is along the lines
integer, parameter :: input = 10
integer :: err
real :: value
open (input, file='text1.txt', form=formatted', iostat=ierr)
if (ierr .ne. 1) stop ! output some error message...
read(finput,*,iostat=ierr) avalue
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An iostat value of -1 is telling you that an end-of-file condition occurred.
If you're writing this as a Fortran 77 program, then you might try REWINDing your files after OPENing then but before READing from them. If you're writing this as a Fortran 95 program, then you can try POSITION='REWIND' when you OPEN your files.
Mike Durisin
If you're writing this as a Fortran 77 program, then you might try REWINDing your files after OPENing then but before READing from them. If you're writing this as a Fortran 95 program, then you can try POSITION='REWIND' when you OPEN your files.
Mike Durisin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is caused by the default directory being different when you run from inside Developer Studio rather than from a console window. Developer Studio sets the default directory to be the project directory, the one with the .DSP file, even though the executable is in the Debug or Release directory. If your program is looking for a file in the same directory as the executable, it won't find it, and instead will open a new, empty file in the project folder that will then get an end-of-file on a read.
Mike's suggestion on using REWIND is not necessary - at least not with CVF.
Steve
Mike's suggestion on using REWIND is not necessary - at least not with CVF.
Steve

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