Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python f2py和capi_返回为空_Python_Fortran_F2py - Fatal编程技术网

Python f2py和capi_返回为空

Python f2py和capi_返回为空,python,fortran,f2py,Python,Fortran,F2py,我遇到了我认为可能是f2py中的一个bug,并回调到 python或者,也许我没有正确地使用东西。我创建了一个 非常简单的例子说明了我的问题: 要重现我的问题: python 2.7.8 格弗特兰 f.f: subroutine test cf2py intent(callback, hide) fred cf2py intent(callback, hide) bambam external fred external bambam inte

我遇到了我认为可能是f2py中的一个bug,并回调到 python或者,也许我没有正确地使用东西。我创建了一个 非常简单的例子说明了我的问题:

要重现我的问题:

python 2.7.8

格弗特兰

f.f:

    subroutine test 
    cf2py intent(callback, hide) fred
    cf2py intent(callback, hide) bambam
    external fred
    external bambam
    integer n
    n = 4
    write (*,*) "Yabba Dabba Doo! In Subroutine TEST" 
    write (*,*) "Calling Fred:"
    call fred
    write (*,*) "Calling Bambam:"
    call bambam(n)
    end
      subroutine barney
      write (*,*) "In Subroutine BARNEY"
      write (*,*) "Calling Subroutine TEST"
      call test
      end
nocallback.f:

    subroutine test 
    cf2py intent(callback, hide) fred
    cf2py intent(callback, hide) bambam
    external fred
    external bambam
    integer n
    n = 4
    write (*,*) "Yabba Dabba Doo! In Subroutine TEST" 
    write (*,*) "Calling Fred:"
    call fred
    write (*,*) "Calling Bambam:"
    call bambam(n)
    end
      subroutine barney
      write (*,*) "In Subroutine BARNEY"
      write (*,*) "Calling Subroutine TEST"
      call test
      end
弗林斯通

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module test__user__routines 
    interface test_user_interface 
        subroutine fred ! in :flintstone:callback.f:test:unknown_interface
            intent(callback,hide) fred
        end subroutine fred
        subroutine bambam(n) ! in :flintstone:callback.f:test:unknown_interface
            intent(callback,hide) bambam
            integer :: n
        end subroutine bambam
    end interface test_user_interface
end python module test__user__routines
python module flintstone ! in 
    interface  ! in :flintstone
        subroutine test ! in :flintstone:callback.f
            use test__user__routines, fred=>fred, bambam=>bambam
            intent(callback, hide) fred
            external fred
            intent(callback,hide) bambam
            external bambam
        end subroutine test
        subroutine barney ! in :flintstone:nocallback.f
        external test
        end subroutine barney
        end interface 
end python module flintstone

! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/
cb.py

f2py-c-m flintstone-flintstone.pyf callback.f nocallback.f

ipython>运行cb.py

我得到以下输出:

In [1]: run cb.py
 Yabba Dabba Doo! In Subroutine TEST
 Calling Fred:
fred!
 Calling Bambam:
bambam: I want 4 Brontosaurus Burgers!
 In Subroutine BARNEY
 Calling Subroutine TEST
 Yabba Dabba Doo! In Subroutine TEST
 Calling Fred:
fred!
 Calling Bambam:
capi_return is NULL
Call-back cb_bambam_in_test__user__routines failed.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/deen/Code/Python/sandbox/fluffy-kumquat/cb.py in <module>()
     12
     13 flintstone.test()
---> 14 flintstone.barney()
     15 
     16 

TypeError: bambam() takes exactly 1 argument (0 given)
然后,它将不会尝试分析bar,因为隐式假设所有没有引用foo参数的语句都与包装器函数生成无关。 例如,f2py需要一些帮助。请在.pyf文件中尝试以下签名:

 subroutine barney ! in :flintstone:nocallback.f
     use test__user__routines, fred=>fred, bambam=>bambam
     intent(callback, hide) fred
     external fred
     intent(callback,hide) bambam
     external bambam
 end subroutine barney
顺便说一句,而不是

f2py-c-m flintstone-flintstone.pyf callback.f nocallback.f

使用

f2py-c flintstone.pyf callback.f nocallback.f


因为模块名来自.pyf文件。

没有f2py,您是如何编译它的?你当时是怎么提供这些废话的?我真的不明白你在那个失败的案例中做了什么。我举的这个例子只是想让你了解一下我所看到的。。。如果您转到github存储库,您可以看到我使用的确切命令以及确切的错误消息…嗨,Vladimir-感谢您的建议。。。我应该包括所有的文件吗?或者这就足够了?如果你把你的修正作为一个答案,而不是将其编辑到问题中,可能会更清楚一点(请参见)请不要在标题中使用修正。此外,最好张贴答案,不要将答案编辑到问题中。