I am trying to compile a piece of old Fortran code with f2py
so that it can be called within Python.
However, the part with external function wouldn’t work.
Here is an MWE, first I have the test.f
:
function f(x)
implicit double precision (a-z)
f = x * x
return
end function f
subroutine gauss(fun)
implicit double precision (a-h, j-z)
! external fun
x = 1.5
write(*,*) fun(x)
return
end subroutine gauss
which is later compiled with makefile
:
f2py -c --quiet --fcompiler=gnu95 \
--f90flags=“-Wtabs” \
-m test \
test.f
Lastly it is called from Python:
import test
f = lambda x: x
test.gauss(test.f)
and gives the error TypeError: test.gauss() 1st argument (fun) can’t be converted to double
.
In a second attempt, I uncomment the line external fun
in the subroutine gauss
and get the following error message during compilation:
/tmp/tmpet9sk3e9/src.linux-x86_64-3.7/testmodule.c: In function ‘cb_fun_in_gauss__user__routines’:
/tmp/tmpet9sk3e9/src.linux-x86_64-3.7/testmodule.c:313:8: error: variable or field ‘return_value’ declared void
I am running out of ideas, any help will be greatly appreciated!