[f2py] Calling external functions

Pearu Peterson pearu.peterson at gmail.com
Wed Nov 23 10:55:54 EET 2011


Hi,

There are several issues with the code. For instance, the functions
don't have return values. Due to limitations of f2py, the DP definition
should be repeated in all routine blocks and f2py does not understand
external kw in attributes list so that explicit `external f0` statement
must be used.

The modified Fortran file that builds with f2py is attached.

HTH,
Pearu

On 11/22/2011 05:25 PM, Davor Horvatic wrote:
> I have a major issue with calling external functions in subroutine. All
> code is attached in
> the end of this mail. Code is used in Sage, and the file is read in and
> then fortran command
> called, i.e. f2py wrapper. This code just wont compile to a module and I
> checked
> user manual and exhausted all options. Can you see what I'm doing wrong ?
>
> Sage is producing this error:
>
> getctype: No C-type found in "{'intent': ['out', 'out=f0']}", assuming void.
> getctype: No C-type found in "{'intent': ['out', 'out=f0']}", assuming void.
>
>
> CODE
> -------------------------------------------------
>
>
> !f90
> module r1potgap
> implicit none
>
> integer, parameter :: DP = kind(1.0d0)
>
> real (DP), parameter :: pi=2.D0*ASIN(1.D0)
> real (DP), parameter :: nf=2.d0
> real (DP), parameter :: nc=3.d0
>
> 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, res)
> implicit none
>
> real (DP) :: r, res
>
> intent (in) :: r
> intent (out) :: res
>
> !f2py intent (in) r
> !f2py intent (out) res
>
> res=exp(-r/l0**2)
>
> end function f0
>
> function df0(r, res)
> implicit none
>
> real (DP) :: r, res
>
> intent (in) :: r
> intent (out) :: res
>
> ! # Pragmas f2py-specific
> !f2py intent (in) r
> !f2py intent (out) res
>
> res=-exp(-r/l0**2)/l0**2
>
> end function df0
>
> subroutine potqf(r, k, b, t, phi3, m, res)
> implicit none
>
> !f2py intent (callback) f0
> real (DP), external:: f0
>
> real (DP) :: r, k, b, t, phi3, m, res
> real (DP) :: rn2,bamp,meas,tmpgb,tmp
> integer :: alpha
> !f2py rn2 = f0(rn2)
>
> 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.d0*pi)/(2.d0*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
>
> end module r1potgap
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users at cens.ioc.ee
> http://cens.ioc.ee/mailman/listinfo/f2py-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: r1potgap.f90
Type: text/x-fortran
Size: 1469 bytes
Desc: not available
Url : http://cens.ioc.ee/pipermail/f2py-users/attachments/20111123/9e39b6e9/attachment.bin 


More information about the f2py-users mailing list