Dynamic output format setting

回眸只為那壹抹淺笑 提交于 2019-11-28 10:20:25

问题


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.


回答1:


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




回答2:


You don't need to supply exact number of values, indicating more is ok. The normal way is to use a large enough value, like

        '(a,999f9.4)'

in Fortran 2008 u can use the feature M.S.B. shows *999(f9.4).

If you need dynamic string for some other purpose, use the concatenation operator //.



来源:https://stackoverflow.com/questions/27728502/dynamic-output-format-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!