我正在尝试编写一个fortran例程,其中我声明了数组,其长度来自对输入参数进行的操作。
subroutine my_program(N, A,B,m)
implicit none
integer, intent(in) :: N
integer, parameter :: minA = 1, maxA = N
integer, parameter :: minB = 0, maxB = N-1
double precision, intent(out) :: max,A(minA:maxA),B(minB:maxB)
A = 0.d0
B = 1.d0
m = maxA*maxB-minA*minB
end subroutine my_program
现在,我从第5行Parameter 'N' at (1) has not been declared or is a variable, which does not reduce to a constant expression
答案 0 :(得分:2)
N
,因此您无法使用它来初始化parameter
。相反,请直接使用N
来声明A
和B
:
subroutine my_program(N, A, B, m)
implicit none
integer, intent(in) :: N
double precision, intent(out) :: m, A(1:N), B(0:N-1)
integer :: minA, maxA
integer :: minB, maxB
minA = 1 ; maxA = N
minB = 0 ; maxB = N-1
A = 0.d0
B = 1.d0
m = maxA*maxB - minA*minB
end subroutine my_program