使用f2py编译fortran模块 [英] Compile fortran module with f2py

查看:227
本文介绍了使用f2py编译fortran模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Fortran模块,我试图用f2py编译(列在下面)。当我删除模块声明并将它自己的子例程留在文件中时,一切正常。但是,如果模块声明如下所示,则得到以下结果:

 > f2py.py -c -m其中--compiler = mingw itimes-s2.f 
...
阅读fortran代码...
阅读文件'itimes-s2.f'(格式:fix,strict)
crackline:groupcounter = 1 groupname = {0:'',1:'module',2:'interface',3:'subroutine'}
crackline:遇到的块不匹配。试图通过假设结束声明来解决它。
...
c:\users\astay13\appdata\local\temp\tmpgh5ag8\Release\users\astay13\appdata\local\temp\ tmpgh5ag8\src.win32-3.2\itsmodule.o:itsmodule.c :(。data + 0xec):对`itimes_'的未定义引用
collect2:ld返回1退出状态

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

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

itimes-s2.f:

  b 
$ b包含

子程序itimes(infile,outfile)

隐含无

!常量
整数,参数:: dp = selected_real_kind(15)

!子例程输入
字符(*),意图(in):: infile
字符(*),意图(in):: outfile

!内部变量
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' )


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

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

end subroutine itimes

end module


解决方案

您正尝试在Python模块中使用Fortran模块。如果你想要,名称必须不同,例如

  f2py.py -c -m SOMEDIFFERENTNAME itimes-s2.f 

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



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


I have a Fortran module which I am trying to compile with f2py (listed below). When I remove the module declaration and leave the subroutine in the file by itself, everything works fine. However, if the module is declared as shown below, I get the following results:

> 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

What is different about compiling a module or subroutine in f2py? Have I left something important out in the module that causes f2py to have trouble? Note that the module compiles fine when I use gfortran alone.

Software: 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

解决方案

You are trying to have a Fortran module in a Python module. If you want that, the names must be different, e.g.

 f2py.py -c -m SOMEDIFFERENTNAME itimes-s2.f

The result will be called as pythonmodule.fortranmodule.yourfunction().

Otherwise it worked on my machine.

这篇关于使用f2py编译fortran模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆