From 24ea24ff24288ade3af6b2350189233895365ef0 Mon Sep 17 00:00:00 2001 From: Harald Klimach Date: Fri, 21 Dec 2018 23:36:55 +0100 Subject: [PATCH] Added more syntactic cases to the demos/fortran/submodules example. Also build a main program that uses the parent module. --- demos/fortran/submodules/container.f90 | 14 ++++++++++++++ demos/fortran/submodules/parent.f90 | 9 +++++++++ demos/fortran/submodules/submain.f90 | 18 ++++++++++++++++++ demos/fortran/submodules/wscript | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 demos/fortran/submodules/submain.f90 diff --git a/demos/fortran/submodules/container.f90 b/demos/fortran/submodules/container.f90 index 1d9387c0..d8a6c471 100644 --- a/demos/fortran/submodules/container.f90 +++ b/demos/fortran/submodules/container.f90 @@ -3,6 +3,20 @@ submodule (parent) container contains + module procedure init + p%mother = mother + p%father = father + end procedure init + + module subroutine harmonize(p) + type(parent_type), intent(inout) :: p + real :: avg + + avg = 0.5 * (p%father + p%mother) + p%father = avg + p%mother = avg + end subroutine harmonize + module function parent_weight(p) result(w) type(parent_type), intent(in) :: p real :: w diff --git a/demos/fortran/submodules/parent.f90 b/demos/fortran/submodules/parent.f90 index e40fbca9..17b8370b 100644 --- a/demos/fortran/submodules/parent.f90 +++ b/demos/fortran/submodules/parent.f90 @@ -7,6 +7,15 @@ module parent end type parent_type interface + module subroutine init(p, mother, father) + type(parent_type), intent(out) :: p + real, intent(in) :: mother, father + end subroutine init + + module subroutine harmonize(p) + type(parent_type), intent(inout) :: p + end subroutine harmonize + module function parent_weight(p) result(w) type(parent_type), intent(in) :: p real :: w diff --git a/demos/fortran/submodules/submain.f90 b/demos/fortran/submodules/submain.f90 new file mode 100644 index 00000000..e47013a5 --- /dev/null +++ b/demos/fortran/submodules/submain.f90 @@ -0,0 +1,18 @@ +program submain + use parent + + implicit none + + type(parent_type) :: a,b + real :: dist, weight + + call init(a, 1.0, 2.0) + call init(b, 10.0, 12.0) + + call harmonize(a) + weight = parent_weight(b) + write(*,*) weight + dist = parent_distance(a, b) + write(*,*) dist + +end program submain diff --git a/demos/fortran/submodules/wscript b/demos/fortran/submodules/wscript index 73f8be13..771614e1 100644 --- a/demos/fortran/submodules/wscript +++ b/demos/fortran/submodules/wscript @@ -18,3 +18,9 @@ def build(bld): source = 'parent.f90 container.f90 helper.f90', target = 'fudge', ) + bld( + features = 'fc fcprogram', + source = 'submain.f90', + use = 'fudge', + target = 'submain', + )