function capacitor_3d_test ( )

%*****************************************************************************80
%
%% capacitor_3d_test plots data computed by FreeFem++.
%
%  Discussion:
%
%    The data arises from the simulation of a 3D parallel plate capacitor.
%
%  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_3d_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Make plots of data for a 3D 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_3d.mesh' );
  [ vh ] = ffreaddata ( 'capacitor_3d_vh.txt' );
  [ u ] = ffreaddata ( 'capacitor_3d_pot.txt' );
  [ Ex, Ey, Ez ] = ffreaddata ( 'capacitor_3d_vec.txt' );
%
  figure ( );

  CK = 30;
  CA = 31;
 
  S1 = [-0 0.375 0.0; ...
    0.375 0 0.0];
  S2 = [0.0 0.375 0.5; ...
    0.375 0 0.5];
  S3 = [0.75 0.375 0.0; ...
    0.375 0.75 0.0];

  ffpdeplot3D ( p, b, t, ...
    'VhSeq',vh, ...
    'XYZData',u, ...
    'Slice',S1,S2,S3, ...
    'SGridParam',[50,50], ...
    'Boundary','on', ...
    'BDLabels',[CK,CA], ...
    'XYZStyle','monochrome', ...
    'ColorMap',jet(200), ...
    'ColorBar','on', ...
    'BoundingBox','on' );

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

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

  S1=[-0 0.0 0.0];
  S2=[0.0 0.375 0.5];
  S3=[0.75 0.375 0.0];

  ffpdeplot3D ( p, b, t, ...
    'VhSeq',vh, ...
    'XYZData',u, ...
    'Slice',S1,S2,S3, ...
    'SGridParam',[50,50], ...
    'Project2D', 'on', ...
    'Boundary','off', ...
    'ColorMap',jet(200), ...
    'ColorBar','on' );

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

  ffpdeplot3D ( p, b, t, ...
    'VhSeq',vh, ...
    'FlowData',[Ex,Ey,Ez], ...
    'FGridParam3D',[8,8,5], ...
    'FLim3D',[0.125,0.625;0.125,0.625;0.1,0.4], ...
    'BDLabels',[CK,CA], ...
    'XYZStyle','monochrome' );

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

  ffpdeplot3D ( p, b, t, ...
    'XYZStyle', 'monochrome' );

  str = {sprintf('nVertex: %i',nv);
         sprintf('nTets:   %i',nt);
         sprintf('nTris:   %i',nbe)};

  annotation ( ...
    'textbox',[0.05 0.05 0.2 0.15], ...
    'String',str, ...
    'FitBoxToText','on', ...
    'FontName','Courier', ...
    'EdgeColor',[1 1 1] );

  filename = 'capacitor_3d_mesh.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'capacitor_3d_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

