Fortran:你能解释一下这个格式化字符串吗? [英] Fortran: can you explain this formatting string

查看:217
本文介绍了Fortran:你能解释一下这个格式化字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Fortran程序,我需要修改,所以我正在阅读并试图理解。你可以解释下面语句中的格式化字符串是什么意思:

$ $ $ $ $ $ $ $ $ $($,$(1p,(5x,3 (1x,g20.10)))')x(jr,1:ncols)


解决方案

http://www.fortran.com/F77_std /rjcnf0001-sh-13.html



不过,你正在写每行三个一般(g)格式的浮点数。每个浮点数的总字段宽度为20个字符,小数点右侧为10个位置。大量的数字是指数形式。



1x s只是简单的添加空格通过增加字段宽度来实现,即 g21.10 ,因为数字是正确的, 5x

在这里有点棘手的事情是临时导致 1p 这是一个比例因子。它使得由下面的 g 格式产生的所有指数形式数的尾数乘以10,并且指数相应地改变,即代替默认值

  g17.10  - > b0.1234567890E + 12 

你得到:

  1p,g17.10  - > b1.2345678900E + 11 

b 表示输出中的空白。请务必在字段宽度计数器中为 - 留出余地...



的鳞片e大于1小数位数被减少(保留总精度),即

  3p,g17.10  - > ; b123.45678900E + 09!注意小数点后面只有8位数

1p

  -7p,g17.10  - > b0.0000000123E + 19 

我应该加上 p 比例因子编辑描述符在输入上完全不同。阅读文档...


I have a Fortran program which I need to modify, so I'm reading it and trying to understand. Can you please explain what the formatting string in the following statement means:

write(*,'(1p,(5x,3(1x,g20.10)))') x(jr,1:ncols)

解决方案

http://www.fortran.com/F77_std/rjcnf0001-sh-13.html

breifly, you are writing three general (g) format floats per line. Each float has a total field width of 20 characters and 10 places to the right of the decimal. Large magnitude numbers are in exponential form.

The 1xs are simply added spaces (which could as well have been accomplished by increasing the field width ie, g21.10 since the numbers are right justified. The 5x puts an additional 5 spaces at the beginning of each line.

The somewhat tricky thing here is tha lead 1p which is a scale factor. It causes the mantissa of all exponential form numbers produced by the following g format to be multiplied by 10, and the exponent changed accordingly, ie instead of the default,

    g17.10  ->  b0.1234567890E+12

you get:

  1p,g17.10  -> b1.2345678900E+11

b denotes a blank in the output. Be sure to allow room for a - in your field width count...

for completeness in the case of scale greater than one the number of decimal places is reduced (preserving the total precision) ie,

  3p,g17.10  -> b123.45678900E+09  ! note only 8 digits after the decimal

that is 1p buys you a digit of precision over the default, but you don't get any more. Negative scales cost you precision, preserving the 10 digits:

    -7p,g17.10  ->  b0.0000000123E+19

I should add, the p scale factor edit descriptor does something completely different on input. Read the docs...

这篇关于Fortran:你能解释一下这个格式化字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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