使用f2py编译fortran模块

ast*_*y13 6 python fortran f2py

我有一个Fortran模块,我试图用f2py编译(下面列出).当我删除模块声明并将子程序单独保留在文件中时,一切正常.但是,如果声明模块如下所示,我得到以下结果:

> f2py.py -c -m its --compiler=mingw itimes-s2.f
...
Reading fortran codes...
    Reading file 'itimes-s2.f' (format:fix,strict)
crackline: groupcounter=1 groupname={0: '', 1: 'module', 2: 'interface', 3: 'subroutine'}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming "end" statement.
...
c:\users\astay13\appdata\local\temp\tmpgh5ag8\Release\users\astay13\appdata\local\temp\tmpgh5ag8\src.win32-3.2\itsmodule.o:itsmodule.c:(.data+0xec): undefined reference to `itimes_'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

在f2py中编译模块或子程序有什么不同?我是否在模块中留下了一些重要的东西导致f2py出现问题?请注意,当我单独使用gfortran时,模块编译得很好.

软件:Windows 7; gcc,gfortran 4.6.1(MinGW); python 3.2.2; f2py v2

itimes-s2.f:

  module its

  contains

  subroutine itimes(infile,outfile)

    implicit none

    ! Constants
    integer, parameter :: dp = selected_real_kind(15)

    ! Subroutine Inputs
    character(*), intent(in) :: infile
    character(*), intent(in) :: outfile

    ! Internal variables
    real(dp) :: num
    integer :: inu
    integer :: outu
    integer :: ios

    inu = 11
    outu = 22

    open(inu,file=infile,action='read')
    open(outu,file=outfile,action='write',access='append')

    do
      read(inu,*,IOSTAT=ios) num
      if (ios < 0) exit

      write(outu,*) num**2
    end do

  end subroutine itimes

  end module its
Run Code Online (Sandbox Code Playgroud)

Vla*_*r F 9

您正在尝试在Python模块中安装Fortran模块.如果你想要,那么名字必须是不同的,例如

 f2py.py -c -m SOMEDIFFERENTNAME itimes-s2.f
Run Code Online (Sandbox Code Playgroud)

结果将被称为pythonmodule.fortranmodule.yourfunction().

否则它在我的机器上工作.