动态输出格式设置 [英] Dynamic output format setting

查看:215
本文介绍了动态输出格式设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着动态地制作输出格式,因为要打印的变量数量可以动态变化。我已经对以下两种方法做了一些实验(参见下面的上下文),但是他们都导致了这样的错误消息:

forrtl:error(63) :输出转换错误,单元1016,file / panfs / roc / Node_ 16.txt第一种方法使用一个字符串来指定输出格式,例如 p>

  real a(4)= [1 2 3 4] 
int size = 4
write(string, '(a,i3,a)')'(a,',size,'(f9.4))'
write(*,string)a(:)

第二种方法是我从互联网上学到的,它只占用一行,但它也不起作用:

b
$ b

  write(*,'(a,< size> f9.4)')a(:) 

请使用此格式设置帮助我。谢谢。



编辑:我发现问题的罪魁祸首。在我的真实项目中,数组a的某些元素非常大,因此f9.4不适合显示完整数组。为了解决这个问题,我用e11.3之类的东西替换了f9.4。

解决方案

Fortran最近添加了 * 作为无限格式转发器。例如'(*(2X,F3.1))'这比动态格式更易于使用。

I tried to make the output format dynamically in the sense that the number of variables to be printed out could be varied dynamically. I had done some experiment with the following two methods (see the context below), but both of them led to a error message like this:

forrtl: error (63): output conversion error, unit 1016, file /panfs/roc/Node_ 16.txt

The first method uses a string to specify the output format, for example,

real a(4) = [1 2 3 4]
int size = 4
write(string,'(a,i3,a)') '(a,',size,'(f9.4))'
write(*, string) a(:)

The second method is what I just learnt from the Internet, which occupies only one line, but it didn't work either:

write(*,'(a,<size>f9.4)') a(:)

Please help me with this format setting. Thanks.

EDIT: I found the culprit of the problem. In my real project, some element of the array "a" is pretty huge such that f9.4 is not suitable to display the full array. To fix the problem, I replace f9.4 with something like e11.3.

解决方案

Fortran recently added * as an unlimited format repeater. e.g., '( *(2X, F3.1) )' This is easier to use than a dynamic format.

这篇关于动态输出格式设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆