For three digit exponents Fortran drops the 'E' in the output

与世无争的帅哥 提交于 2019-11-30 14:04:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/24004824/for-three-digit-exponents-fortran-drops-the-e-in-the-output

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