小编Ast*_*ist的帖子

在模块中使用外部函数

我正在用 Fortran 编写一个 n 维数值求解器。我为此创建了一个从主程序调用的模块。我external在为一阶 ode 编写时用于调用未知函数。但是,在使用多维复制结果时,external出现以下错误

Error: EXTERNAL attribute conflicts with DIMENSION attribute in 'f_x' 
Run Code Online (Sandbox Code Playgroud)

这意味着我的编译器无法处理带有数组输出的外部函数。

我尝试使用接口块来预定义具有固定维度的函数参数,但最终出现此错误

Error: PROCEDURE attribute conflicts with INTENT attribute in 'f_x' 
Run Code Online (Sandbox Code Playgroud)

Fortran 中是否有任何方法可以让外部函数返回使用子例程中的虚拟函数初始化的数组。

这是我使用的代码。

module int_adaptive
implicit none
contains

subroutine RK4nd(f_x, norder, nvar, x_0, t_0, t_f, x_out, t_out)
    INTERFACE
        FUNCTION f_x (x_0, t_0)
            integer, parameter  :: dp=kind(0.d0)
            REAL(dp), INTENT(IN)    :: x_0(2, 3), t_0
            REAL, intent(out)   :: f_x(2,3)
        END FUNCTION f_x
    END INTERFACE


    integer, parameter  :: dp=kind(0.d0)
    integer             :: norder, i, …
Run Code Online (Sandbox Code Playgroud)

fortran gfortran

2
推荐指数
1
解决办法
2204
查看次数

标签 统计

fortran ×1

gfortran ×1