QUICK FORTRAN QUESTION

Kenji4861

Banned
Jan 28, 2001
2,821
0
0
I just want to know how to output everything onto one line.

do 100 i=1, 10
write (*,*) i
100 continue

If I do this, it outputs as
1
2
3
4
5
6
7
8
9
10

How can I make it so, it'll go
1 2 3 4 5 6 7 8 9 10
 

MereMortal

Golden Member
Oct 16, 2000
1,919
2
81
Formatting in fortran is a pain. Use the '$' in a format statement to omit the carriage return that follows a write statement. E.g.,

do 100 i=1,10
if (i.eq.1) then
write (*,110) i
else if (i.lt.10) then
write (*,120) i
else
write (*,130) i
endif
100 continue

110 format($,I1)
120 format($,1X,I1)
130 format($,1X,I2,/)

is one way to output
1 2 3 4 5 6 7 8 9 10