Fortran 子程序可以将另一个子程序作为参数。
subroutine mst(yht)
..
..
call yht(..)
但是来自 python 的对象数组呢?我怎样才能发送 say
arr=[yht,yht,yht]
到 Fortran。我试过了,但是失败了。有什么办法吗?
请您参考如下方法:
这可能是一个扩展的评论而不是一个答案......
据我所知,f2py 会将 Fortran 过程(即函数和子例程)签名翻译成 Python。我认为 f2py 不会将 Fortran 派生类型定义转换为 Python 对象定义。我已经好几年没用过 f2py 了,所以我在这方面可能是错的。用 Fortran 派生类型的实例识别 Python 对象的明显途径可能难以实现。
如果您可以说服您的 Python 代码创建 Fortran 编译器识别为 C 结构的内容并使用 Fortran 的与 C 的互操作性功能来读写它们,您可能会取得更大的成功。 Metcalf, Reid and Cohen状态(p246)
These restrictions allow the type to interoperate with a C struct type that has the same number of components. The components correspond by position in their definitions. Each Fortran component must be interoperable with the corresponding C component.
