fortran写输出:一行中的所有变量 [英] fortran write output: all variables in a line
问题描述
我尝试写一个file.dat白a很多列(11),格式不同(1.4e-12,10 ...)
当我尝试写代码时,我使用以下fortran命令:
WRITE(7,*)id,t,a,e,inc,capom,omega,capm,mass,radius
但原始文件中的每一行现在都是以乘法行写入的。
1222221 0.0 10.0 0.0 3.1415927 0.0 0.0 3.7828348 9.0E-
$ b 1222221 0.000000000000000E + 000 10.0000000000000
0.000000000000000E + 000 0.000000000000000E + 000 0.000000000000000E + 000
0.000000000000000E + 000 1.67102026939392 9.000000189551827E-010
3.999999989900971E-006
我该如何解决这个问题?
非常感谢您的帮助!
您需要指定所需的格式。你可以通过使用
-
i0
来指定一些未知宽度的整数 li>
-
f4.1
指定最多2位数真实值和1位小数位数(最小值为0.0,最大值为99.9) -
f9.7
可指定最多1位数的实数位7位小数位(适合pi)
-
es10.1
用一个小数位指定最多8位科学记数法(很适合9e-9) -
1x
指定每个数字之间的空格
这些可以一起使用得到
write(7,'(i0,1x,3(f4.1,1x),f9 .7,1x,2(f4.1,1x),2(es10.1,1x))')&
id,t,a,e,inc,capom,omega,capm,mass,radius
sorry,
I try to write a file.dat whit a lot of columns (11) with different format (1.4e-12, 10...)
when i try ro write the code i use the following fortran command:
WRITE(7,*) id,t,a,e,inc,capom,omega,capm,mass,radius
but each line in the original file is now write in multiply lines.
From:
1222221 0.0 10.0 0.0 3.1415927 0.0 0.0 3.7828348 9.0E-9 4.0E-6
to:
1222221 0.000000000000000E+000 10.0000000000000 0.000000000000000E+000 0.000000000000000E+000 0.000000000000000E+000 0.000000000000000E+000 1.67102026939392 9.000000189551827E-010 3.999999989900971E-006
How can i resolve this?
Thanks a lot for your help!
You need to specify the format you want. You can do this by using
i0
to specify some unknown width integerf4.1
to specify an up-to 2 digit real plus 1 decimal place (min of 0.0 and max of 99.9)f9.7
to specify an up-to 1 digit real plut 7 decimal places (fits pi nicely there)es10.1
to specify an up-to 8 digit scientific notation real with a single decimal place (will fit 9e-9 nicely)1x
to specify a space between each number
These can be used together to get
write(7,'(i0,1x,3(f4.1,1x),f9.7,1x,2(f4.1,1x),2(es10.1,1x))') &
id,t,a,e,inc,capom,omega,capm,mass,radius
这篇关于fortran写输出:一行中的所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!