function c = isbn13_check_digit ( s )

%*****************************************************************************80
%
%% isbn13_check_digit_calculate() determines the check digit for an ISBN13.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    30 May 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string S, a string.  Dashes and spaces and other
%    nonnumeric data is ignored, but at least 13 digits are expected, and only
%    the first 12 digits will be examined.
%
%  Output:
%
%    character ISBN_CHECK_DIGIT, the ISBN13 
%    check digit that should be appended to form the full 13 digit ISBN.
%

%
%  Extract the first 12 numeric digits from character string.
%
  n = 12;
  dvec = s_to_digits ( s, n );
%
%  Compute the check digit.
%  Coefficient S alternates between 1 and 3.
%
  d = 10;
  s = 1;
  for i = 1 : n
    d = d - s * dvec(i);
    s = 4 - s;
  end

  d = mod ( d, 10 );
%
%  Convert digits 0 through 9 to characters '0' through '9'.
%  C represents the 13-th digit in the ISBN13 string.
%
  c = char ( d + '0' );

  return
end
