ベクトル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
私は手動で(n + 6)/10
にすべてm
を変更するが、私はよりエレガントなアプローチを求めている場合は、コードが正常にコンパイルしてコンパイルされません。
は別のアプローチとして、私はそれが不可能な
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
値を使用して定数を初期化することはできません。 f変数。 – Wildcat