取决于变量的输出格式字符串 [英] Format string for output dependent on a variable
问题描述
我希望将 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
可以是任何东西,并且输出将按我喜欢的方式工作.我怎样才能做出这样的事情?
如果你使用的是 Intel fortran,它有一个专有的扩展——你可以在尖括号中包含一个现有的变量作为说明符:
p>
write(*,'(3f15.3,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)
这篇关于取决于变量的输出格式字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!