File: arrays_op_9.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (46 lines) | stat: -rw-r--r-- 880 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
program arrays_op_9
implicit none

call f()

contains

function modify(n, array_a)  result(r)
    integer, intent(in) :: n
    real(4), intent(in) :: array_a(n)
    real(4) :: r(n)
    r = sqrt(array_a)
end function

subroutine verify(array_a, array_b, result, size)
    real(4), intent(in) :: array_a(:), array_b(:), result(:)
    integer, intent(in) :: size
    integer :: i
    real(4) :: eps
    eps = 1e-6

    do i = 1, size
        if ( abs(array_a(i) * array_a(i) + sqrt(array_b(i)) - result(i)) > eps )  error stop
    end do

end subroutine

subroutine f()
    integer :: i, j

    real(4) :: array_a(256), array_b(256), array_c(256)

    do i = 1, 256
        array_a(i) = i
    end do

    do j = 1, 256
        array_b(j) = j + 5
    end do

    array_c = array_a**2 + modify(256, array_b)
    call verify(array_a, array_b, array_c, 256)

end subroutine

end program