Fortran Coder

查看: 6409|回复: 0
打印 上一主题 下一主题

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

[复制链接]

15

帖子

6

主题

0

精华

熟手

F 币
172 元
贡献
72 点
跳转到指定楼层
楼主
发表于 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位。。。。谢谢大侠指点。

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-11-23 13:46

Powered by Tencent X3.4

© 2013-2024 Tencent

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