我看到this post关于制作一个参差不齐的数组。
当我尝试这样做时,一切正常,直到我想要访问这个数组。
type :: vector
integer, dimension(:), allocatable :: elements
end type vector
type :: ragged_array
type(vector), dimension(:), allocatable :: vectors
end type ragged_array
type(ragged_array) :: ragarr
allocate(ragarr%vectors(1)%elements(3))
allocate(ragarr%vectors(2)%elements(4))
!PROBLEM HERE :
raggar(1,1:3)=0
raggar(2,1:4)=1
它给我错误:
The assigment operation or the binary expression operation is invalid for the data type of two operands
我还不清楚如何操纵这个不规则的阵列,如何访问特定的值...感谢您的帮助!
答案 0 :(得分:2)
您的代码包含许多错误:
更正后的代码:
type :: vector
integer, dimension(:), allocatable :: elements
end type vector
type :: ragged_array
type(vector), dimension(:), allocatable :: vectors
end type ragged_array
type(ragged_array) :: ragarr
allocate( raggar%vectors(2) )
allocate( ragarr%vectors(1)%elements(3) )
allocate( ragarr%vectors(2)%elements(4) )
!PROBLEM HERE :
raggar%vectors(1)%elements=0 !raggar(1,1:3)=0
raggar%vectors(2)%elements=0 !raggar(2,1:4)=1