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

约翰·卢克·卢斯蒂

我已经使用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与外部函数一起使用时,有人遇到过类似的错误吗?

弗拉基米尔F

该错误是正确的,并且是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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我可以在带有子例程调用的子例程上使用F2PY吗?

为什么我不能通过f2py调用Fortran子例程而没有正确数量的输入?

f2py 编译的 Fortran 模块中的垃圾收集

具有可变类型的F#函数

F#中带有类型注释的值限制,而没有显式函数参数

Scala中具有抽象类型的F界多态

F#中没有装箱的多参数事件类型

f2py:将数组预先分配为Fortran子例程的输入

如何使用f2py将字符串数组传递给Fortran子例程

如何在Visual Studio代码中调试从F2py接口调用共享库中的C函数的python程序

使用f2py编译后,获取模块没有属性错误

使用setuptools将f2py生成的* .so文件链接到python包中

如何告诉f2py模块在当前目录中查找共享对象依赖项

在用f2py包装的模块中包含已编译模块(最小工作示例)?

f2py在不同版本的Fortran和CPython中的性能是否不同

无法使用f2py编译功能中的fortran代码

没有变量的 F# 中的 SUMPRODUCT

具有F#函数类型的扩展方法

具有F边界类型和存在性类型的Scala中的编译问题

具有不同返回类型的F#中的区分联合类型检查

为什么不能通过f2py输入正确数量的输入参数来调用Fortran子例程?

为什么方法参数F与类型构造函数F具有相同的名称?

如何在golang中的F2()之前调用函数F1()

在 Python 中动态创建函数——f(2) 无法解析 (f1)

没有要调用的匹配函数:错误:必须使用'。*'或'-> *'来调用'f(...)'中的指针成员函数,例如'(...-> * f)( ...)'

函数中的子shell`(别名;声明-f)`

如何在F#中没有度量的情况下创建度量记录类型

有没有更好的方法在F#/ OCaml中编写交换函数?

由于在模块/公共块中定义了参数数组的尺寸,导致f2py并发症