Dear all,
I posted this question on the user list but I didn't receive any
answer, maybe it was not the right place. I wanted to contribute to the
f2py documentation, but I feel I need to understand the issues I submit
first.
1. The follwing fortran function:
function f2(x,y)
implicit none
real,intent(in):: x,y
real, dimension(3):: f2
f2(1)=x+y**2
f2(2)=sin(x*y)
f2(3)=2*x-y
end function f2
gives a segmentation fault when called from python if it is not in a
fortran module. If it is contained in a fortran module, it works fine
and returns an array.
That makes sense because fortran modules
automatically generate an interface. However, I don't see that reflected
in the .pyf files generated by f2py.
So, is there a way to "correct" the
function outside the module to work with f2py?
2. I have read in several posts that automatic arrays
do not work with
f2py.
So that something like:
real function trace(m)
real, dimension(:,:), intent(in) :: m
Has to be converted into:
real function trace2(m,n)
integer, intent(in) :: n
!f2py
integer,intent(hide),depend(m) :: n=shape(m,0)
real, dimension(n,n), intent(in) :: m
which works fine with f2py
but is not nice in fortran90. I've tried to do
something like:
real function trace(m)
!f2py
integer,depend(m) :: n=shape(m,0)
!f2py
real, dimension(n,n), intent(in) :: m
real, dimension(:,:), intent(in) :: m
But it does not work. Is there a workaround to avoid passing the
dimension of the matrix as a fortran argument?
Thanks in advance!
Ramon