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

Historical question on Formatted Read

chauvjo
Novice
287 Views

A quick historical question. I am working on an old Fortran 66 program in which the original programmer went to great lengths to provide detail precision on the read format statements for a fixed field input.  Here is a short example:

(f10.3,f10.4,/,(5(f10.5,f10.2))

Given the generic Fw.d descriptor, I have always assumed that during a Fortran read, the compiler only uses w and that d has no effect and in fact is ignored.  Was there a time when this was not true?   I did check to see if he might have shared this format with a WRITE statement.  He did not…it was only used for READ.

Thanks….

 

 

0 Kudos
2 Replies
IanH
Honored Contributor II
287 Views

Under some important circumstances, your assumption isn't true today. 

The processor uses the decimal precision specification from the data edit descriptor if the input doesn't contain a decimal separator.

So if your edit descriptor is F10.3, and you supply input of `2` (with padding blanks as appropriate), the result value is 2E-3.

Supply input of `2.`, and you get a value of 2.

Perhaps at the time the program was written, input columns were in short supply, so using a column for a decimal separator was seen as wasteful.

I think it is fair to say that people expect input of `2`, without a decimal separator, to be the value 2, so today I always use a decimal width specification of zero - i.e. F10.0.  But for historic code you need to be mindful of other code that may have generated the input files, that relied on this particular behaviour.

0 Kudos
Steven_L_Intel1
Employee
287 Views

I'm pretty sure that the effect of d on read as Ian describes it has been in Fortran since at least Fortran 66. It was quite common to do this when reading data from punchcards, where you have only 80 columns and didn't want to waste one on a decimal point.

0 Kudos
Reply