A problem I have with kinds is that the three compilers I use most
offer 4, 4 and 3 different real kinds: gfortran and g95 offer precisions
6,15,18,33 and ifort offers only 6,15,33. I have not yet discovered how
to write a standard-conforming program, valid with all three compilers,
that has a generic interface block and a specific function for each
real kind. This little example showing what I mean works with gfortran
and g95, but ifort complains, correctly, "Ambiguous generic interface
SQR: previously declared specific procedure SQR18 is not distinguishable
from this declaration. [SQR33]"
module sqrgeneric
implicit none
integer,parameter:: &
k6 = selected_real_kind(6), k15 = selected_real_kind(15),&
k18 = selected_real_kind(18),k33 = selected_real_kind(33)
interface sqr
module procedure sqr6,sqr15,sqr18,sqr33
end interface sqr
contains
real(k6) function sqr6(x)
real(k6),intent(in)::x
sqr6 = x**2
end function sqr6
real(k15) function sqr15(x)
real(k15),intent(in):: x
sqr15 = x**2
end function sqr15
real(k18) function sqr18(x)
real(k18),intent(in):: x
sqr18 = x**2
end function sqr18
real(k33) function sqr33(x)
real(k33),intent(in):: x
sqr33 = x**2
end function sqr33
end module sqrgeneric
program testit
use sqrgeneric,only: k6,k15,k18,k33,sqr
implicit none
print *,sqr(2.0_k6),sqr(2.0_k15),sqr(2.0_k18),sqr(2.0_k33)
end program testit
-- John Harper, School of Mathematics and Statistics
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail [log in to unmask] phone (+64)(4)463 5276 fax (+64)(4)463 5045
|