Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...