使用f2py将对象数组传递给Fortran

2024-09-27 23:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

Fortran子例程可以接受另一个子例程作为参数。在

subroutine mst(yht)
 ..
 ..
 call yht(..)

但是python中的一个对象数组呢?我怎么能发说

arr=[yht,yht,yht]

对Fortran。我试过了但是失败。是有办法吗?在


Tags: 对象参数数组call例程arrfortranmst
1条回答
网友
1楼 · 发布于 2024-09-27 23:22:44

这也许是一个延伸的评论,而不是一个答案。。。在

据我所知,f2py将把Fortran过程(即函数和子例程)的签名转换成Python。我不认为f2py会将Fortran派生的类型定义转换为Python对象定义。我已经好几年没有使用f2py,所以我可能在这个问题上错了。用Fortran派生类型的实例来识别Python对象,这一明显的方法可能很难实现。在

如果您能说服Python代码创建一些Fortran编译器识别为C结构的东西,并使用Fortran的C与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.

相关问题 更多 >

    热门问题