reading doubles with I and writing integers with F
François-Xavier Coudert
Francois-Xavier.Coudert@lcp.u-psud.fr
Fri Jan 7 09:01:00 GMT 2005
Hi,
> print '(F10.3)', 1
> end
I believe this is non standard. Many compilers throw a runtime error
(something like "Expected REAL for item 1 in formatted transfer, got
INTEGER", for g95 and gfortran; Portland Group compiler does something
similar). Some others accept this as if there were an equivalence statement
and return 0.000 (that's the case of g77 and the Intel compilers).
In fact, you can do the same with gfortran (for learning purpose) if you
specify the equivalence in the code:
program test
integer :: i
real :: r
equivalence(r,i)
i = 1
print '(F10.3)', r
end
Which is correct F90 (and F77 as far as I believe) and returns, in this
case, 0.000.
> real*8 a
> character b
> b = '6 '
> read (b, '(i2)'),a
> print *,a
> read (b, '(f2.0)'),a
> print *,a
> end
Same thing here. The equivalence used by g77 is something like:
integer*8 i
real*8 a
equivalence (i,a)
character b
b = '6 '
read (b, '(i2)'),i
print *,a
read (b, '(f2.0)'),a
print *,a
end
--
Someday your prints will come. (Kodak)
More information about the Fortran
mailing list