|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jayxwang
Joined: 13 Jun 2011 Posts: 3
|
Posted: Thu Jun 23, 2011 4:06 am Post subject: Selection of the KIND values for real and integer variables |
|
|
In a fortran-77 written program, the real variables are defined as: Implicit double precision (A-H, O-Z).
When the program was compiled using FTN-95, link errors come up with the values of KIND for some arrays seemingly different in differnt subroutines. I am wondering if the real variable must be defined in each subroutine by adding up the the following two lines:
integer, parameter :: dp=kind(1.d0)
real (kind=dp) :: x,y,z....
Values of KIND for those real and integer variables should be the same in the program?
Thanks, |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Thu Jun 23, 2011 5:14 am Post subject: |
|
|
FTN95 uses different values of KIND to most other compilers, so your use of "dp" is a good idea.
I have listed a program below to give some examples of using double precision and also extended precision.
It demonstrates you must be careful when defining both double and extended precision constants.
My preference is to use the non-standard definition "REAL*8", which is the clearest and most concise definition.
Code: | integer, parameter :: dp = kind (1.d0)
integer, parameter :: qp = selected_real_kind (17)
!
real (kind=dp) :: x,y,z
real (qp) :: q,r
real*8 a
integer*4 i
!
a = 0.1d0
x = 0.1_dp
y = 0.1d0
z = 0.1
q = 0.1_qp
r = 0.1d0
!
write (*,*) 'double precision',a,x,y,z
write (*,*) 'extended precision',q,r
write (*,*) 'dp =',dp
write (*,*) 'qp =',qp
!
do i = 5,20
write (*,*) i, selected_real_kind (i)
end do
!
end
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|