| 1 |
Fortran 2008 adds a new feature, submodules. |
| 2 |
|
| 3 |
These have the syntax: |
| 4 |
|
| 5 |
``` |
| 6 |
module points |
| 7 |
type :: point |
| 8 |
real :: x, y |
| 9 |
end type point |
| 10 |
|
| 11 |
interface |
| 12 |
module function point_dist(a, b) result(distance) |
| 13 |
type(point), intent(in) :: a, b |
| 14 |
real :: distance |
| 15 |
end function point_dist |
| 16 |
end interface |
| 17 |
end module points |
| 18 |
|
| 19 |
submodule (points) points_a |
| 20 |
contains |
| 21 |
module function point_dist(a, b) result(distance) |
| 22 |
type(point), intent(in) :: a, b |
| 23 |
real :: distance |
| 24 |
distance = sqrt((a%x - b%x)**2 + (a%y - b%y)**2) |
| 25 |
end function point_dist |
| 26 |
end submodule points_a |
| 27 |
``` |
| 28 |
|
| 29 |
where the submodule inherits from the module `points`. |
| 30 |
|
| 31 |
When compiled with gfortran this results in files: |
| 32 |
``` |
| 33 |
points.smod |
| 34 |
points@points_a.smod |
| 35 |
``` |
| 36 |
|
| 37 |
while when compiled with Flang / F18 or PGI Fortran, this results in: |
| 38 |
`` |
| 39 |
points.mod |
| 40 |
points-points_a.mod |
| 41 |
``` |
| 42 |
|
| 43 |
So, makedepf90 presented with a submodule creates a dependency on the file parent.mod, where 'parent' is the name of |
| 44 |
the parent module, as it cannot determine (with only one file) the source filename containing the module. |