Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] WRITE without newline?

148 views
Skip to first unread message

Steven G. Johnson

unread,
May 26, 1998, 3:00:00 AM5/26/98
to

This is a very simple question I'm sure, but I don't have a Fortran manual
and I need to modify some of our code.

How do you do the equivalent of a WRITE statement without appending a
newline? I want to do several disjoint WRITE's that output onto the same
line.

Thanks very much for your help!

Cordially,
Steven G. Johnson

Peter Smulders

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

Steven G. Johnson <ste...@alum.mit.edu> wrote:
> This is a very simple question I'm sure, but I don't have a Fortran manual
> and I need to modify some of our code.

> How do you do the equivalent of a WRITE statement without appending a
> newline? I want to do several disjoint WRITE's that output onto the same
> line.

Don't be too sure! What you want is not a standard ANSI 77 feature,
but a widely available extension is the $ edit descriptor.
Terminating the format specification with a $ causes the cursor
to remain on the same line in such a Fortran.
--
Peter

Mike Aspden

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

There is a standard Fortran90/95 method of doing it by using
non-advancing IO:

write(*,"(A)",advance="no") "One "
write(*,"(A)",advance="no") "two "
write(*,"(A)") "three"

Note that an explicit format descriptor is needed when using
non-advancing
IO.

Oleg Rokach

unread,
May 27, 1998, 3:00:00 AM5/27/98
to


Steven G. Johnson <ste...@alum.mit.edu> wrote in article
<stevenj-ya0240800...@news.mit.edu>...


> This is a very simple question I'm sure, but I don't have a Fortran
manual
> and I need to modify some of our code.
>
> How do you do the equivalent of a WRITE statement without appending a
> newline? I want to do several disjoint WRITE's that output onto the same
> line.
>

> Thanks very much for your help!
>
> Cordially,
> Steven G. Johnson
>

C For printing in the same line just use an "+" at the first position in
output list.
C ( this possibility is available since FORTRAN 66 !)
C ----------------
integer i
do i = 1, 10000
write (*,'(A,2x,I5)') '+ Number= ', i
enddo
end


Juergen von Hagen

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

Oleg Rokach wrote:
>
...

> C For printing in the same line just use an "+" at the first position in
> output list.
> C ( this possibility is available since FORTRAN 66 !)
> C ----------------
> integer i
> do i = 1, 10000
> write (*,'(A,2x,I5)') '+ Number= ', i
> enddo
> end
but then you need probably an output filter like fpr on DEC Unix
machines (exists also on SUN).
out of man fpr:

______________________________________________________
Character Vertical Space Before Printing
______________________________________________________
Blank One line
0 Two lines
1 To first line of next page
+ No advance
$ or ASCII NUL One line; no return after printing
______________________________________________________


cheers
juergen

Ralph Jay Frisbie

unread,
May 28, 1998, 3:00:00 AM5/28/98
to

On 27 May 1998 16:02:13 GMT, "Oleg Rokach" <rok...@ncac.torun.pl>
wrote:

>
>
>Steven G. Johnson <ste...@alum.mit.edu> wrote in article
><stevenj-ya0240800...@news.mit.edu>...
>> This is a very simple question I'm sure, but I don't have a Fortran
>manual
>> and I need to modify some of our code.
>>
>> How do you do the equivalent of a WRITE statement without appending a
>> newline? I want to do several disjoint WRITE's that output onto the same
>> line.
>>
>> Thanks very much for your help!
>>
>> Cordially,
>> Steven G. Johnson
>>
>

>C For printing in the same line just use an "+" at the first position in
>output list.
>C ( this possibility is available since FORTRAN 66 !)
>C ----------------
> integer i
> do i = 1, 10000
> write (*,'(A,2x,I5)') '+ Number= ', i
> enddo
> end
>
>
>

Try this, however I've worked with systems where
only the last item written appears, i.e., the screen cursor
returns to column one of the display and thus the new write
overwrites the information already there. This often happens
so fast it's invisible, so you think the write is wrong.....
ralph frisbie

Ralph Frisbie
a saucer lover
but not the inventor..

ARya...@my-dejanews.com

unread,
May 29, 1998, 3:00:00 AM5/29/98
to

> > How do you do the equivalent of a WRITE statement without appending a
> > newline? I want to do several disjoint WRITE's that output onto the same
> > line.

> C For printing in the same line just use an "+" at the first position in


> output list.
> C ( this possibility is available since FORTRAN 66 !)
> C ----------------
> integer i
> do i = 1, 10000
> write (*,'(A,2x,I5)') '+ Number= ', i
> enddo
> end

Yes! it'll be print on the same line but from the begining of the line!
I think, the question was how to continue printing on the same line.
It is depend on compiler. For example MS Fortran use back slash format
specify:

WRITE(*,1000)
1000 FORMAT(' Input value for I - ' \)
READ(*,*) I

As I remeber some other compiler use '$' instead '\'

Hope this can help!

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading

Fred Hawes

unread,
May 29, 1998, 3:00:00 AM5/29/98
to

Hi,

Ralph Jay Frisbie wrote:
> On 27 May 1998 16:02:13 GMT, "Oleg Rokach" <rok...@ncac.torun.pl>
> wrote:
>

> >Steven G. Johnson <ste...@alum.mit.edu> wrote ...
...


> >> How do you do the equivalent of a WRITE statement without appending a
> >> newline? I want to do several disjoint WRITE's that output onto the same
> >> line.

...


> >
> >C For printing in the same line just use an "+" at the first position in
> >output list.
> >C ( this possibility is available since FORTRAN 66 !)
> >C ----------------
> > integer i
> > do i = 1, 10000
> > write (*,'(A,2x,I5)') '+ Number= ', i
> > enddo
> > end
> >

> Try this, however I've worked with systems where
> only the last item written appears, i.e., the screen cursor
> returns to column one of the display and thus the new write
> overwrites the information already there. This often happens
> so fast it's invisible, so you think the write is wrong.....
> ralph frisbie

I remember that working in Fortran-66, *but* I find it doesn't work
in (the locally available version of) Fortran-77, at least not
for writes to standard input. Perhaps it only works for file-writes?

The original poster's question was slightly ambiguous.
If what he wants is to do several contiguous writes on the same line,
without overwriting the previous stuff, the way to do it is to end the
formats with a $-sign:


Num1 = 30
Num2 = 500

write(*,'(A,2x,I5,$)') ' First is ',Num1
write(*,'(A,2x,I5,$)') ' ; Second is ',Num2
write (*,*)


Regards,
Fred Hawes


Oleg Rokach

unread,
Jun 1, 1998, 3:00:00 AM6/1/98
to

Hi,

Ralph Jay Frisbie wrote:
> On 27 May 1998 16:02:13 GMT, "Oleg Rokach" <rok...@ncac.torun.pl>
> wrote:
>
> >Steven G. Johnson <ste...@alum.mit.edu> wrote ...
...
> >> How do you do the equivalent of a WRITE statement without appending a
> >> newline? I want to do several disjoint WRITE's that output onto the same
> >> line.
...
> >
> >C For printing in the same line just use an "+" at the first position in
> >output list.
> >C ( this possibility is available since FORTRAN 66 !)
> >C ----------------

> > integer i <-------------------------|


> > do i = 1, 10000 |
> > write (*,'(A,2x,I5)') '+ Number= ', i |
> > enddo |
> > end |
> > |
> Try this, however I've worked with systems where |
> only the last item written appears, i.e., the screen cursor |
> returns to column one of the display and thus the new write |
> overwrites the information already there. This often happens |
> so fast it's invisible, so you think the write is wrong..... |
> ralph frisbie |
|

This is working well for DOS/Windows ( MS compilers at least) --|
--
[==========={ Oleg Rokach }=============] |\ _,,,---,,_
[Nicolaus Copernicus Astronomical Center] ZZZzz /,`.-'`' -. ;-;;,_
[ Rabianska 8, Torun, 87-100, POLAND ] |,4- ) )-,_. ,\ ( `'-'
[ tel. (+48 56) 62 19249 ] '---''(_/--' `-'\_)
[ fax. (+48 56) 62 19381 ]
[ http://ncac.torun.pl/~rokach ]
[========<rok...@ncac.torun.pl>=========]

LC's No-Spam Newsreading account

unread,
Jun 1, 1998, 3:00:00 AM6/1/98
to

On Fri, 29 May 1998 ARya...@my-dejanews.com wrote:

> > > How do you do the equivalent of a WRITE statement without appending a
> > > newline? I want to do several disjoint WRITE's that output onto the same
> > > line.

> > write (*,'(A,2x,I5)') '+ Number= ', i
>

> Yes! it'll be print on the same line but from the begining of the line!

The + (1H+ for those who remember Hollerith codes) is a feature intended
for old printers (and need a print filter to work on modern one), and I
won't really regret if this one REALLY goes on the OBSOLESCENT or
OBSOLETE list.

> I think, the question was how to continue printing on the same line.
> It is depend on compiler. For example MS Fortran use back slash format

> 1000 FORMAT(' Input value for I - ' \)
>

> As I remeber some other compiler use '$' instead '\'

Most Unix (Sun Ultrix DU=OSF HP-UX) and VMS use $.
Old HP RTE used underscore

I believe Fortran 90 has a NOADVANCE option to handle this standardly.

----------------------------------------------------------------------
nos...@ifctr.mi.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.


0 new messages