Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 347
Dex Avatar asked Jun 02 '14 23:06

Dex


1 Answers

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.

like image 169
IanH Avatar answered Nov 16 '22 00:11

IanH