Software Archive
Read-only legacy content
17060 Discussions

files not read properly when in debugger

Intel_C_Intel
Employee
430 Views
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
0 Kudos
2 Replies
durisinm
Novice
430 Views
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
0 Kudos
Steven_L_Intel1
Employee
430 Views
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
0 Kudos
Reply