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
|