# Fortran Wiki Submodules

Submodules are a feature of Fortran 2008 which allow a module procedure to have its interface defined in a module while having the body of the procedure defined in a separate unit, a submodule.

Submodules were originally introduced as an extension to Fortran 2003 and were later adopted as part of the Fortran 2008 standard. For further details, see the following technical report: ISO/IEC TR 19767:2005 Fortran - Enhanced Module Facilities.

## Example

Consider the following example (from ISO/IEC TR 19767):

module points
type :: point
real :: x, y
end type point

interface
module function point_dist(a, b) result(distance)
type(point), intent(in) :: a, b
real :: distance
end function point_dist
end interface
end module points

submodule (points) points_a
contains
module function point_dist(a, b) result(distance)
type(point), intent(in) :: a, b
real :: distance
distance = sqrt((a%x - b%x)**2 + (a%y - b%y)**2)
end function point_dist
end submodule points_a

The repetition in the above example can be avoided by using an alternative declaration. The following example shows that it is not necessary to restate the properties of the point_dist interface.

submodule (points) points_a
contains
module procedure point_dist
distance = sqrt((a%x - b%x)**2 + (a%y - b%y)**2)
end procedure point_dist
end submodule points_a