I ran into a curious problem with an interface block that I am using while converting an old library. This library contains specific implementations of standard functions like log and exp, the double-precision versions being called dexp and dlog. I have used this interface in a number of source files without any problem:
integer, parameter :: dp = kind(1.0d0)
interface
real(kind=dp) function dexp( x ) -- why is this a problem?
import :: dp
real(kind=dp), intent(in) :: x
end function dexp
end interface
But with one source file where I use that both gfortran and Intel Fortran claim that something is wrong, but I cannot determine what is wrong, quite probably it is staring me in the face, but I seem to be blind for it (mind you, I simply copied fragments from source files where this was no problem!). My workaround is to comment it out.
Here is the source file:
! dgami.f90 –
! Original:
! july 1977 edition. w. fullerton, c3, los alamos scientific lab.
!
! evaluate the incomplete gamma function defined by
!
! gami = integral from t = 0 to x of exp(-t) * t**(a-1.0) .
!
! gami is evaluated for positive values of a and non-negative values
! of x. a slight deterioration of 2 or 3 digits accuracy will occur
! when gami is very large or very small, because logarithmic variables
! are used.
!
function dgami (a, x)
use ieee_arithmetic
implicit none
integer, parameter :: dp = kind(1.0d0)
interface
real(kind=dp) function dgamit( a, x )
import :: dp
real(kind=dp), intent(in) :: a, x
end function dgamit
real(kind=dp) function dlngam( x )
import :: dp
real(kind=dp), intent(in) :: x
end function dlngam
real(kind=dp) function dexp( x )
import :: dp
real(kind=dp), intent(in) :: x
end function dexp
real(kind=dp) function dlog( x )
import :: dp
real(kind=dp), intent(in) :: x
end function dlog
!real(kind=dp) function dexp( x ) -- why is this a problem?
! import :: dp
! real(kind=dp), intent(in) :: x
!end function dexp
end interface
real(kind=dp) :: dgami
real(kind=dp) :: a, x
real(kind=dp) :: factor
if ( a <= 0.0d0 .or. x <= 0.0d0 ) then
dgami = ieee_value( x, ieee_quiet_nan )
else
dgami = 0.d0
if ( x /= 0.0d0 ) then
!
! the only error possible in the expression below is a fatal overflow.
factor = dexp (dlngam(a) + a*dlog(x))
dgami = factor * dgamit (a, x)
endif
endif
end function dgami
Can anyone point out what is wrong?
(I also posted this in comp.lang.fortran, but that has been very quiet for the past couple of weeks. I suspect Google is to blame …)