pure function dtrace(A) result(t) real(8), intent(in) :: A(:,:) real(8) :: t integer :: i t = 0d0 do i = 1,minval(shape(A)) t = t + A(i,i) end do end function dtrace