繁体   English   中英

(1)中的外部函数'f'在具有f2py的子例程中没有IMPLICIT类型

[英]External function ‘f’ at (1) has no IMPLICIT type in subroutine with f2py

我已经使用Fortran 90一段时间了,最​​近决定使用f2py封装一些模块,以使用Python作为前端来简化原型设计。

但是,在尝试编译通过外部函数(从Python)传递的子例程时遇到错误。 这是复制错误的代码:

! file: callback.f90
subroutine callback(f,x,y)
  implicit none
  ! - args -
  ! in
  external :: f
  real(kind=kind(0.0d0)), intent(in) :: x
  ! out
  real(kind=kind(0.0d0)), intent(inout) :: y

  y = f(x)
end subroutine

现在,如果我使用f2py生成签名文件(.pyf),则将获得以下信息:

!    -*- f90 -*- 
! Note: the context of this file is case sensitive.
python module callback__user__routines 
interface callback_user_interface 
    function f(x) result (y) ! in :callback:callback.f90
        intent(inout) f
        real(kind=kind(0.0d0)) intent(in) :: x
        real(kind=kind(0.0d0)) intent(inout) :: y
    end function f
end interface callback_user_interface
end python module callback__user__routines
python module callback ! in  
    interface  ! in :callback
        subroutine callback(f,x,y) ! in :callback:callback.f90
            use callback__user__routines
            external f
            real(kind=kind(0.0d0)) intent(in) :: x
            real(kind=kind(0.0d0)) intent(inout) :: y
        end subroutine callback
    end interface 
end python module callback

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

这是不正确的,因此我通过以下方式对其进行了更改:

!    -*- f90 -*- 
! Note: the context of this file is case sensitive.
python module __user__routines
    interface
        function f(x) result (y) 
            real(kind=kind(0.0d0)) intent(in) :: x
            real(kind=kind(0.0d0)) :: y
        end function f
    end interface
end python module __user__routines
python module callback ! in  
    interface  ! in :callback
        subroutine callback(f,x,y)
            use __user__routines
            external f
            real(kind=kind(0.0d0)) intent(in) :: x
            real(kind=kind(0.0d0)) intent(inout) :: y
        end subroutine callback
    end interface 
end python module callback

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

但是,两者都抛出一个错误,告诉我我还没有定义f:

callback.f90:1:21:
subroutine callback(f,x,y)
                    1
Error: Symbol ‘f’ at (1) has no IMPLICIT type
callback.f90:10:6:

  y = f(x)
      1
Error: Can't convert UNKNOWN to REAL(8) at (1)
callback.f90:1:21:

subroutine callback(f,x,y)
                    1
Error: Symbol ‘f’ at (1) has no IMPLICIT type
callback.f90:10:6:

   y = f(x)
       1
Error: Can't convert UNKNOWN to REAL(8) at (1)

我已经对手动正确编辑.pyf签名文件进行了尽可能多的研究,但在这种情况下无济于事。 尝试将f2py与外部函数一起使用时,有人遇到过类似的错误吗?

该错误是正确的,并且是Fortran错误,即使没有任何f2py或Python也会发生

subroutine callback(f,x,y)
  implicit none
  external :: f
  real(kind=kind(0.0d0)), intent(in) :: x
  real(kind=kind(0.0d0)), intent(inout) :: y

  y = f(x)
end subroutine

f没有声明任何类型,并且未启用implicit none类型,因此这是Fortran错误。

采用

  real(kind=kind(0.0d0)), external :: f

要么

  external :: f
  real(kind=kind(0.0d0)) :: f

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM