|
首先是pasuka 大侠的例子fortran 源码:
[Fortran] 纯文本查看 复制代码 02 | use , intrinsic :: iso_c_binding |
05 | subroutine transferMat 2 For ( matrix , n 1 , n 2 ) bind ( c , name = 'array2py' ) |
07 | integer ( c_int ) , intent ( in ) , value :: n 1 , n 2 |
08 | real ( c_float ) , intent ( out ) :: matrix ( n 1 , n 2 ) |
15 | matrix ( i , j ) = real ( i , 4 ) * 1 .E 1 + real ( j , 4 ) * 2 .E 0 |
16 | write ( * , "('Row:',i4,1x,'Col:',i4,1x,'Value:',1x,F5.2)" ) i , j , matrix ( i , j ) |
python 源码:
[Fortran] 纯文本查看 复制代码 02 | from numpy.ctypeslib import load_library , ndpointer |
03 | from ctypes import c_int |
07 | # create an empty 2d array |
08 | data = np.empty ( shape = ( n 1 , n 2 ) , dtype = 'f4' , order = 'f' ) |
10 | flib = load_library ( "mydll.dll" , "./" ) |
11 | flib.argtypes = [ ndpointer ( dtype = 'f4' , ndim = 2 ) , c_int , c_int ] |
12 | flib.array 2 py ( data .ctypes. data , n 1 , n 2 ) |
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位。。。。谢谢大侠指点。
|
|