function d = upc_check_digit_calculate ( s )

%*****************************************************************************80
%
%% upc_check_digit_calculate() returns the check digit of a UPC.
%
%  Discussion:
%
%    UPC stands for Universal Product Code.
%
%    A full UPC is a string of 12 digits, in groups of size 1, 5, 5, and 1,
%    of the form P-LLLLL-RRRRR-C, where:
%
%      P is the one-digit product type code.
%      L is the five-digit manufacturer code.
%      R is the five_digit product code
%      C is the check digit.
%
%  Example:
%
%    0-72890-00011-8
%    0-12345-67890-5
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 September 2015
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    David Savir, George Laurer,
%    The Characteristics and Decodability of the Universal Product Code,
%    IBM Systems Journal,
%    Volume 14, Number 1, pages 16-34, 1975.
%
%  Input:
%
%    string S, a string containing at least 11 digits.
%    Dashes and other characters will be ignored.  A 12th digit may be
%    included, but it will be ignored.
%
%  Output:
%
%    integer D, the check digit.
%
  n = 11;
  dvec = s_to_digits ( s, n );

  d = sum ( dvec(1:2:11) ) * 3 + sum ( dvec(2:2:10) );

  d = mod ( d, 10 );

  d = mod ( 10 - d, 10 );

  return
end
