具有多个子例程的f2py模块

2024-09-26 22:51:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我用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子例程都必须有一个模块吗

谢谢, D


Tags: intestnoneoutrealaaccmodule

热门问题