Re: [f2py] Calling external functions
Davor Horvatic <[email protected]> Wed, 23 Nov 2011 15:33:47 +0100
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, Thanks, I see now where I made trivial mistakes. Unfortunately I found another issue which I can't solve. From your example I can see that one has to call potqf function as: r1potgap.potqf(0.1,1,0.5,0.1,0.2,0.1,r1potgap.f0) so in principle I would not define f0 and df0 in this module but in Sage I can build another module with f0 and df0 and call this function as: r1potgap.potqf(0.1,1,0.5,0.1,0.2,0.1,mod2.f0) Now, if I introduce another subroutine that uses same external function I get following error: /tmp/tmpX8M5U1/src.linux-x86_64-2.6/fortran_module_3module.c:371: error: redefinition of ‘f0_’ /tmp/tmpX8M5U1/src.linux-x86_64-2.6/fortran_module_3module.c:270: error: previous definition of ‘f0_’ was here /tmp/tmpX8M5U1/src.linux-x86_64-2.6/fortran_module_3module.c:371: error: redefinition of ‘f0_’ /tmp/tmpX8M5U1/src.linux-x86_64-2.6/fortran_module_3module.c:270: error: previous definition of ‘f0_’ was here Code is attached. Plus additional issue, in future I will have several external functions that will be called in each of many subroutines. I'm trying to build solid code that I can use in python which will have basic uniform subroutines and where I'll feed them with different f0, f1 etc functional forms. All help is really appreciated. All the best, Davor _______________________________________________ f2py-users mailing list f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] http://cens.ioc.ee/mailman/listinfo/f2py-users
r1potgap.f90
(text/plain, 2 KB)
!f90
module r1potgap
implicit none
integer, parameter :: DP = kind(1.0d0)
real (DP), parameter :: pi=2.D0*ASIN(1.D0)
real (DP), parameter :: nf=2d0
real (DP), parameter :: nc=3d0
real (DP), parameter :: l0=0.687d0
real (DP), parameter :: mu=0.0096d0*l0
real (DP), parameter :: dq0=128.d0/l0**2
contains
function f0(r) result (res)
implicit none
integer, parameter :: DP = kind(1.0d0)
real (DP) :: r, res
intent (in) :: r
!f2py intent (in) r
res=exp(-r/l0**2)
end function f0
function df0(r) result (res)
implicit none
integer, parameter :: DP = kind(1.0d0)
real (DP) :: r, res
intent (in) :: r
!f2py intent (in) r
res=-exp(-r/l0**2)/l0**2
end function df0
subroutine potqf(r, k, b, t, phi3, m, res)
implicit none
integer, parameter :: DP = kind(1.0d0)
!f2py intent (callback) f0
!f2py external f0
real (DP), external:: f0
real (DP) :: r, k, b, t, phi3, m, res
real (DP) :: rn2,bamp,meas,tmpgb,tmp
integer :: alpha
intent (in) :: r, k, b, t, phi3, m
intent (out) :: res
!f2py intent (in) r, k, b, t, phi3, m
!f2py intent (out) res
meas=((4.0d0*pi)/(2.0d0*pi)**3)*(r**2)
tmp=0
DO alpha = -1,1,1
rn2 = r**2 + ((2.d0*k+1.d0)*pi*t + alpha*phi3)**2
bamp = m+b*f0(rn2)
tmpgb = -2.d0*t*meas*(log(rn2+bamp**2)-log(rn2+m**2))
tmp = tmp+tmpgb
ENDDO
res=tmp
end subroutine potqf
subroutine gapqf(r, k, b, t, phi3, m, res)
implicit none
integer, parameter :: DP = kind(1.0d0)
!f2py intent (callback) f0
!f2py external f0
real (DP), external:: f0
real (DP) :: r, k, b, t, phi3, m, res
real (DP) :: rn2,bamp,meas,tmpgb,tmp,ff0
integer :: alpha
intent (in) :: r, k, b, t, phi3, m
intent (out) :: res
!f2py intent (in) r, k, b, t, phi3, m
!f2py intent (out) res
meas=((4.0d0*pi)/(2.0d0*pi)**3)*(r**2)
tmp=0
DO alpha = -1,1,1
rn2 = r**2 + ((2.0d0*k+1.0d0)*pi*t + alpha*phi3)**2
ff0 = f0(rn2)
bamp = m+b*ff0
tmpgb = (16.0d0*dq0/9.0d0)*t*meas*(bamp*ff0/(rn2+bamp**2))
tmp = tmp+tmpgb
ENDDO
res=tmp
end subroutine gapqf
end module r1potgap