Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Simulate End-of-file with a keystroke
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

Report this thread to moderator Post Follow-up to this message
Old Post
Hani Andreas Ibrahim
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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


Report this thread to moderator Post Follow-up to this message
Old Post
Dick Russell
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
> because the keyboard can't be end-of-filed.

Not sure of that...I'd try CRTL-Z or CRTL-D.

Jan

Report this thread to moderator Post Follow-up to this message
Old Post
Jan Vorbrüggen
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Dan Nagle
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Donald R. Fredkin
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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

Report this thread to moderator Post Follow-up to this message
Old Post
Ron Shepard
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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


Report this thread to moderator Post Follow-up to this message
Old Post
Hani Andreas Ibrahim
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
I'd vote for the more portable solution Dick suggested.  Neither of
these will work on VM, possibly other OS'.


Report this thread to moderator Post Follow-up to this message
Old Post
gary.l.scott@lmco.com
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
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 sin
ce it is
a "backward compatibility" feature for WinNT/2000/XP it is not clear how lon
g it will
be present in WinXX.

Detecting all blank lines may be more portable and safer.

Report this thread to moderator Post Follow-up to this message
Old Post
Kevin G. Rhoads
12-14-05 12:04 AM


Re: Simulate End-of-file with a keystroke
Kevin G. Rhoads wrote:
> Ctrl-Z (a.k.a., ^Z) is the EOF character for Text/ASCII files starting wit
h 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 s
ince it is
> a "backward compatibility" feature for WinNT/2000/XP it is not clear how l
ong 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Brooks Moses
12-15-05 02:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:36 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.