E Format code whinge [message #42574] |
Tue, 15 February 2005 14:16 |
William Clodius
Messages: 30 Registered: December 1996
|
Member |
|
|
I have just had to clean up a UNIX to Windows porting problem that
occurred because IDL's implementation of formats (in printf) use only a
subset of the capabilities provided Fortran's more detailed
specification, and the Windows and UNIX specifications for this
implementation differ.
In Fortrran the E format code can have either of the formats
Ew.d
or
Ew.dEe
where w is the width (in characters) of the output, d is the number of
positions after the decimal point, and e is the number of characters
required by the exponent. The first simplification in IDL's format
implementation is to ignore the Ee specification and have e be a fixed
size. Unfortunately this size differs between UNIX and WIndows (e is 2
on UNIX and 3 on Windows). Thiss by itself is a portability problem,
but it is worsened by IDL's failure to implement Fortran's flexibility
in dealing with format specification that do not match the
characteristics of the input data. In Fortran, some of the default
characters in the outpur (the 'E' the sign in the exponent, or the
digit in front of the decimal poin) can be dropped to allow appropriate
output.
As a result of this lack of flexibility an E10.3 Format code for the
IDL printf procedure has the following output formats
Sf.dddEsee on UNIX
and
f.dddEseee on Windows
where S is the sign ' ' or '-', f is the first significant digit, ddd
is the digits after the decimal point, s is the exponent sign '+', or
'-', and eee is the exponent.
Note what happens to S in Windows. As a result IDL on Windows cannot
output a negative number in E10.3 format. Fortran by default wold
eliminate the f and change ddd and eee appropriately.
I was surprised at the choice of e=3 for Windows. On most Fortran
systems e=2 is sufficient as the s can be dropped for large positive
exponents, and the E can be dropped for large negative exponents.
|
|
|