function pgma_write_test ( file_name )

%*****************************************************************************80
%
%% pgma_write_test() tests pgma_write().
%
%  Discussion:
%
%    This example makes a sort of grayscale checkerboard.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 May 2017
%
%  Author:
%
%    John Burkardt
%
  comment = "File created by pgma_write_test.m";
  width = 300;
  height = 300;
  maxval = 255;

  ngray = 11;
  gray = [ 0.000, 0.291, 0.434, 0.540, 0.629, ...
           0.706, 0.774, 0.837, 0.895, 0.949, ...
           1.000 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, 'pgma_write_test():\n' );
  fprintf ( 1, '  pgma_write() writes an ASCII PGM file.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  In this example, we make a sort of grayscale checkerboard.\n' );

  for i = 1 : height
    for j = 1 : width
      k = ( i - 1 + j - 1 ) * ngray / min ( width, height );
      k = floor ( 1 + mod ( k, ngray ) );
      g(i,j) = floor ( 255.0 * gray(k) );
    end
  end

  pgma_write ( file_name, comment, width, height, maxval, g );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Created the file %s.\n', file_name );

  return
end
