For three digits, Fortran outputs "E" at the output.

I just come to Fortran90 from Python, and frankly, the hardest part is still used to formatting codes for writing output. I ran into a formatting problem that I can’t imagine on Google or go out of my way, I searched this site for an answer but didn’t find anything useful.

I do the calculation and write the output to a file. I format the calculation results with the following code

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

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

10e-100

But instead, I get this in my output file,

10-100

This is not useful for me, because I have another program that should read this file and understand that these numbers are indicators.

I would appreciate any help with this.

+6
source share
1 answer

Try the ES11.2E3 format ES11.2E3 . This allows three positions (always) for the exponent.

There is a strong color "fixed column width" for formatted input and output Fortran. Without specifying the exponent field width, the default width is two. If the exponential part requires one more position, then the column usually occupied by E is borrowed, at least, to allow the output without loss of information. If two default values ​​are required to display the exponent, you will see the stars.

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

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

+11
source

Source: https://habr.com/ru/post/970213/


All Articles