function pc_vectors_test ( filelist, n )

%*****************************************************************************80
%
%% pc_vectors_test() tests PC_VECTORS.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 December 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string FILELIST, a list of files to be processed.
%
%    integer N, the number of principal component vectors to extract.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pc_vectors_test():\n' );
  fprintf ( 1, '  PC_VECTORS computes principal component vectors.\n' );
  fprintf ( 1, '  Pack multiple PGM files into a single array.\n' );
  fprintf ( 1, '  Do principal component analysis.\n' );
  fprintf ( 1, '  Display the PC vectors.\n' );
%
%  Create a single array of multiple PGMs.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Packing files from the list "%s"\n', filelist );

  [ pgms, w, h, pgm_num ] = pgms_pack ( filelist );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Packed array contains %d PGM files\n', pgm_num );
  fprintf ( 1, '  Each PGM has width %d and height %d\n', w, h );
%
%  Compute N principal component vectors.
%
  [ pcvec, pcval, avg ] = pc_vectors ( pgms, n );
%
%  Display the average face.
%
  fig_num = 0;

  fig_num = fig_num + 1;
  figure ( fig_num );
  clf
  I = avg;
  I = reshape ( I, w, h );
  I = I';
  imagesc ( I );
  colormap ( gray(256) );
  daspect ( [1,1,1] );
  title ( 'Average face', 'Fontsize', 16 );

  for j = 1 : n
    fig_num = fig_num + 1;
    figure ( fig_num );
    clf
    I = pcvec(:,j);
    I = reshape ( I, w, h );
    I = I';
    imagesc ( I );
    colormap ( gray(256) );
    daspect ( [1,1,1] );
    label = sprintf ( 'Eigenface #%d', j );
    title ( label, 'Fontsize', 16 );
  end
%
%  Show energy distribution.
%
  xcdf = 0:pgm_num;
  ycdf = cumsum ( pcval ) / sum ( pcval );
  ycdf = [ 0.0; ycdf ];
  fig_num = fig_num + 1;
  figure ( fig_num );
  clf
  plot ( xcdf, ycdf, '-o', 'Linewidth', 3 )
  grid ( 'on' )
  title ( 'Eigenvalue cumulative sum:' )
  axis ( [ 0.0, pgm_num, 0.0, 1.0 ] )
%
%  V'*V = I?
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Confirm that the vectors are orthonormal:\n' );
  fprintf ( 1, '  V'' * V = I?\n' );
  fprintf ( 1, '\n' );
  disp ( pcvec' * pcvec );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pc_vectors_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end

