function fnorm = r8mat_is_diag2 ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_DIAG2 counts the number of nonzero diagonals.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    real A(M,N), the matrix.
%
%  Output:
%
%    real FNORM, the number of nonzero diagonals, divided
%    by (M+N-1),
%
  ival = 0;

  for jmi = 1 - m : n - 1
    nonzero = 0;
    ilo = max ( 1, 1 - jmi );
    ihi = min ( m, n - jmi );
    for i = ilo : ihi
      if ( a(i,i+jmi) ~= 0 )
        nonzero = 1;
      end
    end
    ival = ival + nonzero;
  end

  fnorm = ival / ( m + n - 1 );

  return
end
