forked from zziolko/fortran-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subroutine-example.f90
54 lines (34 loc) · 890 Bytes
/
subroutine-example.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
program subroutine_example
implicit none
real, allocatable, dimension(:,:) :: A
integer :: n
n = 3
call PrintInfo()
allocate( A(n,n) )
call UnitMatrix(A,n)
call PrintMatrix(A,n)
deallocate(A)
end program subroutine_example
! Print info
subroutine PrintInfo
print *,' Example subroutine which only offloads some part of code '
end subroutine PrintInfo
! Sets matrix A to a unit matrix
subroutine UnitMatrix(matrix,n)
implicit none
integer, intent(in) :: n
real, dimension(n,n), intent(out) :: matrix
integer :: i
matrix = 0.0
forall( i=1:n ) matrix(i,i) = 1.0
end subroutine UnitMatrix
! Print matrix in human readable format
subroutine PrintMatrix(matrix,n)
implicit none
integer :: n
real, dimension(n,n), intent(in) :: matrix
integer :: i, j
do i=1,n
print *,( matrix(i,j), j=1,n )
end do
end subroutine PrintMatrix