gpt4 book ai didi

arrays - 使用 Intent(in) 参数初始化 Fortran 参数

转载 作者:行者123 更新时间:2023-12-02 03:20:42 26 4
gpt4 key购买 nike

考虑以下程序:

Subroutine foo(p,v)
implicit none
integer, intent(in) :: p
double precision, dimension(p), intent(in) :: v

!local variables
integer,parameter :: n=floor(par(p))
double precision :: z(2*n)

[...]
End Subroutine

我收到以下错误:

Error: Array ‘v’ at (1) is a variable, which does not reduce to a constant expression

这是非常明确的,但我想知道是否有一种方法可以管理这种情况:将子例程的 intent(in) 参数分配给参数变量?

最佳答案

不,那是不可能的。参数是一个编译时常量。它的值不能来自任何参数或变量。

也完全不清楚您为什么要这样做(请参阅 https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem )。您不需要需要参数来声明数组

double precision :: z(2*floor(par(p)))

因为在自动数组中,边界可以是过程参数。

关于arrays - 使用 Intent(in) 参数初始化 Fortran 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54899939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com