3

Using gfortran 4.6. This code:

PROGRAM f1
IMPLICIT NONE

INTEGER :: i=1, j=3

WRITE(*,*) "integer i is ", i, ", and j is ", j, "."
END PROGRAM f1

produces this console output, which has way too much whitespace:

 integer i is            1 , and j is            3 .

Is there some setting I can set so that there is no space before the first token ("integer"), and so the whitespace between tokens is just one space? I know one fix is

WRITE(*,'(A,I1,A,I1,A)') "integer i is ", i, ", and j is ", j, "."

but this seems very cumbersome to have to do every time I have a print statement - would rather it be somewhat more like C++ where you explicitly write any whitespace in the output.

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
bcf
  • 2,104
  • 1
  • 24
  • 43

2 Answers2

5

List-directed IO, i.e, write (*, *) is meant as a convenience. There are no settings to change its behavior. Different compilers will produce different output. Instead you can, as you have identified, use formatted IO. In this case you can use I0 as the format, which will produce the required number of digits, while I1 will only output single-digit integers. Which is OK if those are the largest values that will be output.

WRITE(*,  '( "integer i is ", I0, ", and j is ", I0, "." )' )  i, j
M. S. B.
  • 28,968
  • 2
  • 46
  • 73
2

You may try some more universal format and re-use it

    fmt = "(*(1x,g0))"

    write(*,fmt) whatever1, whatever2