By the new standard, the programmer can use not only the original data types (REAL, INTEGER, etc.) but also, can define and use aggregates of them. These structures can in turn serve as the building blocks of more complex entities. Such a derived type is defined through the keyword, TYPE. For example:
TYPE vector REAL :: x, y, z END TYPE vectordefines a structure holding three real numbers (which can be the coordinates of a vector in 3D space).
The user can declare the type of a variable to be a derived type (for example TYPE (vector) :: a, b, c), address its components via % (for example a%x = 1.0) and pass them as arguments to a subroutine, effectively packing related information in one variable.
The programmer can also define operations involving them. For example, the cross product of two vectors can be computed via the * operator, as in c = a * b, provided that a suitable definition for the intended action of this operator is made known to the compiler. This is done by first defining a function in the same module as TYPE (vector) being something like:
FUNCTION cross(a, b) TYPE (vector), INTENT (in) :: a, b TYPE (vector) :: cross cross%x = a%y * b%z - a%z * b%y cross%y = a%z * b%x - a%x * b%z cross%z = a%x * b%y - a%y * b%x END FUNCTION crossAn interface should exist to overload the operator *
INTERFACE OPERATOR (*) MODULE PROCEDURE cross END INTERFACEIn addition to operator overloading, FORTRAN 90 supports function overloading; one could use the notation ABS(a), to compute the absolute value (norm) of a vector a. This requires a function
FUNCTION absvec(a) TYPE (vector), INTENT (in) :: a REAL :: absvec absvec = sqrt(a%x**2 + a%y**2 + a%z**2) END FUNCTION absvecand an interface declaration to overload the generic name ABS with a new function
INTERFACE ABS MODULE PROCEDURE absvec END INTERFACE
Given these declarations, the same function (ABS) applied to a REAL returns the absolute value, and applied to a vector returns its norm.
The programmer can define functions accepting vectors and returning a vector; for example, rotation can be performed through such a function.
The access attribute (PRIVATE or PUBLIC) can be specified for an entity in a module. The former indicates that the entity can be used only inside the module, while the latter attribute ``exports'' it to any program unit which uses the module.