forked from zziolko/fortran-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subroutine-argument.f90
68 lines (44 loc) · 1.19 KB
/
subroutine-argument.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
program subroutine_argument
implicit none
integer :: n
real, allocatable, dimension(:,:) :: matrix
external :: zero_matrix, unit_matrix
n = 3
allocate( matrix(n,n) )
print *, 'Zero matrix'
call initialize_matrix(matrix,n,zero_matrix)
print *, 'Unit matrix'
call initialize_matrix(matrix,n,unit_matrix)
deallocate( matrix )
end program subroutine_argument
subroutine initialize_matrix(A,n,matrix_init)
implicit none
integer, intent(in) :: n
real, dimension(n,n), intent(inout) :: A
integer :: i,j
interface
subroutine matrix_init(matrix,ndim)
implicit none
integer, intent(in) :: ndim
real, dimension(ndim,ndim), intent(inout) :: matrix
end subroutine matrix_init
end interface
call matrix_init(A,n)
do i=1, n
print *,( A(i,j), j=1,n )
end do
end subroutine initialize_matrix
subroutine zero_matrix(A,n)
implicit none
integer, intent(in) :: n
real, dimension(n,n), intent(inout) :: A
A = 0.0
end subroutine zero_matrix
subroutine unit_matrix(A,n)
implicit none
integer, intent(in) :: n
real, dimension(n,n), intent(inout) :: A
integer :: i
A = 0.0
forall( i=1:n ) A(i,i) = 1.0
end subroutine unit_matrix