function a = r8vec_normalize_l1 ( n, a )

%*****************************************************************************80
%
%% r8vec_normalize_l1() normalizes an R8VEC to have unit sum.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 July 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of entries in the vector.
%
%    real A(N), the vector to be normalized.
%
%  Output:
%
%    real A(N), the entries of A should have unit sum.  However, 
%    if the input vector has zero sum, the routine halts.
%
  a_sum = sum ( abs ( a(1:n) ) );

  if ( a_sum == 0.0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8VEC_NORMALIZE_L1 - Fatal error!\n' );
    fprintf ( 1, '  The vector entries sum to 0.\n' );
    error ( 'R8VEC_NORMALIZE_L1 - Fatal error!' );
  end

  a(1:n) = a(1:n) / a_sum;

  return
end

