Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

string - Dynamic output format setting

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...