Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Derived types a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 26 Topic 8212 of 8528
Post > Topic >>

Derived types and allocatable

by Gib Bogle <g.bogle@[EMAIL PROTECTED] > May 6, 2008 at 04:01 PM

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
 ----
 




 26 Posts in Topic:
Derived types and allocatable
Gib Bogle <g.bogle@[EM  2008-05-06 16:01:28 
Re: Derived types and allocatable
Gib Bogle <g.bogle@[EM  2008-05-06 18:09:36 
Re: Derived types and allocatable
"James Van Buskirk&q  2008-05-06 00:41:26 
Re: Derived types and allocatable
Steven Correll <steven  2008-05-06 07:08:11 
Re: Derived types and allocatable
"James Giles" &  2008-05-11 00:26:34 
Re: Derived types and allocatable
=?ISO-8859-15?Q?Jan_Vorbr  2008-05-14 12:07:46 
Re: Derived types and allocatable
"James Giles" &  2008-05-14 19:30:39 
Re: Derived types and allocatable
glen herrmannsfeldt <g  2008-05-14 12:39:38 
Re: Derived types and allocatable
"James Giles" &  2008-05-14 20:49:59 
Re: Derived types and allocatable
glen herrmannsfeldt <g  2008-05-14 13:27:46 
Re: Derived types and allocatable
"James Giles" &  2008-05-14 21:40:48 
Re: Derived types and allocatable
=?ISO-8859-15?Q?Jan_Vorbr  2008-05-15 11:14:13 
Re: Derived types and allocatable
"James Van Buskirk&q  2008-05-14 11:03:21 
Re: Derived types and allocatable
"James Giles" &  2008-05-14 19:37:02 
Re: Derived types and allocatable
"Kurt Kallblad"  2008-05-07 07:56:49 
Re: Derived types and allocatable
nospam@[EMAIL PROTECTED]   2008-05-07 00:15:43 
Re: Derived types and allocatable
Gib Bogle <bogle@[EMAI  2008-05-08 08:35:27 
Re: Derived types and allocatable
Damian <damian@[EMAIL   2008-05-07 12:03:34 
Re: Derived types and allocatable
Steve Lionel <Steve.Li  2008-05-07 15:33:13 
Re: Derived types and allocatable
Damian <damian@[EMAIL   2008-05-08 09:05:09 
Re: Derived types and allocatable
Steve Lionel <Steve.Li  2008-05-08 12:52:00 
Re: Derived types and allocatable
Damian <damian@[EMAIL   2008-05-08 19:56:55 
Re: Derived types and allocatable
Steve Lionel <Steve.Li  2008-05-09 14:11:34 
Re: Derived types and allocatable
Damian <damian@[EMAIL   2008-05-09 12:15:07 
Re: Derived types and allocatable
"James Van Buskirk&q  2008-05-06 00:11:29 
Re: Derived types and allocatable
Gib Bogle <g.bogle@[EM  2008-05-06 18:39:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 18 20:40:54 CDT 2008.