-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_011.F90
42 lines (39 loc) · 1.11 KB
/
example_011.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
! elemental functions in Fortran
module test_mod
implicit none
interface increment ! generic interface
module procedure increment_i
module procedure increment_r
end interface
contains
elemental integer function increment_i(x) ! elemental function
integer, intent(in) :: x
increment_i = x + 1
end function
elemental real function increment_r(x) ! elemental function
real, intent(in) :: x
increment_r = x + 1
end function
end module
subroutine vincr(fi, fr, n)
use test_mod
implicit none
integer, intent(IN) :: n
integer, dimension(n), intent(INOUT) :: fi
real, dimension(n), intent(INOUT) :: fr
fi(1:n) = increment(fi(1:n)) ! call elemental function with a vector argument
fr(1:n) = increment(fr(1:n)) ! call elemental function with a vector argument
end subroutine
program test
implicit none
integer, dimension(5) :: fi
real, dimension(5) :: fr
integer :: i
fi(1:5) = [(i, i=1,5)]
fr = fi
print *,'fi avant =',fi
print *,'fr avant =',fi
call vincr(fi, fr, 5)
print *,'fi apres =',fi
print *,'fr apres =',fi
end