I am still trying to get to grips with how one should copy derived types
that contain allocatable
arrays. The test program below, when compiled with IVF 10.1, displays the
cdata array contents
correctly, but gives an access violation in the deallocation step. If I
neglect the deallocation
there are no error messages. When compiled on IBM Linux (with xlf95_r) it
runs without errors. But
running my real program, in which I am presumably doing something wrong,
on the IBM machine there is
no error until the deallocation step, which is carried out exactly as in
the code below, and then I
get a multitude of error messages like
glibc detected *** double free or corruption (!prev): 0x100a0220
and
glibc detected *** corrupted double-linked list: 0x1009db18
Is it OK to do
cell2(i) = cell1(i)
when cell2(i)%cdata has not been allocated, or do I first need to ensure
that %cdata is allocated?
!----------------------------------------------------------------
program main
integer :: csize(2) = (/10,100/)
integer :: k, i
type cell_type
integer :: ID
real, allocatable :: cdata(:)
end type
type(cell_type), allocatable :: cell1(:),cell2(:)
allocate(cell1(2))
allocate(cell2(2))
do i = 1,2
allocate(cell1(i)%cdata(csize(i)))
do k = 1,csize(i)
cell1(i)%cdata(k) = k
enddo
enddo
do i = 1,2
cell2(i) = cell1(i) ! cell2(i)%cdata not allocated
write(*,*) cell2(i)%cdata
enddo
do i = 1,2
do k = 1,csize(i)
if (allocated(cell1(i)%cdata)) then
deallocate(cell1(i)%cdata)
endif
enddo
if (allocated(cell1)) then
deallocate(cell1)
endif
enddo
do i = 1,2
do k = 1,csize(i)
if (allocated(cell2(i)%cdata)) then
deallocate(cell2(i)%cdata)
endif
enddo
if (allocated(cell2)) then
deallocate(cell2)
endif
enddo
end
------------ And now a word from our sponsor ------------------
Want to have instant messaging, and chat rooms, and discussion
groups for your local users or business, you need dbabble!
-- See http://netwinsite.com/sponsor/sponsor_dbabble.htm
----


|