如果子程序中有以下代码(thanks to M. Chinoune)
type :: vector
integer, dimension(:), allocatable :: elements
end type vector
type :: ragged_array
type(vector), dimension(:), allocatable :: vectors
end type ragged_array
type(ragged_array) :: raggar
allocate( raggar%vectors(2) )
allocate( raggar%vectors(1)%elements(3) )
allocate( raggar%vectors(2)%elements(4) )
raggar%vectors(1)%elements=0
raggar%vectors(2)%elements=0 如果我想在另一个子程序中传递raggar以修改raggar的大小。我是否应该这样做:
CALL MySubroutine(raggar)或
CALL MySubroutine(raggar%vectors%elements)然后,在我的子程序中,我如何声明它?
SUBROUTINE MySubroutine(raggar)
type :: vector
integer, dimension(:), allocatable :: elements
end type vector
type :: ragged_array
type(vector), dimension(:), allocatable :: vectors
end type ragged_array
type(ragged_array), INTENT(INOUT):: raggar我做了很多尝试,但我总是遇到错误,例如:
The type of the actual argument differs from the types of the dummy argument.
或
the shape matching rules of actual arguments and dummy argument have been violated
发布于 2017-06-06 17:37:42
将类型定义放入模块中,并在程序和子程序中使用。
module my
type :: vector
integer, dimension(:), allocatable :: elements
end type vector
type :: ragged_array
type(vector), dimension(:), allocatable :: vectors
end type ragged_array
end module
program probe
use my
type(ragged_array) :: ragarr
allocate( ragarr%vectors(2) )
allocate( ragarr%vectors(1)%elements(3) )
allocate( ragarr%vectors(2)%elements(4) )
ragarr%vectors(1)%elements=0
ragarr%vectors(2)%elements=0
CALL MySubroutine(ragarr)
end program
SUBROUTINE MySubroutine(rr)
use my
type(ragged_array), INTENT(INOUT):: rr
end subroutinehttps://stackoverflow.com/questions/44395450
复制相似问题