问题描述
我想要一个Fortran写入语句格式化为依赖于某个变量。例如,我可以写:
write(*,'(3f15.3,3f9.2)')x,y ,z,(var(i),i = 1,nvari)
其中 nvari = 3
。但是,如果在某些情况下,我实际上有4个变量(即 nvari = 4
)。我想写这样的东西:
write(*,'(3f15.3,nvari(f9.2)) ')x,y,z,(var(i),i = 1,nvari)
, nvari
可以是任何东西,输出将按照我喜欢的方式工作。我怎么能做这样的工作?
如果您使用英特尔fortran,它有一个专有的扩展 - 你可以在尖括号中包含一个现有的变量来作为一个说明符:
$ $ p $ $ code写(*,'(3f15.3,< ; nvari> f9.2)')x,y,z,(var(i),i = 1,nvari)
I would like to have a Fortran write statement formatted to depend on some variable. For example, I could write:
write(*,'(3f15.3,3f9.2)') x,y,z,(var(i),i=1,nvari)
where nvari = 3
. But, what if, in some cases, I actually have 4 variables (i.e. nvari = 4
). I would like to write something like this:
write(*,'(3f15.3,nvari(f9.2))') x,y,z,(var(i),i=1,nvari)
Now, nvari
can be anything and the output will work as I like. How can I make something like this work?
If you are using Intel fortran, it has a proprietary extension for this -- you can include an existing variable in angle brackets to act as a specifier:
write(*,'(3f15.3,<nvari>f9.2)') x,y,z,(var(i),i=1,nvari)
这篇关于输出格式字符串取决于一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!