function histogram_data_2d_sample_test02 ( n )

%*****************************************************************************80
%
%% histogram_data_2d_sample_test02() looks at a 12x8 region.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 December 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of sample points to be generated.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'histogram_data_2d_sample_test02():\n' );
  fprintf ( 1, '  Consider data suggested by the shape and density of Iowa.\n' );
  fprintf ( 1, '  Generate %d samples\n', n );
%
%  Get the dimensions of the PDF data.
%
  [ n1, n2 ] = get_discrete_pdf_size2 ( );
  fprintf ( 1, '  PDF data is on a %d by %d grid.', n1, n2 );
%
%  Construct a PDF from the data.
%
  pdf = get_discrete_pdf_data2 ( n1, n2 );
%
%  "Integrate" the data over rows and columns of the region to get the CDF.
%
  cdf = set_discrete_cdf ( n1, n2, pdf );
%
%  Choose N CDF values at random.
%
  u = rand ( n, 1 );
%
%  Find the cell corresponding to each CDF value,
%  and choose a random point in that cell.
%
  xy = discrete_cdf_to_xy ( n1, n2, cdf, n, u );
%
%  Write data to a file for examination, plotting, or analysis.
%
  filename = 'histogram_data_2d_sample_test02.txt';
  r8mat_write ( filename, 2, n, xy );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Wrote sample data to file "%s".\n', filename );

  return
end
