Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Internal READ of Double-precision REAL Constant in Various Formats

durisinm
Novice
482 Views
I'm using IVF 8.0.044 on Windows XP Pro, and I'm getting different results when performing a list-directedread of a double-precision constant value from an internal file into a double-precision variable.
The constant valueis in an80-character, fixed-length string variable named DataLine. The READ statement is the following:

read

(DataLine, fmt=*, iostat=iostatus) ElSize

For example, if the value for ElSize appears in DataLine as 0.000000375_fpdp (where "fpdp" is a PARAMETER defined as 8in a USEd module) or 0.000000375_8, then the read fails with an iostat value of 59. If the value appears as 0.375D-6, then the read succeeds.
The definition for error 59 from the IVF Language Reference Manual is, "The data in a list-directed input record had an invalid format, or the type of the constant was incompatible with the corresponding variable. The value of the variable was unchanged."
Why is this? I thought that the three formats were equivalent.
Mike D.
0 Kudos
4 Replies
Steven_L_Intel1
Employee
482 Views
They're equivalent in Fortran source, not input to a READ. READs don't support kind specifiers and have no idea what PARAMETER constants you may have declared.
0 Kudos
durisinm
Novice
482 Views

Chapman's Fortran 90/95 for Scientists and Engineers (pp. 537, 777) recommends not to use the D format descriptor in new programs, calling it obsolete and stating that it is preserved only for backwards compatibility with earlier versions of Fortran. Every time I try to follow that advice and use the number_kind type of syntax I always seem to run into some kind of an issue (no pun intended) like this one.

Is Chapman all wet with his advice, or am I just not understanding how to apply it properly?

Mike D.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
482 Views
You cannot use _kind notationfor formatted I/O -- only throughout the code.
AFAIK (but I'm not really an expert on the issue), D is basically equivalent to E when it comes to I/O. The manner how it is interpreted depends on kind/precision of corresponding I/O item, not on whether D or E is present. In other words, if the file contains:
3.1415926535897D0
3.1415926535897E0
and it is read as:
REAL(kind=4):: F
REAL(kind=8):: D
READ(11,"(E20.0)") F -> gives 3.141593 (truncated)
READ(11,"(D20.0)") F -> gives 3.141593 (truncated)
READ(11,"(E20.0)")D -> gives 3.1415926535897 (non-truncated)
READ(11,"(D20.0)") D-> gives 3.1415926535897 (non-truncated)
Thus, it doesn't really matter whether it's D or E in an external file or in format string. What matters is variable type.
However, in source code Dversus E makes difference:
D = 3.1415926535897E0 -> gives 3.14159274101257 (truncated, then zero-extended)
D = 3.1415926535897D0 -> gives 3.1415926535897 (non-truncated)
Regarding Chapman, I haven't read the book, but a person whose opinionsI highly respect (namely, Richard Maine from c.l.f.) dislikes it primarily because the author has the tendency to present his own preferences (some even highly doubtful) as universally accepted guidelines or truths.
Jugoslav
0 Kudos
Steven_L_Intel1
Employee
482 Views
I agree with Jugoslav - the underscore kind specifier is preferable in new Fortran code, but, as Jugoslav notes, it is not acceptable during formatted input (includes list-directed). Jugoslav is also correct in saying that D or E doesn't matter in formatted input - it is the datatype of the variable that is used.
0 Kudos
Reply