[Callback functions] may also be explicitly set in the module. Then it is not necessary to pass the function in the argument list to the Fortran function. This may be desired if the Fortran function calling the python callback function is itself called by another Fortran function.
That's what has been stated in the scipy documentation. However, I can't seem to find an example of how this would be done.
Let's take this particualr Fortran / Python combination for an example:
test.f:
subroutine test(py_func)
use iso_fortran_env, only stdout => output_unit
!f2py intent(callback) py_func
external py_func
integer py_func
!f2py integer y,x
!f2py y = py_func(x)
integer :: a
integer :: b
a = 12
write(stdout, *) a
end subroutine
call_test.py:
import test
def func(x):
return x * 2
test.test(func)
Compiled with the following command (Intel compiler):
python f2py.py -c test.f --fcompiler=intelvem -m test
What changes would I have to take to expose the function to the entire Fortran program in the form of a module, so that I could call the function from inside the subroutine test, or any other subroutine in any other fortran file in the project?