function wave_euler ( )

%*****************************************************************************80
%
%% wave_euler() uses euler() to solve the wave PDE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 December 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'wave_euler():\n' );
  fprintf ( 1, '  Use euler() to solve the wave PDE.\n' );
%
%  Get the parameters.
%
  [ xmin, xmax, nx, dx, c, t0, tstop ] = wave_parameters ( );
  x = linspace ( xmin, xmax, nx );
%
%  Under periodic boundary conditions, our integration process is simple.
%
  f = @ wave_deriv;
  tspan = [ t0, tstop ];
  w0 = wave_init ( );
  nt = 100;

  [ t, w ] = euler ( f, tspan, w0, nt );
%
%  Plot the initial condition.
%
  nt1 = 1;
  u = w(nt1,1:nx);
  v = w(nt1,  nx+1:2*nx);

  t1 = t0;
  we = wave_exact ( t1 );
  ue = we(1,1:nx);
  ve = we(nx+1:2*nx);
  figure ( 1 );
  clf ( );
  hold ( 'on' );
    plot ( x, u, 'ro', ...
           x, v, 'bo', 'linewidth', 2 );
    plot ( x, ue, 'r-', ...
           x, ve, 'b-', 'linewidth', 2 );
    plot ( [xmin,xmax], [ 0.0, 0.0 ], 'k--', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- U(T0,X),V(T0,X) -->' );
  label = sprintf ( 'wave euler: T = %g', t1 );
  title ( label );
  legend ( 'Computed U', 'Computed V', 'Exact U', 'Exact V', ...
    'Location', 'South' );
  filename = 'wave_euler_initial.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( 1 );
%
%  Plot at mid time.
%
  ntm = floor ( ( nt + 1 ) / 3.5 );
  u = w(ntm,1:nx);
  v = w(ntm,  nx+1:2*nx);

  tm = ( ( nt + 1 - ntm ) * t0 + ( ntm - 1 ) * tstop ) / nt;
  we = wave_exact ( tm );
  ue = we(1:nx);
  ve = we(nx+1:2*nx);
  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( x, u, 'ro', ...
           x, v, 'bo', 'linewidth', 2 );
    plot ( x, ue, 'r-', ...
           x, ve, 'b-', 'linewidth', 2 );
    plot ( [xmin,xmax], [ 0.0, 0.0 ], 'k--', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- U(TM,X),V(TM,X) -->' );
  label = sprintf ( 'wave euler: T = %g', tm );
  title ( label );
  legend ( 'Computed U', 'Computed V', 'Exact U', 'Exact V', ...
    'Location', 'South' );
  filename = 'wave_euler_midtime.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( 2 );
%
%  Plot at final time.
%
  u = w(nt+1,1:nx);
  v = w(nt+1,  nx+1:2*nx);

  we = wave_exact ( tstop );
  ue = we(1:nx);
  ve = we(nx+1:2*nx);
  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( x, u, 'ro', ...
           x, v, 'bo', 'linewidth', 2 );
    plot ( x, ue, 'r-', ...
           x, ve, 'b-', 'linewidth', 2 );
    plot ( [xmin,xmax], [ 0.0, 0.0 ], 'k--', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- U(TM,X),V(TM,X) -->' );
  label = sprintf ( 'wave euler: T = %g', tstop );
  title ( label );
  legend ( 'Computed U', 'Computed V', 'Exact U', 'Exact V', ...
    'Location', 'South' );
  filename = 'wave_euler_final.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( 3 );
%
%  Plot the energy.
%
  h = wave_conserved ( w );

  we = wave_exact ( t0 );
  he = wave_conserved ( we );

  figure ( 4 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'ro', 'linewidth', 2 );
    plot ( [t0,tstop], [ he, he ], 'b--', 'linewidth', 2 );
    plot ( [t0,tstop], [ 0.0, 0.0 ], 'k--', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title ( 'wave euler: energy' );
  legend ( 'Computed energy', 'Exact energy', 'Zero energy', ...
    'Location', 'South' );
  filename = 'wave_euler_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( 4 );

  return
end

