forked from zziolko/fortran-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overload-subroutine.f90
61 lines (47 loc) · 1.22 KB
/
overload-subroutine.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
program overload_subroutine
implicit none
interface print_matrix
subroutine print_matrix_real(A,n)
integer, intent(in) :: n
real, dimension(n,n), intent(in) :: A
end subroutine print_matrix_real
subroutine print_matrix_integer(A,n)
integer, intent(in) :: n
integer, dimension(n,n), intent(in) :: A
end subroutine print_matrix_integer
end interface print_matrix
integer :: n = 4
real, allocatable, dimension(:,:) :: A
integer, allocatable, dimension(:,:) :: B
integer :: i
allocate( A(n,n), B(n,n) )
A = 0.0
B = 0
forall( i=1:n )
A(i,i) = 1.0
B(i,i) = 1
end forall
print *,'real matrix'
call print_matrix(A,n)
print *,'integer matrix'
call print_matrix(B,n)
deallocate( A, B )
end program overload_subroutine
subroutine print_matrix_real(A,n)
implicit none
integer, intent(in) :: n
real, dimension(n,n), intent(in) :: A
integer :: i,j
do i=1, n
print *,( A(i,j), j=1,n )
end do
end subroutine print_matrix_real
subroutine print_matrix_integer(A,n)
implicit none
integer, intent(in) :: n
integer, dimension(n,n), intent(in) :: A
integer :: i,j
do i=1, n
print *,( A(i,j), j=1,n )
end do
end subroutine print_matrix_integer