I apologise for the errors in the program source.
I am not sure how that happened when cutting and pasting.
The program below has been corrected.
Cheers
Ian Chivers
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
Ian Chivers
Sent: 18 January 2005 15:44
To: [log in to unmask]
Subject: Real literal constants
I have a query regarding real literal constants when reading data from a
file or the terminal.
I can't find anything in the standard that covers this issue, only in the
context of real literal constants in a program.
Consider the following program
program ch1310
implicit none
INTEGER , PARAMETER :: Long=SELECTED_REAL_KIND(15,307)
integer , parameter :: longi = selected_int_kind(15)
REAL (Long) :: R1 real :: x1
REAL (Long) :: R2=0.01_long real :: x2=0.01
read *,x1
read *,r1
print *,x1
print *,x2
print *,r1
print *,r2
print *,bitpattern32(x1)
print *,bitpattern32(x2)
print *,bitpattern64(r1)
print *,bitpattern64(r2)
contains
function bitpattern32(x)
implicit none
real , intent(in) :: x
character*32 :: bitpattern32
integer :: i,j
bitpattern32=' '
i=transfer(x,i)
Jloop : &
DO J=0,31
IF (BTEST(i,J)) THEN
bitpattern32(32-J:32-J)='1'
ELSE
bitpattern32(32-J:32-J)='0'
END IF
END DO Jloop
end function bitpattern32
function bitpattern64(x)
implicit none
real (long) , intent(in) :: x
character*64 :: bitpattern64
integer (longi) :: i,j
bitpattern64=' '
i=transfer(x,i)
Jloop : &
DO J=0,64
IF (BTEST(i,J)) THEN
bitpattern64(64-J:64-J)='1'
ELSE
bitpattern64(64-J:64-J)='0'
END IF
END DO Jloop
end function bitpattern64
end program ch1310
And input of
0.01
0.01
With the second read I do not need to add _long to the external data to get
the higher precision. Is this standard conforming?
Cheers
Ian Chivers
|