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

allocatable Components of derived types

ipeta
Beginner
675 Views

i wrote the following code to check if i can use allocatable components in derived types.

When i run the program end try to change the initial values of A(Type(Region_2D))they remain unchanged.

What is wrong???

P.S. When i use allocatable arrays of type Real, as a Derived type Component There 's nothing wrong.

module

Analytic_Geometry_Types

!---Data-Types-----------------------------------------------!****************************************************

!*****************************************************

!----------------------

!*Point 2D*

!----------------------

Type :: Point_2D

real :: x

real :: y

End Type

!-----------------------

!*Vector2D*

!------------------------

Type :: Vector_2D

Type(Point_2D) :: i

Type(Point_2D) :: j

End Type

!*****************************************************

!*Region2D*

!---------------------------------

Type :: Region_2D

integer :: Sec_Number

Type(Vector_2D),allocatable,Dimension(:) :: Sections

end Type

!*****************************************************

end moduleAnalytic_Geometry_Types

program main< /FONT>

use Analytic_Geometry_Types

Type(Region_2D) :: A

allocate (A%Sections(3))

A%Sec_Number = 3

do I=1,A%Sec_Number

A%Sections(I)%i%x=1.0

A%Sections(I)%j%x=1.0

A%Sections(I)%i%y=1.0

A%Sections(I)%j%y=1.0

enddo

stop

end

Message Edited by ipeta on 06-15-2004 10:39 AM

0 Kudos
3 Replies
Steven_L_Intel1
Employee
675 Views
You're using an undeclared and uninitialized variable Sec_Number in the DO loop.
0 Kudos
ipeta
Beginner
675 Views

in the original message i wrote by mistake

do I=1,Sec_Number

in my code the statement for the do loop is:

do I=1,A%Sec_Number

but even if i write

do i=1,3

i cannot change the initial values of A

0 Kudos
Steven_L_Intel1
Employee
675 Views
It works for me in a recent version of the compiler.
0 Kudos
Reply