1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
module A
implicit none
type D
integer :: member
end type
type E
type(D), allocatable :: ds(:)
end type
type F
type(E), allocatable :: es(:)
end type
contains
function get_ds() result(ds)
type(D), allocatable :: ds(:)
ds = [D(1), D(2), D(3)]
end function
subroutine new_ds(self)
type(F), intent(inout) :: self
if( .not. allocated(self%es) ) error stop
self%es(2)%ds = get_ds()
end subroutine
end module
program allocate_12
use A
implicit none
type(F) :: fobj(2)
allocate(fobj(2)%es(3))
if(.not. allocated(fobj(2)%es)) error stop
if( allocated(fobj(1)%es) ) error stop
call new_ds(fobj(2))
print *, fobj(2)%es(2)%ds
if( fobj(2)%es(2)%ds(1)%member /= 1 ) error stop
if( fobj(2)%es(2)%ds(2)%member /= 2 ) error stop
if( fobj(2)%es(2)%ds(3)%member /= 3 ) error stop
if( any(fobj(2)%es(2)%ds(:)%member /= (/1, 2, 3/)) ) error stop
end program
|