function histogram_data_2d_sample_test01 ( n )

%*****************************************************************************80
%
%% HISTOGRAM_DATA_2D_SAMPLE_TEST01 looks at a 20x20 region.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    15 December 2012
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of sample points to be generated.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'HISTOGRAM_DATA_2D_SAMPLE_TEST01\n' );
  fprintf ( 1, '  Consider data skewed toward the upper left corner of the unit square.\n' );
  fprintf ( 1, '  Generate %d samples\n', n );
%
%  Get the dimensions of the PDF data.
%
  [ n1, n2 ] = get_discrete_pdf_size1 ( );
  fprintf ( 1, '  PDF data is on a %d by %d grid.', n1, n2 );
%
%  Construct a PDF from the data.
%
  pdf = get_discrete_pdf_data1 ( 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.
%
  seed = 123456789;
  [ u, seed ] = r8vec_uniform_01 ( n, seed );
%
%  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, seed, u );
%
%  Write data to a file for examination, plotting, or analysis.
%
  filename = 'histogram_data_2d_sample_test01.txt';
  r8mat_write ( filename, 2, n, xy );

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

  return
end
