Arrays 在不规则数组中访问的语法?
我看到了制作一个不规则阵列的想法 当我尝试这样做时,一切都会工作,直到我想要访问此阵列为止Arrays 在不规则数组中访问的语法?,arrays,fortran,Arrays,Fortran,我看到了制作一个不规则阵列的想法 当我尝试这样做时,一切都会工作,直到我想要访问此阵列为止 type :: vector integer, dimension(:), allocatable :: elements end type vector type :: ragged_array type(vector), dimension(:), allocatable :: vectors end type ragged_array type(ragged_array) :: ra
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
我还不清楚如何操作这个不规则的数组,如何访问特定的值。。。谢谢你的帮助 您的代码包含许多错误:
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
您的代码包含许多错误:
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
有没有一种方法可以将整个
raggar
传递给子程序的参数?似乎执行raggar%vectors%elements
不起作用……有没有办法让整个raggar
通过子程序的参数传递?似乎做raggar%vectors%elements
不起作用。。。。