function mad_stats ( t, label )

%*****************************************************************************80
%
%% mad_stats() reports time and timestep statistics for mad_compute().
%
%  Discussion:
%
%    This function prints some information about the time nodes and time steps,
%    and creates plots that show the variation in timesteps, and in the ratio
%    of successive timesteps, over the integration interval.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 February 2022
%
%  Author:
%
%    John Burkardt, Catalin Trenchea
%
%  Input:
%
%    real t(n+1): the sequence of time values.
%
%    string label: a label to prefix the plotfile names.  Default is 'mad'.
%    The files will be 'label_timesteps.png' and 'label_timestep_ratios.png'.
%
  if ( nargin < 2 )
    label = 'mad';
  end

  tau = t(2:end) - t(1:end-1);
  r = tau(2:end) ./ tau(1:end-1);

  fprintf ( 1, '\n' );
  fprintf ( 1, 'mad_stats():\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Final time interval is [%g,%g]\n', t(end-1), t(end) );
  fprintf ( 1, '  Number of times t() %d\n', length ( t ) );
  fprintf ( 1, '  Number of timesteps tau() %d\n', length ( tau ) );
  fprintf ( 1, '  Minimum timestep is %g\n', min ( tau ) );
  fprintf ( 1, '  Maximum timestep is %g\n', max ( tau ) );

  figure ( );
  plot ( t(1:end-1), tau, '.-' );
  grid ( 'on' );
  title ( 'timesteps' );
  xlabel ( '<-- t(i) -->' );
  ylabel ( '<-- dt(i) -->' );
  filename = sprintf ( '%s_timesteps.png', label );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  figure ( );
  plot ( t(1:end-2), r, '.-' );
  grid ( 'on' );
  title ( 'timestep ratios' );
  xlabel ( '<-- t(i) -->' );
  ylabel ( '<-- dt(i+1)/dt(i) -->' );
  filename = sprintf ( '%s_timestep_ratios.png', label );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

