Control-D not closing unit 5 in list-directed input
John Nabelek
nabelek@coas.oregonstate.edu
Sat Jan 26 08:54:00 GMT 2008
Hi Jerry,
here is a small test program which reads a number from a terminal. It
works with g77. If Control-D is pressed, code accepts the default
value of 999. In case of an error (e.g., if you enter a character),
the number is read again. Subroutine bs5 restores unit 5 for input
after it was closed.
-John
Main.f:
number=999
30 write(6,*) 'Enter number1?'
read(5,*,iostat=ios) number
write(6,*) 'ios= ',ios
call bs5(ios)
if(ios) 20,20,10
10 write(6,*) 'Input Error'
go to 30
20 write(6,*) number
60 write(6,*) 'Enter number2?'
read(5,*,iostat=ios) number
write(6,*) 'ios= ',ios
call bs5(ios)
if(ios) 50,50,40
40 write(6,*) 'Input Error'
go to 60
50 write(6,*) number
end
bs5.f:
subroutine bs5(ios)
character *20 name
if(ios.ge.0) go to 20
name=TtyNam(5)
close (unit=5)
open(unit=5,file=name,status='old')
20 return
end
On Jan 25, 2008, at 1:48 PM, Jerry DeLisle wrote:
> John Nabelek wrote:
>> I would like to report a problem in gfortran IO.
>> Normally (in f77, g77) one could enter Control-D to close unit 5
>> for input (and thus accept default values).
>> In gfortran this works for 'formatted' input but not 'list-
>> directed' input.
>> With a statement such as
>> read(5,*,iostat=ios) number
>> entering Control-D has no effect. The program just sits at this
>> statement and does not continue. In f77 and g77, Control-D at this
>> line would close unit 5 and continue execution.
>> Would it be possible to make gfortran behave as f77 and g77 did?
>> Cheers -John
> Can you provide a small working example of a complete program so
> that I can explore this?
>
> How do you define a "default value" ?
>
> Jerry
More information about the Fortran
mailing list