ALLOCATABLE components of derived types

ALLOCATABLE components of derived types

Apparantly CVF 6.6B has support for ALLOCATABLE components of derived types. Does anyone have a code snippet showing how to avail of this F2K feature? (I've looked in the HTML and samples folder but I didn't come across anything relevant.)

Thank you,
Gerry T.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Here is an example:

program allcomp
implicit none
type stuff
  integer length
  integer, allocatable :: value(:)
end type stuff
real h
integer max_fields, i, j
type (stuff), allocatable :: fields(:)

call RANDOM_SEED ()
max_fields = 20

! allocate data structure, random number of
! values per field

ALLOCATE (fields(max_fields))
do i = 1, max_fields
  call RANDOM_NUMBER (h)
  fields(i)%length = FLOOR(h*9.) + 1
  ALLOCATE (fields(i)%value(fields(i)%length))
end do

! initialize each existing value to its index

do i = 1, max_fields
  do j = 1, fields(i)%length
    fields(i)%value(j) = j
  end do
end do

! show what we have

do i = 1, max_fields
  j = fields(i)%length
  print "((x,i1))", fields(i)%value(1:j)
end do

end program allcomp

James

James:

Your sample is much appreciated.
I dug up ftp://ftp.nag.co.uk/sc22wg5/N1351-N1400/N1379.pdf which might be of interest.

Ciao,
Gerry T.

Leave a Comment

Please sign in to add a comment. Not a member? Join today