【发布时间】:2013-11-28 12:03:40
【问题描述】:
考虑以下 Fortran 子例程,在 test.f 中定义:
subroutine test(py_func)
use iso_fortran_env, only stdout => output_unit
external py_func
integer :: a
integer :: b
a = 12
write(stdout, *) a
b = py_func(a)
write(stdout, *) b
end subroutine
还有以下 Python 代码,在 call_test.py 中定义:
import test
def func(x):
return x * 2
test.test(func)
使用以下编译器(英特尔编译器):
python f2py.py -c test.f --fcompiler=intelvem -m test
我希望在运行测试时将其作为输出:
12
24
但我实际上明白了:
12
0
似乎b 被初始化为默认值,而不是test 的结果。我曾尝试在 Fortran 中使用以下内容:
!f2py intent(callback) py_func
external py_func
!f2py integer y,x
!f2py y = py_func(x)
但是在将12 打印到控制台后,我的程序崩溃了。
有什么想法可以在这里发生吗?崩溃的原因将是一个奖励,但我真的只是想在这一点上让一个简单的回调工作。
【问题讨论】:
标签: callback fortran intel-fortran f2py