Explaining Fortran Write Format

廉价感情. 提交于 2019-12-12 10:28:22

问题


I am a beginner of fortran90. Now I am trying to learn fortran code and I am not clear with the description of the write format

write ( *, '(2x,i4,2x,g14.6,2x,14x,2x,g14.6)' ) 0, unew_norm, error

Can anybody explain to me what does '(2x,i4,2x,g14.6,2x,14x,2x,g14.6)' stuff mean.

It would be very nice to teach me the dummy things.

Best


回答1:


From this source:

nX means that n spaces are added to the line; iw means that an integer (hence the i) is printed in a field w spaces wide; gw.p is a specifier for a floating point number (i.e. not an integer) and is a little more complicated. g means that we will output in either standard floating point format (i.e. 100.123) or in E format (1.00123E+03), whichever is more compact. w means that our number has to fit in a field of width w, just like with the integer. The p indicates how much precision we want in the output, or the number of digits after the decimal point.

In your case, the format specifier '(2x,i4,2x,g14.6,2x,14x,2x,g14.6)' means 2 spaces, integer with width 4, 2 spaces, floating point with width 14 and precision 6, 2 spaces, 14 spaces, 2 spaces, floating point with width 14 and precision 6.

Hope that helps!



来源:https://stackoverflow.com/questions/17177553/explaining-fortran-write-format

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