File: arrays_intrin_08.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 (36 lines) | stat: -rw-r--r-- 588 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
program arrays_intrin_08

real :: zmat(4, 4), hdiag(4)
integer :: i, j

do i = 1, 4
    do j = 1, 4
        zmat(i, j) = i + j
    end do
end do

hdiag = calden(zmat)

print *, hdiag
if( any(hdiag /= [28.0, 36.0, 44.0, 52.0]) ) error stop


contains

function calden(zmat) result(hdiag)
implicit none

real(4), intent(in) :: zmat(:, :)  ! ZMAT(NPT, NPT - N - 1)

! Outputs
real(4) :: hdiag(size(zmat, 1))

! Local variables
integer(4) :: idz_loc
idz_loc = 3

hdiag = -sum(zmat(:, 1:idz_loc - 1)**2, dim=2) + sum(zmat(:, idz_loc:size(zmat, 2))**2, dim=2)

end function calden

end program