[f2py] f2py, C, and multidimensional arrays.
Josef Koller
jkoller at lanl.gov
Sat May 29 20:50:02 EEST 2010
why not use SWIG? ~Josef
On May 28, 2010, at 11:41 PM, Daniel Welling wrote:
> Greetings. I am new to F2py and am trying to use it to wrap some
> simple C functions. I've had success with scalars and vectors, but
> cannot get any multidimensional arrays to work correctly. An example:
>
> /* bar.c */
> void bar(int n, int m, double **x) {
> int i, j;
> for (i=0; i<n; i++)
> for (j=0; j<m; j++)
> printf("Position %i, %i = %.3f\n", i, j, x[i][j]);
> }
>
> ! wrapper m.pyf
> python module m
> interface
> subroutine bar(n, m, x)
> intent(c) bar
> intent(c)
> integer intent() :: n
> integer intent() :: m
> double precision intent(in) :: x(n,m)
> end subroutine bar
> end interface
> end python module m
>
> Build shared object:
> $ f2py2.5 foo.c foo.pyf -c
>
> Try to run it:
> >>>import m
> >>>import numpy as np
> >>>dog = np.zeros((0,0))
> >>>m.bar(dog)
> Bus error
>
> And that's it. It drops me out of ipython/python shell and back to
> the bash prompt. I cannot find any examples similar to this, nor
> any mailing list threads on this topic. Does anyone have any
> experience with such examples?
>
> Thanks for your help.
> _______________________________________________
> f2py-users mailing list
> f2py-users at cens.ioc.ee
> http://cens.ioc.ee/mailman/listinfo/f2py-users
--
Josef Koller, Ph.D. (TSPA/Correspondence)
Space Science and Applications, ISR-1, MS D466
Los Alamos National Laboratory, NM 87545-1663
Phone: (505) 665 3399 http://www.koller.info
Fax: (505) 665 7395 email: jkoller at lanl.gov
More information about the f2py-users
mailing list