<i id='q9Sl9'><tr id='q9Sl9'><dt id='q9Sl9'><q id='q9Sl9'><span id='q9Sl9'><b id='q9Sl9'><form id='q9Sl9'><ins id='q9Sl9'></ins><ul id='q9Sl9'></ul><sub id='q9Sl9'></sub></form><legend id='q9Sl9'></legend><bdo id='q9Sl9'><pre id='q9Sl9'><center id='q9Sl9'></center></pre></bdo></b><th id='q9Sl9'></th></span></q></dt></tr></i><div id='q9Sl9'><tfoot id='q9Sl9'></tfoot><dl id='q9Sl9'><fieldset id='q9Sl9'></fieldset></dl></div>
<legend id='q9Sl9'><style id='q9Sl9'><dir id='q9Sl9'><q id='q9Sl9'></q></dir></style></legend>

        <small id='q9Sl9'></small><noframes id='q9Sl9'>

      1. <tfoot id='q9Sl9'></tfoot>
          <bdo id='q9Sl9'></bdo><ul id='q9Sl9'></ul>

        使用 f2py 编译 Fortran 模块

        时间:2023-09-12
        <legend id='W6NFY'><style id='W6NFY'><dir id='W6NFY'><q id='W6NFY'></q></dir></style></legend>
          <tbody id='W6NFY'></tbody>

            <tfoot id='W6NFY'></tfoot>
            1. <small id='W6NFY'></small><noframes id='W6NFY'>

                <bdo id='W6NFY'></bdo><ul id='W6NFY'></ul>
              • <i id='W6NFY'><tr id='W6NFY'><dt id='W6NFY'><q id='W6NFY'><span id='W6NFY'><b id='W6NFY'><form id='W6NFY'><ins id='W6NFY'></ins><ul id='W6NFY'></ul><sub id='W6NFY'></sub></form><legend id='W6NFY'></legend><bdo id='W6NFY'><pre id='W6NFY'><center id='W6NFY'></center></pre></bdo></b><th id='W6NFY'></th></span></q></dt></tr></i><div id='W6NFY'><tfoot id='W6NFY'></tfoot><dl id='W6NFY'><fieldset id='W6NFY'></fieldset></dl></div>

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

                  问题描述

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

                  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:usersastay13appdatalocal	emp	mpgh5ag8Releaseusersastay13appdatalocal	emp	mpgh5ag8src.win32-3.2itsmodule.o:itsmodule.c:(.data+0xec): undefined reference to `itimes_'
                  collect2: ld returned 1 exit status
                  

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

                  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.

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

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

                  times-s2.f:

                  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
                  

                  推荐答案

                  您试图在 Python 模块中包含 Fortran 模块.如果需要,名称必须不同,例如

                  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
                  

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

                  你也可以导入为

                  from pythonmodule import fortranmodule
                  fortranmodule.yourfunction()
                  

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

                  Otherwise it worked on my machine.

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

                  上一篇:如何轻松地将 FORTRAN 代码转换为 Python 代码(真实 下一篇:读取fortran未格式化文件时记录标记不一致

                  相关文章

                  最新文章

                1. <legend id='IaIRc'><style id='IaIRc'><dir id='IaIRc'><q id='IaIRc'></q></dir></style></legend>
                    <i id='IaIRc'><tr id='IaIRc'><dt id='IaIRc'><q id='IaIRc'><span id='IaIRc'><b id='IaIRc'><form id='IaIRc'><ins id='IaIRc'></ins><ul id='IaIRc'></ul><sub id='IaIRc'></sub></form><legend id='IaIRc'></legend><bdo id='IaIRc'><pre id='IaIRc'><center id='IaIRc'></center></pre></bdo></b><th id='IaIRc'></th></span></q></dt></tr></i><div id='IaIRc'><tfoot id='IaIRc'></tfoot><dl id='IaIRc'><fieldset id='IaIRc'></fieldset></dl></div>
                    <tfoot id='IaIRc'></tfoot>

                    <small id='IaIRc'></small><noframes id='IaIRc'>

                    • <bdo id='IaIRc'></bdo><ul id='IaIRc'></ul>