This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Console I/O Help with g77


> > > These calls are used to clear the screen on IBM 3270 style terminals
> prior
> > > to subsequent output.  Is there an equivalent g77 command that be used
> to
> > > clear the contents of the console (e.g. issue a form feed?)?
> >
> > No.  Your CMS call is not part of the language.  I'm not familiar with
> > console I/O under W2k.  If a form feed does the trick then something like,
> >
> > write (6,'(a1)') 12
> >
> > should work.
> Hmm, I tried that and also:
> write(6,'(a1)') '\f'
> Both produced a graphic character in the console output rather than clearing
> the screen or issuing a form feed as desired.  The results that I would
> really like are equivalent to the MSDOS/Windows CLS command.  Any further
> suggestions on this problem appreciated.

I don't have a Win32 machine with gcc installed but try,

	call system ('CLS')

> > > The mainframe version of the program also contains numerous chunks of
> code
> > > similar to the following:
> > >
> > >  1315 REWIND 5
> > >  1411 WRITE(7,1412) PCS
> > >  1412 FORMAT(' ','Surface casing pressure (psi): ',F6.0)
> > >       READ(5,*,ERR=1411,END=1415) PCS
> > >
> > > g77 doesn't seem to allow a REWIND for unit 5 (console input).  Without
> the
> > > REWIND there doesn't seem to be any way to detect and handle null input
> > > (which is very important in this program to accept numerous default
> values).
> > > Is there some way to do this that I am missing?
> >
> > I used this trick a lot under DEC VMS which also allows recovery from END=
> > & ERR= on terminal input and had the same problem when porting to g77.
> > Here is my solution.  At the <label> when the 'READ (5,*,END=<label>)'
> > condition has been taken I do a 'call reset_unit_5' which clears the
> > end-of-file condition and allows it to be taken again.

> I definitely appreciate those tips and the code.  However, I think the
> behavior I am looking for may be somewhat different from what your code
> does.  In the program that is being converted, the desired behavior is as
> follows:  If the user hits Enter without entering anything, then the
> previous value of the variable that was being entered (PCS in my sample code
> above) needs to be maintained, and the user should *not* have to hit another
> key or enter another value.  On the other hand, if the user enters an

See my code below.  Under g77/Linux/Shell it does this.

> erroneous value (e.g. an invalid alpha character for a numeric variable),
> then the READ statement should be executed again so that the user can enter
> a correct value.  Part of the problem that I am seeing under Win2K is that

Can you check the contents of my 'line' variable in the code below for non 
numerics etc. and make the call again accompanied by suitable error 

> the END label branch is apparantly *never* taken.  The ERR label branch

The End branch should only be taken if glibc receives an end-of-file 
condition --eg. the user hits <ctrl>-D.  

> seems to be taken on null input instead.  Unless I am missing something, I
> don't think that your reset_unit code addresses that problem.  Perhaps this
> behavior is different on other platforms...?

My reset_unit trick is only to let the program take end/err branches 
on unit 5, more than once in the program.

	program test
	pcs=123.456 ! Before read this is the value of pcs
	call mainframe_read_real(pcs)
	print *,'pcs=',pcs ! After read this is the value of pcs

	subroutine mainframe_read_real(var)
	character *100 line

	read (5,'(a)',end=10) line
	read (line,*,err=10,end=10) dummy
10	return

Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill,
Egham, Surrey, TW20 0EX, England. 
Fax:    +44 (0) 1784 472794

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]