[f2py] wrapping a fortran library with f2py
Paul Anton Letnes
paul.anton.letnes at gmail.com
Thu May 5 23:03:15 EEST 2011
> Hi all!
>
> I am attempting to wrap the SHTOOLS [0] library using this [1] approach. I started out with a fairly simple routine, the PlmBar routine (attached).
>
> I first generated a "first draft" of the interface, then made a few additions - notably dimension-ing the variable p explicitly, using depend().
> python module shtools ! in
> interface ! in :shtools
> subroutine plmbar(p, lmax, z, csphase, cnorm) ! in :shtools:PlmBar.f95
> use shtools, only: csphase_default
> integer, intent(in) :: lmax
> real*8, intent(out), dimension((lmax + 1) * (lmax + 2) / 2), depend(lmax) :: p
> real*8, intent(in) :: z
> integer, optional, intent(in) :: csphase
> integer, optional, intent(in) :: cnorm
> end subroutine plmbar
> end interface
> end python module shtools
>
> I compile with (gfortran 4.4 and):
> f2py -c shtools.pyf PlmBar.f95 SHTOOLS.f95
> Everything looks nice and dandy, except a lot of:
> Warning: Nonconforming tab character at (1)
>
> Now, the compiled .so seems not to do what I would like it to:
> % python -c 'import shtools; shtools.plmbar(10, 0.3)'
> Error --- PlmBar
> P must be dimensioned as (LMAX+1)*(LMAX+2)/2 where LMAX is 10
> Input array is dimensioned 1
> So my dimensioning is off, somehow. What's going on?
>
> Oh, and there is a "use shtools" so you need to generate the .mod file from SHTOOLS.f95 first.
>
> Cheers,
> Paul.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PlmBar.f95
Type: application/octet-stream
Size: 7612 bytes
Desc: not available
Url : http://cens.ioc.ee/pipermail/f2py-users/attachments/20110505/95a76717/attachment-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SHTOOLS.f95
Type: application/octet-stream
Size: 26577 bytes
Desc: not available
Url : http://cens.ioc.ee/pipermail/f2py-users/attachments/20110505/95a76717/attachment-0003.obj
-------------- next part --------------
>
>
> [0] http://www.ipgp.fr/~wieczor/SHTOOLS/SHTOOLS.html
> [1] http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#the-smart-way
More information about the f2py-users
mailing list