File: array_section_13.f90

package info (click to toggle)
lfortran 0.61.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 61,892 kB
  • sloc: cpp: 181,767; f90: 92,175; python: 17,616; ansic: 10,170; yacc: 2,377; sh: 1,444; fortran: 892; makefile: 38; javascript: 15
file content (51 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download
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
module array_section_13_mod
implicit none
contains
    subroutine mwe(n, x, y, M)
        integer, value :: n
        real, intent(in) :: x(n), y(n)
        real, intent(out) :: M(n, n)
        integer :: k
        do k = 1, n
            call phs(x(k), y(k), M(:, k))
        end do
    contains
        subroutine phs(xc, yc, b)
            real, intent(in) :: xc, yc
            real, intent(out) :: b(n)
            real :: r
            integer :: k, l
            do k = 1, n
                r = hypot(xc - x(k), yc - y(k))
                b(k) = r**3
            end do
        end subroutine
    end subroutine
end module array_section_13_mod

program array_section_13
use array_section_13_mod
implicit none
integer, parameter :: n = 3
real :: x(3), y(3), M(n, n)
real :: eps
eps = 1e-4

x = [1.0, 3.0, 2.0]
y = [0.0, 3.0, 0.0]

call mwe(n, x, y, M)

if (abs(M(1,1)) > eps) error stop
if (abs(M(2,2)) > eps) error stop
if (abs(M(3,3)) > eps) error stop

if (abs(M(1,2) - M(2,1)) > eps) error stop
if (abs(M(1,3) - M(3,1)) > eps) error stop
if (abs(M(2,3) - M(3,2)) > eps) error stop

if (abs(M(1,2) - 46.8721657) > eps) error stop
if (abs(M(1,3) - 1.0) > eps) error stop
if (abs(M(2,3) - 31.6227760) > eps) error stop

end program array_section_13