我有以下一段代碼將矢量x
分成幾個數組。根據子程序自變量創建一個常量
subroutine split(n, x, r, v, p, t)
implicit none
integer, intent(in) :: n
double precision, intent(in) :: x(n)
integer, parameter :: m = (n + 6)/10
! problem here 1
double precision, intent(out) :: r(3, m - 1)
double precision, intent(out) :: v(3, m - 1)
double precision, intent(out) :: p(3, m)
double precision, intent(out) :: t(m)
! code
end subroutine split
此代碼不能與消息
Error: Parameter 'n' at (1) has not been declared or is a variable, which does not reduce to a constant expression
代碼編譯的罰款,如果我手動更改所有m
到(n + 6)/10
但我尋求一個更優雅的方式編譯。
作爲一種替代方法,我已經重寫了代碼
subroutine splitcore(n, m, x, r, v, p, t)
implicit none
integer, intent(in) :: n, m
double precision, intent(in) :: x(n)
double precision, intent(out) :: r(3, m - 1)
double precision, intent(out) :: v(3, m - 1)
double precision, intent(out) :: p(3, m)
double precision, intent(out) :: t(m)
! code
end subroutine splitcore
subroutine split(n, x, r, v, p, t)
implicit none
integer, intent(in) :: n
double precision, intent(in) :: x(n)
integer :: m
double precision, intent(out) :: r(3, *)
double precision, intent(out) :: v(3, *)
double precision, intent(out) :: p(3, *)
double precision, intent(out) :: t(*)
m = (n + 6)/10
call splitcore(n, m, x, r, v, p, t)
end subroutine split
您不能使用值初始化常量o f變量。 – Wildcat