提问人:zpan 提问时间:1/13/2022 更新时间:1/13/2022 访问量:61
使用 f2py 模块时如何处理内在功能?
How to deal with the intrinsic funtion when using f2py module?
问:
我有一个 Fortran 代码,并尝试使用 f2py 将其编译成 Python 模块。Fortran 代码“drandn.f”如下:
SUBROUTINE DRANDN (N,DX,SEED)
INTRINSIC DBLE, IABS, MOD
INTEGER N, SEED
DOUBLE PRECISION DX(N)
INTEGER I, J
DOUBLE PRECISION DMAX
INTEGER IM, IMAX, IS
SAVE DMAX, IM, IMAX, IS
DATA IM/0/
IF (IM.EQ.0) THEN
J = 0
IM = 1
DO 10 I = 1, 31
J = J + 1
IF (IM*2.LE.IM) GO TO 20
IM = IM * 2
10 CONTINUE
20 IMAX = (IM-1) * 2 + 1
DMAX = DBLE(IMAX)
DO 30 I = 1, MOD(J,3)
J = J - 1
IM = IM / 2
30 CONTINUE
IM = IM + 5
IS = IABS(MOD(IM*30107,IMAX))
END IF
IF (SEED.GT.0) IS = (SEED / 2) * 2 + 1
DO 40 I = 1, N
DX(I) = DBLE(IS) / DMAX
IS = IABS(MOD(IM*IS,IMAX))
40 CONTINUE
RETURN
END
我尝试使用以下命令编译它:
f2py drandn.f -m drandn -h drandn.pyf
“drandn.pyf”代码:
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module drandn ! in
interface ! in :drandn
subroutine drandn(n,dx,seed) ! in :drandn:drandn.f
integer :: n
double precision dimension(n) :: dx
integer :: seed
end subroutine drandn
end interface
end python module drandn
! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/
我尝试使用以下命令编译它:
f2py -c -m drandn drandn.pyf
但是当我导入 drandn 模块时,我收到一个错误:
ImportError Traceback (most recent call last)
<ipython-input-1-2d31b1e24e91> in <module>
3 import numpy as np
4 import math
----> 5 from fortran_sourcecode import drandn
ImportError: /public/home/zpan/pyscf-gsc/fortran_sourcecode/drandn.cpython-37m-x86_64-linux-gnu.so: undefined symbol: drandn_
(路径是正确的。我已经编译了另一个 fortran 代码,它可以工作。 我该如何解决这个问题?我很困惑。
答: 暂无答案
评论