Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29487 Discussions

Allocatable arrays as components of derived types

longthong
Beginner
1,606 Views

I use CVF 6.6.A Professional.

I have seen in some documentation that one cannot use allocatable arrays in the definition of derived types. And yet the code below seems to work. The only problem with it is the last print output which gives some funny extra output. Do you think it wold be safe to proceed assuming this works?

*******************************************************
! PROGRAM: TestBed
! PURPOSE: Test ALLOCATABLE component of derived type
!*******************************************************

program TestBed
implicit none

integer(4) i,j

TYPE tagStar
integer(4) Mass
integer(4) Other
END TYPE

TYPE tagCluster
integer(4) numStars
type (tagStar), ALLOCATABLE :: Stars(:)
END TYPE tagCluster

TYPE (tagCluster), ALLOCATABLE :: Clusters(:)

ALLOCATE (Clusters(3))

print *, ALLOCATED (Clusters(1)%Stars) ! prints false

do i=1,3
ALLOCATE (Clusters(i)%Stars(i+2))
end do

print *, ALLOCATED (Clusters(1)%Stars) ! prints true

do i = 1,3
Clusters(i)%Stars(i+2)%Mass = i+90
end do

do i = 1,3
print *, Clusters(i)%Stars(i+2) ! prints 91,92,93 and
! some other funny stuff?
end do

End Program TestBed

LongThong

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,606 Views
That feature is not reliable in CVF 6.6A. I would suggest 6.6C if you must stay with CVF, and even then there are lots of bugs fixed later in Intel Visual Fortran.
0 Kudos
longthong
Beginner
1,606 Views

Unfortunately, I am stuck with 6.6A. Is there any way, now that Compaq is out of the picture, to upgrade to C?

LongThong

0 Kudos
Steven_L_Intel1
Employee
1,606 Views
See if this link works for you. You will need to do a free registration at HP.

It would be much better if you purchased Intel Visual Fortran 10 instead - many bugs relating to this feature have been fixed since CVF.
0 Kudos
longthong
Beginner
1,606 Views

Thanks Steve,

The link works. I will download it when I have time. (Dial-up!)

Thanx much for all the help.

LongThong

0 Kudos
Reply