2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-21 17:35:55 +01:00

Added more syntactic cases to the demos/fortran/submodules example.

Also build a main program that uses the parent module.
This commit is contained in:
Harald Klimach 2018-12-21 23:36:55 +01:00
parent 9ff9eb73ad
commit 24ea24ff24
4 changed files with 47 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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',
)