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

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

问题描述

我刚刚从Python到Fortran90,说实话,到目前为止最困难的部分已经习惯了写输出的格式化代码。我遇到了一个格式问题,我似乎无法谷歌或摆脱我的出路,我已经搜索了这个网站的答案,但没有发现任何有用的。



我正在做一个计算,并将输出写入文件。我使用下面的代码格式化计算结果:

lockquote
write(file,('13ES11.2)')kappa p>

有些值非常小,所以我最终得到三位数的负值。所以,应该看起来像这样,


<10e-100


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


10-100


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



我很感谢任何人的帮助。

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



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

一个编辑描述符,如 G0.3 提供了一个部分的解决方法,这个古怪的,但是你不能保证科学的格式。


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

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.

解决方案

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

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.

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

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天全站免登陆