Suppressing newline in "print" statement

3,069 views
Skip to first unread message

bdsatish

unread,
Mar 24, 2008, 12:23:16 AM3/24/08
to GNU Fortran
Hi all,

How do I suppress the printing of a newline after the print
statement. This is called non-advancing output. In G95, I used to
write:

print "(a,\)" "Enter a number: "

That is, a backslash used to suppress the newline at the end of a
string. However, the same statement in gfortran gives an error. Any
help ?

FX Coudert

unread,
Mar 24, 2008, 5:07:46 AM3/24/08
to gnu-f...@googlegroups.com
> print "(a,\)" "Enter a number: "


The standard way of doing non-advancing I/O is to use advance="no".
See examples here: http://mrccs.man.ac.uk/hpctec/courses/Fortran90/
Fortran90_56.html

FX

--
François-Xavier Coudert
http://www.homepages.ucl.ac.uk/~uccafco/

bdsatish

unread,
Mar 24, 2008, 6:00:27 AM3/24/08
to GNU Fortran
Yes, I knew that it is possible in "write" statement, but I also
wanted such a thing in the "print" statement. I find it awkward to
type everytime like

write(unit=*, fmt="blah", advance="no") "My message"

For a newcomer who is browsing the code casually, the following line
is more intuitive

print "(a,\)" "My message"

I need not bother about 'unit' or 'fmt' or 'advance' and such
concepts. Of course, if "write" is the standard, i'll follow it,
anyway. It was just a curiosity that I wanted non-advancing "print" in
gfortran, since it is also available in G95.

FX Coudert

unread,
Mar 24, 2008, 6:39:57 AM3/24/08
to gnu-f...@googlegroups.com
> Yes, I knew that it is possible in "write" statement, but I also
> wanted such a thing in the "print" statement.

There's no standard way to do it in a print statement. There is a
rather widespread nonstandard way of doing it, though, using $ as an
format edit descriptor:

print "(a,$)", "My message"

> For a newcomer who is browsing the code casually, the following line
> is more intuitive
>
> print "(a,\)" "My message"

Well, I don't see why it's more intuitive than:

write(*,"(a)",advance=no) "My message"

If a newcomer wants to understand the form you use, they have to look
up for the meaning of the backslash, they won't find it in the
standard or textbooks, so they need to find the manual of the
compilers that use it.

Anyway, there is one more thing that is nonstandard about your code:
there needs to be a comma between the format and the first element of
the I/O list in the PRINT statement.

Reply all
Reply to author
Forward
0 new messages