映射自定义类型Fortran-to-Java(使用JNA)

时间:2016-05-31 18:30:48

标签: java java-native-interface fortran jna

我必须编写一个从Java调用的Fortran子例程的接口。 Fortran子例程中的一些参数是派生类型(自定义类型/结构)。可以用JNA映射那些吗?到目前为止,我不能这样做如何工作。 JNI怎么样?

e.g。像这样的子程序:

subroutine mysub(arg)
implicit none
type mytype
   integer:: i
   real*8 :: a(3)
end type mytype

type(mytype) arg

! do stuff...

end subroutine mysub

1 个答案:

答案 0 :(得分:1)

是的,JNA通过引用和值支持聚合类型(C中的struct)。参数的默认约定是按值,例如

public interface MyLibrary extends Library {
    MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary("mylib", MyLibrary.class);

    class MyStruct extends Structure {
        public static class ByValue extends MyStruct implements Structure.ByValue {}
        public int i;
        public double a[3];
        protected List getFieldOrder() {
            return Arrays.asList("i", "a");
        }
    }

    void mysub(MyStruct.ByValue arg);
}