Clicky

Fortran Wiki
Submodules (Rev #4)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

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

References

Revision from September 20, 2010 11:51:27 by Jason Blevins
Forward in time (to current) | Back in time (3 more) | See current | See changes | History | Rollback | View: Source | Linked from: Fortran 2008, Library distribution, 2009, Keywords, Compiler .MOD files, Guide to Fortran 2008 Programming

AltStyle によって変換されたページ (->オリジナル) /