Error in Derived type declaration: Variable at (1) in this context must be constant

戏子无情 提交于 2019-12-02 03:31:13

Yes. Declaring an explicit-shape array in a non-parameterized derived type requires a constant expression. You could either

  • make k allocatable,dimension(:,:) (and (de-)allocation), or
  • make nrx and maxprx global/module constants (or replace them right away).

If your compiler supports it, you can use parameterized derived types:

  type :: PRM(nrx,maxprx)  ! parameterized derived type definition
    integer, len :: nrx
    integer, len :: maxprx
    real         :: k(nrx,maxprx) 
    ! ...
  end type PRM

(Taken and adjusted from here.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!