Silverfrost Forums

Welcome to our forums

Selection of the KIND values for real and integer variables

23 Jun 2011 3:06 #8453

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,

23 Jun 2011 4:14 #8454

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.

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 
Please login to reply.