string to real conversion in gfortran

510 Views Asked by At

I have made a gfortran program which used the READ-statement to converse a string into a real.

Problem: When the string ('1.00000E-03') is read from a file with the command READ(line(54:67),*) t the program returns for t: 1.76617300510772955878279319145152225E-0003. This is a wrong conversion.

But when I write READ('1.00000E-03',*) t then the program returns 1.00000000000366461737654319145152225E-0003. It's OK.

Does someone recognize this failure? Who can help me?

1

There are 1 best solutions below

0
On

John,

you have to read the AS real. Do something like this(and as you have not shown the type declarations):

Program so
Implicit None
character(8)::fchar
real(kind=4):: rnum

write(20,'(a6)') "1.2345"
close(20)
open(22,file='fort.20')
!fchar=line(54:67)
read(22,'(f8.4)') rnum
close(22)
write(*,'(f8.4)')rnum
End Program so

Hope this will help.