gpt4 book ai didi

variables - Fortran 中是否可以将零值变量输出为空白?

转载 作者:行者123 更新时间:2023-12-02 20:57:18 25 4
gpt4 key购买 nike

我想在格式化文件中输出实际变量。如果变量非零,则使用格式语句。但如果变量为零,则仅输出空格,类似于 Iw.0 的做法。是否可以在格式语句中执行此操作?谢谢。

最佳答案

不,不是使用格式语句,但是通过将值写入字符串并进行处理,这相当容易做到。下面是一个演示。可能最好放入子例程中。

program demo

real, dimension (6) :: values = [ 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 ]
character (len=100) :: string
integer :: pos

write (string,'( 6 (1X, F4.1 ) )' ) values
write (55, '(A)' ) trim (string)

MakeBlanks: do

pos = index (string, "0.0")

if ( pos < 1 ) exit MakeBlanks

string (pos:pos+2) = " "

end do MakeBlanks

write (55, '(A)' ) trim (string)

end program demo

关于variables - Fortran 中是否可以将零值变量输出为空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39819102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com