我在 fortran 中有这个简单的代码,包含三个子例程:
module test
contains
subroutine aa1(aa,bb,cc)
implicit none
!----------------------------------------------------------------------
integer, intent(in) :: aa
real(8), intent(out) :: bb
real(8), intent(out) :: cc
!----------------------------------------------------------------------
bb = aa*1.5
cc = 1.d0
endsubroutine
subroutine bb1(aa,bb,cc)
implicit none
!----------------------------------------------------------------------
integer, intent(in) :: aa
real(8), intent(out) :: bb
real(8), intent(out) :: cc
!----------------------------------------------------------------------
bb = aa*1.5
cc = 1.d0
endsubroutine
subroutine cc1(aa,bb,cc)
implicit none
!----------------------------------------------------------------------
integer, intent(in) :: aa
real(8), intent(out) :: bb
real(8), intent(out) :: cc
!----------------------------------------------------------------------
bb = aa*1.5
cc = 1.d0
endsubroutine
end module
这是通过f2py链接到python的,如下所示:
from test import test
wx,wy = test.aa1(1)
wx,wy = test.bb1(1)
wx,wy = test.cc1(1)
我将 FORTRAN 模块编译为:
f2py3 -m test -c test.f90
此时,当我运行python代码时出现以下错误:
Traceback (most recent call last):
File "test_py.py", line 40, in <module>
wx,wy = test.bb1(1)
AttributeError: 'fortran' object has no attribute 'bb1'
我做错了什么?每个 FORTRAN 子程序都必须有一个模块吗?
谢谢,