F90 Model : Create User-derived Types

Fortran 90 adds the concept of user-derived types. That is, the user may define some entity in terms of intrinsic types or other user-derived types, along with the operations that can be performed on them. The new derived type can be used as if it were an intrinsic type and part of the language.

The lay-out in memory for a derived type is contiguous, but the amount of memory used may not be as expected since the compiler is free to pad memory as needed to honor word boundaries.

The following example shows a typical Cartesian vector type, and defines what the `+' operation will do between two such types. The advantages are that such code can be isolated and rigorously tested, leading to more robust and less buggy code overall. The derived-type modules then can be re-used in other coding projects.

IMHO: derived-types add 'fun' to the language as it gives you the ability to create useful and meaningful components.

Code examples

Slide 11