Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageReading *,* 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
Post Follow-up to this message> because the keyboard can't be end-of-filed. Not sure of that...I'd try CRTL-Z or CRTL-D. Jan
Post Follow-up to this messageHello, 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.
Post Follow-up to this messageHani 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.
Post Follow-up to this messageIn 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
Post Follow-up to this messageRon 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
Post Follow-up to this messageI'd vote for the more portable solution Dick suggested. Neither of these will work on VM, possibly other OS'.
Post Follow-up to this messageCtrl-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.
Post Follow-up to this messageKevin 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.