[Numpy-discussion] a simple question about f2py
Pauli Virtanen
ptvirtan@elisanet...
Wed Oct 24 09:23:06 CDT 2007
Lisandro Dalcin <dalcinl@gmail.com> kirjoitti:
> Im trying to use f2py to wrap some fortran functions wich receive as
> argument PETSc objects. The usual way to implement this with
> PETSc+fortran is to do something like this
>
> soubrutine matvec(A,x,y)
> Mat A
> Vec x
> Vec y
> end soubrutine
>
> The 'Mat' and 'Vec' types are actually integers of appropriate kind,
> PETSc uses a #define to
> define them. I there any way I can teach/hack f2py to translate
> Mat/Vec/etc. to a normal fortran type?
You can tell f2py to use a different type for the argument as follows:
subroutine foo(a)
!f2py integer, dimension(10), intent(inout) :: a
Mat a
end subroutine foo
This way, f2py will treat the parameter as a chunk of memory of size 10*sizeof(integer), and disregard any following definitions for it. Using a hack like this, it's also possible to pass derived type object pointers, "type(Typename), pointer", from the Python side to the Fortran side, as opaque handles.
--
Pauli Virtanen
More information about the Numpy-discussion
mailing list