嗨,所有fortran恋人,
我试图写入一个输出三个变量的文件
program main
integer N, u
parameter(u=20)
open (u, FILE='points.dat', STATUS='new')
do 10 i= 1, 100
write(u,100) i, i*2, i*5
10 continue
100 format (I5, I10, 9X, I10)
close(u)
print *,'COMPLETE!!'
end
给出输出(points.dat剥离的文件内容):
1 2 5
2 4 10
3 6 15
4 8 20
5 10 25
6 12 30
7 14 35
8 16 40
9 18 45
10 20 50
11 22 55
12 24 60
...
...
...
...
...
99 198 495
100 200 500
|(This line added by the write statement)
但我想要这样的东西:
1 2 5
2 4 10
3 6 15
4 8 20
5 10 25
6 12 30
7 14 35
8 16 40
9 18 45
10 20 50
11 22 55
12 24 60
...
...
...
...
...
99 198 495
100 200 500|(The cursor stop here)
即。每行开始时没有空间。最后一行在打印" 500"
后停止我尝试使用" 1x"指示符使用水平间距,但没有成功。
在写语句中添加Advance ='no'。如果该行不是最后一条,请写EOL:
do 10 i= 1, 100
write(u,100,advance='no') i, i*2, i*5
if (i.ne.100) write(u,*)
10 continue
编辑:我现在看到了,似乎Fortran程序无论如何都会将EOL添加到文件的末尾。然后,您必须使用外部程序来截断文件,例如https://www.quora.com/how-do-i--i-chop-just-just-the-last-byte-byte-file-in-file-in-bash。