Home > Archive > Fortran > December 2005 > Simulate End-of-file with a keystroke
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Simulate End-of-file with a keystroke
|
|
| Hani Andreas Ibrahim 2005-12-13, 7:04 pm |
| Hi,
In the code below I am able to committing a file like:
$> myprog < myfile
DO
READ(*,*,IOSTAT=Reason) a, b, c
IF (Reason > 0) THEN
... something wrong ...
ELSE IF (Reason < 0) THEN
... end of file reached ...
ELSE
... do normal stuff ...
END IF
END DO
The input will stop at the end of the file automatically. But if I call
the program with its name ($> myprog) only I can enter values
manually. To finish the input I press CTRL-D on POSIX machines.
But I didn't find out which keys I have to press to to this on a
Windows machine!
Best regards,
Hani
| |
| Dick Russell 2005-12-13, 7:04 pm |
| Reading *,* will cause the Fortran runtime to ignore blanks, including
whole blank records, and keep expecting more lines to be entered until
the I/O list is satisfied. Without a format specification, the program
will keep on trying until you kill it, because the keyboard can't be
end-of-filed. What you ought to do is to read a character string using
format '(A)' rather than *, then read your I/O list from that internal
string. If just "Enter" is pressed, the string gets loaded with blanks,
and reading from it will fail, triggering the EOF in "Reason."
character*80 string
integer reason
real a,b,c
read(*,'(A)')string
read(string,*,iostat=reason)a,b,c
if(reason.gt.0)then
write(*,*)' Something wrong'
else if(reason.lt.0)then
write(*,*)' EOF detected'
else
write(*,'('' a,b,c='',3g12.4)')a,b,c
end if
end
| |
| Jan Vorbrüggen 2005-12-13, 7:04 pm |
| > because the keyboard can't be end-of-filed.
Not sure of that...I'd try CRTL-Z or CRTL-D.
Jan
| |
| Dan Nagle 2005-12-13, 7:04 pm |
| Hello,
With a list-directed read (the second * in the read statement,
the logical record may be terminated by a / character.
HTH
Hani Andreas Ibrahim wrote:
> Hi,
>
> In the code below I am able to committing a file like:
>
> $> myprog < myfile
>
> DO
> READ(*,*,IOSTAT=Reason) a, b, c
> IF (Reason > 0) THEN
> ... something wrong ...
> ELSE IF (Reason < 0) THEN
> ... end of file reached ...
> ELSE
> ... do normal stuff ...
> END IF
> END DO
>
> The input will stop at the end of the file automatically. But if I call
> the program with its name ($> myprog) only I can enter values
> manually. To finish the input I press CTRL-D on POSIX machines.
>
> But I didn't find out which keys I have to press to to this on a
> Windows machine!
>
> Best regards,
>
> Hani
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
| |
| Donald R. Fredkin 2005-12-13, 7:04 pm |
| Hani Andreas Ibrahim <hibr@gmx.de> wrote in news:dnmot7$o8s$00$1@news.t-
online.com:
> To finish the input I press CTRL-D on POSIX machines.
>
> But I didn't find out which keys I have to press to to this on a
> Windows machine!
^Z works under Win2K.
| |
| Ron Shepard 2005-12-13, 7:04 pm |
| In article <bwCnf.16275$hB6.277@trnddc05>,
Dan Nagle <dannagle@verizon.net> wrote:
> With a list-directed read (the second * in the read statement,
> the logical record may be terminated by a / character.
This is correct, but it does not trigger the EOF condition. The
variables being read keep their original values in this case, the
same as entering a string of commas (which is how individual items
are skipped over with list-directed i/o).
As others have suggested, cntl-z (the DEC convention) and cntl-d
(the unix convention) would be two keystrokes to try.
$.02 -Ron Shepard
| |
| Hani Andreas Ibrahim 2005-12-13, 7:04 pm |
| Ron Shepard wrote:
> In article <bwCnf.16275$hB6.277@trnddc05>,
> Dan Nagle <dannagle@verizon.net> wrote:
>
>
> This is correct, but it does not trigger the EOF condition. The
> variables being read keep their original values in this case, the
> same as entering a string of commas (which is how individual items
> are skipped over with list-directed i/o).
>
> As others have suggested, cntl-z (the DEC convention) and cntl-d
> (the unix convention) would be two keystrokes to try.
Thank you all. CTRL-Z was the keystroke I was looking for.
Best regards and thanks,
Hani
| |
| gary.l.scott@lmco.com 2005-12-13, 7:04 pm |
| I'd vote for the more portable solution Dick suggested. Neither of
these will work on VM, possibly other OS'.
| |
| Kevin G. Rhoads 2005-12-13, 7:04 pm |
| Ctrl-Z (a.k.a., ^Z) is the EOF character for Text/ASCII files starting with PC-DOS 1.0
(inherited AFAIK from CP/M, which inherited this from some DEC OS ?RSX-11?) and has
been promulgated forward through MS-DOS into WinXX.
BUT it does not apply for what PC-DOS/MS-DOS called "binary" files. And since it is
a "backward compatibility" feature for WinNT/2000/XP it is not clear how long it will
be present in WinXX.
Detecting all blank lines may be more portable and safer.
| |
| Brooks Moses 2005-12-14, 9:59 pm |
| Kevin G. Rhoads wrote:
> Ctrl-Z (a.k.a., ^Z) is the EOF character for Text/ASCII files starting with PC-DOS 1.0
> (inherited AFAIK from CP/M, which inherited this from some DEC OS ?RSX-11?) and has
> been promulgated forward through MS-DOS into WinXX.
>
> BUT it does not apply for what PC-DOS/MS-DOS called "binary" files. And since it is
> a "backward compatibility" feature for WinNT/2000/XP it is not clear how long it will
> be present in WinXX.
>
> Detecting all blank lines may be more portable and safer.
Alternately, there's the convention from Unix email (and email-like)
programs of treating a line containing only a single "." as the end of
the file.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
|
|
|
|
|