Saturday, 22 October 2011

Enlightenment from Wikipedia - eventually!

Derived data types

For derived data types, the form of the type must be defined first:
TYPE person
   CHARACTER(10) name
   REAL          age
END TYPE person
and then, variables of that type can be defined:
TYPE(person) you, me
To select components of a derived type, % qualifier is used:
Literal constants of derived types have the form TypeName(1stComponentLiteral, 2ndComponentLiteral, ...):
you = person('Smith', 23.5)
which is known as a structure constructor. Definitions may refer to a previously defined type:
TYPE point
   REAL x, y
END TYPE point
TYPE triangle
   TYPE(point) a, b, c
END TYPE triangle
and for a variable of type triangle, as in
TYPE(triangle) t
each component of type point is accessed as:
t%a   t%b   t%c
which, in turn, have ultimate components of type real:
t%a%x   t%a%y   t%b%x   etc.
(Note that the % qualifier was chosen rather than dot (.) because of potential ambiguity with operator notation, like .OR.).

No comments:

Post a Comment