function cloud ( )

%*****************************************************************************80
%
%% CLOUD extracts the boundary from an image of a cloud.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 August 2015
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Alessandra Agostini, Chiara Piazzola,
%    Mesh Generation with FreeFem++ and Triangle,
%    Master's degree presentation,
%    University of Verona, 2014.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CLOUD:\n' );
  fprintf ( 1, '  Apply IMAGE_BOUNDARY to an image of a cloud.\n' );
  fprintf ( 1, '  Write pixel data to a file for use by FreeFem++.\n' );

  b = image_boundary ( 'cloud.png' );

  [ m, n ] = size ( b );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Extracted pixel list has dimensions %d x %d\n', m, n );
%
%  Too much data!  Cut it down to 1/40.
%
  b2 = b(1:40:m,1:2);
  [ m2, ~ ] = size ( b2 );
  fprintf ( 1, '  Data cut down to %d x %d\n', m2, n );
%
%  Reverse the points so they are listed in counterclockwise order.
%
  b2(1:m2,1:2) = b2(m2:-1:1,1:2);
%
%  Also, make sure first point is repeated at end.
%
  b2(m2,1:2) = b2(1,1:2);
%
%  Write data to a file for input to FreeFem++
%
  filename = 'cloud_points.txt';

  output_unit = fopen ( output_filename, 'wt' );

  fprintf ( output_unit, '%d\n', m2 );

  for i = 1 : m2
    fprintf ( output_unit, '  %d  %d\n', b2(i,1), b2(i,2) );
  end

  fclose ( output_unit );

  fprintf ( 1, '  Saved data for FreeFem++ in "%s"\n', filename );

  return
end

