数据打印在第二行,fortran [英] data is printed in a second row, fortran
问题描述
write(4,'(7f20.4)')在Fortran代码中有以下写入语句: ,x(i,1),x(i,2),x(i,3),x(i,4),x(i,5),x(i,6),x(i,7), x(i,8),x(i,9)
我想完整一组值打印在一行中,但是我在一秒钟内得到最后两个值。
我试过 advance = no
Fortran 2008引入了 unlimited-format-item ,它是<*>(format-items)(换句话说,'*'就像重复计数)。
您的编译器(您没有说明您正在使用哪个)可能会支持此功能。
621页)工作文件,
注10.7进一步解释说:
无限格式项目的效果就好像其包含的列表前面有一个非常大的重复计数。没有 unlimited-format-item 版本隐含的文件定位,这可以用于编写通常所谓的逗号分隔值记录。
<例如,
WRITE(10,'(IARRAY =,*(I0,:,,) )')IARRAY
产生一个记录,其中包含一个标题和一个以逗号分隔的整数值列表。
这是另一个例子 - 一个完整的程序 - 使用上面给出的行
程序测试
隐含无
整数,参数:: i = 1
实数,参数:: x(i,9)=重塑([1,2,3,4,5,6,7,8,9],[1,9])
写(4,'(*(f20.4 ))')x(i,1),x(i,2),x(i,3),x(i,4),x(i,5),&
x(i,6),x(i,7),x(i,8),x(i,9)
结束程序
I have the following write statement in a fortran code:
write(4,'(7f20.4)'),x(i,1), x(i,2),x(i,3),x(i,4),x(i,5),x(i,6),x(i,7),x(i,8),x(i,9)
I'd like to have the complete set of values printed in a single line, however I'm getting the two last values in a second.
I've tried advance=no
already and the issue persists.
Fortran 2008 introduced the unlimited-format-item, which is *(format-items) (in other words, '*' is like a repeat count).
Your compiler (you didn't say which you are using) may support this.
In the (621-page) Working Document, Note 10.7 explains further:
"The effect of an unlimited-format-item is as if its enclosed list were preceded by a very large repeat count. There is no file positioning implied by unlimited-format-item reversion. This may be used to write what is commonly called a comma separated value record.
For example,
WRITE( 10, ’( "IARRAY =", *( I0, :, ","))’) IARRAY
produces a single record with a header and a comma separated list of integer values."
Here's another example - a full program - using the line you gave us above
Program test
Implicit None
Integer, Parameter :: i = 1
Real, Parameter :: x(i, 9) = reshape( [1,2,3,4,5,6,7,8,9], [1,9] )
Write (4, '(*(f20.4))') x(i, 1), x(i, 2), x(i, 3), x(i, 4), x(i, 5), &
x(i, 6), x(i, 7), x(i, 8), x(i, 9)
End Program
这篇关于数据打印在第二行,fortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!