function capacitor_2d_test ( )

%*****************************************************************************80
%
%% capacitor_2d_test plots data computed by FreeFem++.
%
%  Licensing:
%
%    Copyright (C) 2018 Chloros2 <chloros2@gmx.de>
%
%    This program is free software: you can redistribute it and/or modify it
%    under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful, but
%    WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see
%    <https://www.gnu.org/licenses/>.
%
%  Modified:
%
%    2018-05-13
%
%  Author:
%
%    Chloros2 <chloros2@gmx.de>
%    Modifications by John Burkardt.
%
  addpath ( '../ffmatlib' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'capacitor_2d_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Make plots of data for a 2D capacitor model\n' );
  fprintf ( 1, '  as computed by FreeFem++, using the ffmatlib() interface.\n' );

  clear ( 'all' );
%
%  Read the FreeFem++ data.
%
  [ p, b, t, nv, nbe, nt, labels ] = ffreadmesh ( 'capacitor_2d.msh' );
  [ vh ] = ffreaddata ( 'capacitor_2d_vh.txt' );
  [ u, Ex, Ey ] = ffreaddata ( 'capacitor_2d_data.txt' );
%
%  2D Patch (density map) Plot
%
  ffpdeplot ( p, b, t, ...
    'VhSeq',vh, ...
    'XYData',u, ...
    'Mesh','on', ...
    'Boundary','on', ...
    'XLim',[-2 2],'YLim',[-2 2], ...
    'CBTitle','U[V]', ...
    'Title','2D Patch Plot (Electrostatic Potential)' );

  ylabel ( 'y' );
  xlabel ( 'x' );

  filename = 'capacitor_2d_density.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Mesh Plot
%
  figure ( );

  ffpdeplot ( p, b, t, ...
    'Mesh','on', ...
    'Boundary','on', ...
    'Title','Boundary/Edge (Capacitor Electrodes) and 2D Mesh' );

  ylabel ( 'y' );
  xlabel ( 'x' );

  filename = 'capacitor_2d_mesh.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
% 3D Surf Plot
%
  figure ( );

  ffpdeplot ( p, b, t, ...
    'VhSeq',vh, ...
    'XYData',u, ...
    'ZStyle','continuous', ...
    'Mesh','on', ...
    'CBTitle','U[V]', ...
    'Title','3D Patch Plot (Electrostatic Potential)' );

  ylabel ( 'y' );
  xlabel ( 'x' );
  zlabel ( 'u' );
  grid ( 'on' );
  axis ( 'tight' );

  filename = 'capacitor_2d_potential.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Combine Quiver and Contour
%
  figure ( );

  ffpdeplot ( p, b, t, ...
    'VhSeq',vh, ...
    'XYData',u, ...
    'Mesh','off', ...
    'Boundary','on', ...
    'XLim',[-2 2],'YLim',[-2 2], ...
    'Contour','on', ...
    'CColor','b', ...
    'XYStyle','off', ...
    'CGridParam',[150, 150], ...
    'ColorBar','off', ...
    'FlowData',[Ex,Ey], ...
    'FGridParam',[24, 24], ...
    'Title','Quiver+Contour Interpolation Plot' );

  ylabel ( 'y' );
  xlabel ( 'x' );

  filename = 'capacitor_2d_contour_quiver.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Show Labels
%
  figure ( );

  ffpdeplot ( p, b, t, ...
    'Mesh','off', ...
    'Boundary','on', ...
    'BDLabels',labels, ...
    'BDShowText','on', ...
    'Title','Boundary Labels' );

  filename = 'capacitor_2d_labels.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  3D Surf Plot with Gouraud lighting
%
  figure ( );

  ffpdeplot ( p, b, t, ...
    'VhSeq',vh, ...
    'XYData',u, ...
    'ZStyle','continuous', ...
    'Mesh','off', ...
    'CBTitle','U[V]', ...
    'Title','Using Gouraud lighting' );

  ylabel ( 'y' );
  xlabel ( 'x' );
  zlabel ( 'u' );
  grid ( 'on' );
  lighting ( 'gouraud' );
  view([-47,24]);
  camlight ( 'headlight' );
  axis ( 'tight' );

  filename = 'capacitor_2d_gouraud.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'capacitor_2d_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../ffmatlib' );

  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

