Fortran 90
allows the creation of new data types that are constructed from
the intrinsic data types and previously defined new data types.
These new data types are known as derived types.
For example, a derived type for manipulating coordinates consisting
of two real numbers can be defined as follows:
x and y
are components of the derived type coord.
Variables of type coord,
named a and b,
can be declared as follows:
The
assignment statement,
copies the values of all the defined components of b
to those of a.
The individual components of a
and b are referenced
as a%x, a%y,
b%x, and b%y.
By coding appropriate procedures (as described in Chapter 7),
the scope of the standard operators can be extended so that, for
example,
could be defined to be equivalent to
a%x = a%x + b%x; a%y = a%y + b%y |
or to anything else, depending on the use procedure that is
provided to implement the operation.
A derived-type entity can be used as an argument to a procedure
and can be the result of a function— that is, a function
of derived type can be defined.