function d = bank_check_digit_calculate ( s )

%*****************************************************************************80
%
%% bank_check_digit_calculate() returns the check digit of a bank checksum.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 October 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string S, a string containing at least 8 digits.
%    Dashes and other characters will be ignored.  A 9th digit may be
%    included, but it will be ignored.
%
%  Output:
%
%    integer D, the check digit.
%
  n = 8;
  dvec = s_to_digits ( s, n );

  d = 3 * sum ( dvec(1:3:7) ) ...
    + 7 * sum ( dvec(2:3:8) ) ...
    +     sum ( dvec(3:3:6) );

  d = mod ( d, 10 );

  d = mod ( 10 - d, 10 );

  return
end
