C-FORTRAN的互操作性 - 派生类型的指针 [英] c-fortran interoperability - derived types with pointers

查看:364
本文介绍了C-FORTRAN的互操作性 - 派生类型的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我早就FORTRAN code,它已作出从蟒蛇使用。我决定做Fortran-> C-> Python接口。

I have long fortran code that has to be made usable from python. I decided to do Fortran->C->Python interface.

我有一个问题:我已经得出包含的Fortran模块中的类型

I got a problem: I have derived types within Fortran modules that contain

double precision, allocatable  

类型作为成员。

当试图用ifort我得到编译(类似gfortran东西):

When trying to compile with ifort I get (with gfortran something similar):

Each component of a derived type with the BIND attribute shall be a nonpointer,         
nonallocatable data component with interoperable type and type parameters

这实际上是与英特尔编译器文档和Fortran 2003标准协议:15.2.5点

This is actually with agreement with Intel compiler documentation and Fortran 2003 standard: point 15.2.5.

有什么办法来访问Fortran的型与分配的还是里面的指针?

Is there any way to access Fortran "type" with allocatable or pointer inside?

推荐答案

不是真的。即使是全新的 TS 29113
不提供解决办法。它具有 TYPE(*),但你必须知道,如何反code C中的结构可以通过逆向工程做到这一点。

Not really. Even the brand new TS 29113 does not offer a solution. It has the TYPE(*) but you have to know, how to decode the structure in C. You can do it by reverse engineering.

有实际上是该结构中所引用的TS中的大小的宏。参见 CFI_attribute_allocatable 。但是提领遗体的问题。有提出了标准阵列描述,但该TS尚未由一些编译器支持(特别是通过gfortran)

There is actually a macro for the size of the structure in the referenced TS. See CFI_attribute_allocatable. But the problem with dereferencing remains. There is a standard array descriptor proposed, but this TS is not yet supported by some compilers (notably by gfortran).

什么是可能的,就是指针刚刚传递到结构的通用功能,如的qsort 。然后你只使用一块内存,这种情况也包含一些指针或可分配描述符,但C没有了解他们。

What is possible, is to just pass the pointer to the structure to a generic function such as qsort. Then you use just a piece of memory, that happens to contain also some pointer or allocatable descriptor, but C does not have to know about them.

另一种可能性是构造一个派生​​类型,它仅持有键入,而不是Fortran指针(c_ptr),并使用 C_LOC(),以填补他们。确保只有连续的阵列即可。

Another possibility is to construct a derived type which holds only type(c_ptr), instead of Fortran pointers and use c_loc() to fill them. Be sure to have only contiguous arrays then.

这篇关于C-FORTRAN的互操作性 - 派生类型的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆