[comp.lang.fortran] avoiding newline after end of WRITE string

ae219dp@prism.gatech.EDU (Devon Prichard) (02/02/90)

it's probably way too user-friendly for Fortran, but waht I want
to do is;

         WRITE(*, ... ) (' enter number of widgets; ')
         READ(*,*) NWIDGET

(where the WRITE format ... means whatever technique is necessary)
in such a way that the terminal does not recieve a newline after
the WRITE statement has been processed.  it has to be ANSI standard
Fortran 77 (I know it can be done on HP's and VAXen, but I need it
to be portable).

this way, I can read in a lot of data on the same screen, without having
previous questions and answers scroll away... the scheme will be used
for terminal I/O on a variety of terminals, from VT-100 to Tek 4014
to ...

thanx in retreat,


-- 
 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 | Devon Prichard             making the world safe for helicopters ... |
 | ae219dp@prism.gatech.edu                                             |
 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

maine@elxsi.dfrf.nasa.gov (Richard Maine) (02/02/90)

On 1 Feb 90 21:27:30 GMT, ae219dp@prism.gatech.EDU (Devon Prichard) said:

Devon> it's probably way too user-friendly for Fortran, but waht I want
Devon> to do is;

Devon>          WRITE(*, ... ) (' enter number of widgets; ')
Devon>          READ(*,*) NWIDGET

Devon> (where the WRITE format ... means whatever technique is necessary)
Devon> in such a way that the terminal does not recieve a newline after
Devon> the WRITE statement has been processed.  it has to be ANSI standard
Devon> Fortran 77 (I know it can be done on HP's and VAXen, but I need it
Devon> to be portable).

Yer' out of luck if you want it to be ANSI standard (unless you are
willing to wait for ANSI Fortran 90 compilers; this is included in
the Fortran 90 standard - er, I mean proposed standard).  For Fortran
77 it cannot be done while sticking to the standard or even a universally
accepted extension.  The Vax way (with a '$' format descriptor) works
on a lot of systems, but not all.  Its probably as close as you can come
to a widely adopted way in Fortran 77.

Your best bet is to accept the system dependence, but isolate it.
Write a subroutine something like:

      subroutine prompt(msg)
      character msg*(*)
      write (*,'(a,$)') msg
      return
      end

and then call it wherever you need such prompts.
This sample, by the way, uses the common (but not universal) $ format
descriptor that I mentioned above.

This doesn't make your code portable in the sense of being usable
unchanged on all systems, but careful isolation of the system
dependencies like this can make the code "portable" in the literal
sense of the word; it is possible to port it, and it is even relatively
easy.

Of course, when doing it for "real", you'd include some comments
about the system-dependence, mention it in the program documentation,
and presumably separate such system-dependent routines into a
separate file to make them easy to find.
--

Richard Maine
maine@elxsi.dfrf.nasa.gov [130.134.64.6]

whit@milton.acs.washington.edu (John Whitmore) (02/02/90)

In article <5588@hydra.gatech.EDU> ae219dp@prism.gatech.EDU (Devon Prichard) writes:
>it's probably way too user-friendly for Fortran, but waht I want
>to do is;
>
>         WRITE(*, ... ) (' enter number of widgets; ')
>         READ(*,*) NWIDGET
>
>(where the WRITE format ... means whatever technique is necessary)
>in such a way that the terminal does not recieve a newline 

	When I needed to do this, I used a standard manual and came
up with a way that works (on a VAX) without using nonstandard 
statements or formats.  I opened the output file FILE='TT:'
for the terminal output, as FORM='UNFORMATTED'.  Subsequent
writes to the unformatted unit gave prompts as you specify,
and when CR/LF was needed, I just wrote those (or used another
unit with TT: opened FORMATTED). 
	This depends on a filename being available which translates
to "terminal_output", so may be system-dependent anyhow.  At least
if it doesn't work, the syntax will still pass for standard Fortran.

I am known for my brilliance,            John Whitmore
 by those who do not know me well.

maine@elxsi.dfrf.nasa.gov (Richard Maine) (02/03/90)

On 2 Feb 90 07:05:23 GMT, whit@milton.acs.washington.edu (John Whitmore) said:

John> 	When I needed to do this, I used a standard manual and came
John> up with a way that works (on a VAX) without using nonstandard 
John> statements or formats.  I opened the output file FILE='TT:'
John> for the terminal output, as FORM='UNFORMATTED'.  Subsequent
John> writes to the unformatted unit gave prompts as you specify,
John> and when CR/LF was needed, I just wrote those (or used another
John> unit with TT: opened FORMATTED). 
John> 	This depends on a filename being available which translates
John> to "terminal_output", so may be system-dependent anyhow.  At least
John> if it doesn't work, the syntax will still pass for standard Fortran.

The syntax, yes, but several of the semantic issues may be very tricky.
You mentioned the availablity of appropriate file names.  Another
problem is that you have 2 units open for the same device.  This can
cause lots of problems, the simplest possibility being that the system
may just refuse to do it.  All in all, I'd say this was less portable
than the $ format.  Sure, it will compile; but it might not run at
all on some systems.

Regardless of whether one uses this approach, the $ format descriptor,
or some other approach on the Vax, they are all system dependent.
Thus, the most important thing is to isolate and document the dependence
as in my comments in my prior posting.  The approach John suggested
is certainly useable as one of the system-specific implementations of
my suggested "prompt" (or choose your own name) routine.
--

Richard Maine
maine@elxsi.dfrf.nasa.gov [130.134.64.6]