Submodules in Fortran Wiki
**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](ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1602.pdf). ## Example Consider the following example (from ISO/IEC TR 19767): ~~~~~ {: lang=fortran } 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. ~~~~~ {: lang=fortran } 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 ~~~~~ ## External Links * [Progress on Fortran 2003 and the Technical Report on Enhanced Module Facilities](http://www.fortran.bcs.org/2004/ukfortran04.htm) ## References * [ISO/IEC TR 19767:2005 Fortran - Enhanced Module Facilities](ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1602.pdf).
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル