function neighbor_states_test ( )

%*****************************************************************************80
%
%% neighbor_states_test() tests neighbor_states().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 October 2022
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../neighbor_states' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'neighbor_states_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s:\n', version ( ) );
  fprintf ( 1, '  neighbor_states() records connections between\n' );
  fprintf ( 1, '  US states.\n' );
  fprintf ( 1, '  Plot a web of these connections as a graph.\n' );
%
%  Retrieve connected pairs of states, 
%  represented by indices between 1 and 50.
%
  st = state_neighbors ( );
%
%  Split the pairs into S and T.
%  S is the start nodes,
%  T the terminal nodes.
%
  s = st(:,1);
  t = st(:,2); 
%
%  Every pair of state connections occurs twice.
%  To keep the graph simple, drop one of each pair.
%
  i = find ( s < t );
  s2 = s(i);
  t2 = t(i);
%
%  Create a graph from S and T.
%
  G = graph ( s2, t2 );
%
%  Set up node labels as the two-letter state abbreviations.
%
  nLabels = {};
  for i = 1 : 50
    id = state_id_from_index ( i );
    nLabels{i} = id;
  end
%
%  Plot the graph
%
  plot ( G, ...
    'Layout', 'auto', ...
    'NodeLabel', nLabels, ...
    'LineWidth', 2, ...
    'MarkerSize', 10 );

  title ( 'US State Neighbors', 'Fontsize', 16 );
%
%  Save a copy.
%
  filename = 'neighbor_states.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'neighbor_states_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( )

  rmpath ( '../neighbor_states' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

