对于三位指数,Fortran 在输出中删除“E" [英] For three digit exponents Fortran drops the 'E' in the output

查看:51
本文介绍了对于三位指数,Fortran 在输出中删除“E"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从 Python 进入 Fortran90,老实说,到目前为止,最难的部分是习惯于编写输出的格式化代码.我遇到了一个格式问题,我似乎无法通过谷歌搜索或解决问题,我已经在这个网站上搜索了答案,但没有发现任何有用的信息.

I'm just coming to Fortran90 from Python and, honestly, the hardest part so far has been getting used to the formatting codes for writing output. I've run across a formatting problem that I can't seem to google or fiddle my way out of, I have searched this site for an answer but didn't find anything helpful.

我正在计算并将输出写入文件.我正在使用以下代码格式化计算结果

I'm doing a calculation and writing the output to file. I'm formatting the results of the calculation with the following code

写(文件,('13ES11.2)')卡帕

write(file, ('13ES11.2)') kappa

有些值非常小,所以我最终得到三位数的负值.所以应该是这样的,

Some of the values are very small so I end up three digit negative values. So something that should look like this,

10e-100

但是我在我的输出文件中得到了这个,

But instead I get this in my output file,

10-100

这对我没有帮助,因为我有另一个程序需要读取该文件并了解这些数字是指数.

Which isn't helpful for me because I have another program that needs to read that file and understand that those numbers are exponents.

感谢任何人对此的帮助.

I'd appreciate anyone's help on this.

推荐答案

尝试ES11.2E3的格式规范.这允许指数的三个位置(总是).

Try a format specification of ES11.2E3. That allows three positions (always) for the exponent.

对于 Fortran 格式的输入和输出,有一种固定列宽"的强烈味道.如果没有指数字段宽度规范,默认"宽度为 2.如果指数部分需要多一个位置,则借用通常由 E 占据的列以至少允许输出继续而不会丢失信息.如果指数输出需要比默认值多两个,那么您会看到星号.

There is a strong flavour of "fixed column width" to Fortran formatted input and output. Without the exponent field width specification, the "default" width is two. If the exponent part requires one more position than that, then the column normally occupied by the E is borrowed to at least permit output to continue without loss of information. If the exponent output requires two more than the default, then you'll see stars.

请注意,如果您的其他程序是用 Fortran 编写的,那么它会理解这些缺少 E 的奇怪实数.

Note that if your other program was written in Fortran, then it would understand these strange real numbers with the missing E.

诸如 G0.3 之类的编辑描述符可以部分解决此问题,但不能保证科学格式.

An edit descriptor such as G0.3 provides a partial workaround to this oddity, but you are not guaranteed scientific format.

这篇关于对于三位指数,Fortran 在输出中删除“E"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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