Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...