Fortran Coder

查看: 134|回复: 0

[混编] python3 下ctypes 语法换了吗?怎么论坛的例子都有错误啊?

[复制链接]

3

帖子

2

主题

0

精华

新人

F 币
28 元
贡献
15 点
发表于 2019-5-15 17:26:42 | 显示全部楼层 |阅读模式
首先是pasuka 大侠的例子fortran 源码:
[Fortran] 纯文本查看 复制代码
module py2f90
use,intrinsic::iso_c_binding
implicit none
contains
    subroutine transferMat2For(matrix,n1,n2)bind(c,name='array2py')
    implicit none
    integer(c_int),intent(in),value::n1,n2
    real(c_float),intent(out)::matrix(n1,n2)
    integer::i,j
    ! initialize matrix
     matrix = 0.0E0
    ! loop
     do i=1,n1
        do j=1,n2
            matrix(i,j) = real(i,4)*1.E1+real(j,4)*2.E0
            write(*,"('Row:',i4,1x,'Col:',i4,1x,'Value:',1x,F5.2)")i,j,matrix(i,j)
         enddo
     enddo
     return
     end subroutine
end module

python 源码:
[Fortran] 纯文本查看 复制代码
import numpy as np
from numpy.ctypeslib import load_library,ndpointer
from ctypes import c_int

# shape of 2d array
n1,n2 = 2,4+1
# create an empty 2d array
data = np.empty(shape=(n1,n2),dtype='f4',order='f')

flib = load_library("mydll.dll","./")
flib.argtypes = [ndpointer(dtype='f4',ndim=2),c_int,c_int]
flib.array2py(data.ctypes.data,n1,n2)

python 编译运行,提示Traceback (most recent call last):  File "E:/try/python/t1/t1.py", line 12, in <module>    flib.array2py(data.ctypes.data,n1,n2)  File "F:\software\anaconda\lib\ctypes\__init__.py", line 369, in __getattr__    func = self.__getitem__(name)  File "F:\software\anaconda\lib\ctypes\__init__.py", line 374, in __getitem__    func = self._FuncPtr((name_or_ordinal, self))AttributeError: function 'array2py' not found
啥情况啊?我的python 版本3.73,64位,intel visual fortran 64位。。。。谢谢大侠指点。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

QQ|捐赠本站|Archiver|关于我们 About Us|群聊|Fcode

GMT+8, 2019-7-16 08:10

Powered by Discuz! X3.2

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表