function paraheat_gaussian_sample ( )

%*****************************************************************************80
%
%% paraheat_gaussian_sample samples paraheat_gaussian.
%
%  Discussion:
%
%    This program uses a random number seed to choose parameters 
%    xc, yc, sc, vc as input to the paraheat_gaussian() program, and 
%    saves the resulting sensor measurements ns, xs, ys, vs.
%
%    By repeatedly changing this seed, a set of samples of the data
%    are constructed.  
%
%    The sets of data ( seed, xc, yc, sc, vc, vs ) are written to a file.
%
%    The user is free to vary all 4 parameters, or any subset of them.
%
%    Note that, if you are generating many samples, you probably want
%    to modify paraheat_gaussian() so that it doesn't produce plots
%    for every solution that is computed.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 May 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../paraheat_gaussian' );

  timestamp ( );
  fprintf ( 1, 'paraheat_gaussian_sample\n' );
  fprintf ( 1, '  Sample solutions computed by paraheat_gaussian()\n' );
  fprintf ( 1, '  which accepts diffusivity parameters as input,\n' );
  fprintf ( 1, '  solves a certain steady heat equation problem\n' );
  fprintf ( 1, '  and returns the solution value at selected locations.\n' );
  fprintf ( 1, '\n' );
%
%  Choose which parameters will vary and print the list.
%
  vary_xc = true;
  vary_yc = true;
  vary_sc = true;
  vary_vc = true;

  fprintf ( 1, '  Of (xc,yc,sc,vc), we will vary ' )
  next = '(';
  if ( vary_xc )
    fprintf ( 1, '%c', next )
    fprintf ( 1, 'xc' )
    next = ',';
  end
  if ( vary_yc )
    fprintf ( 1, '%c', next )
    fprintf ( 1, 'yc' )
    next = ',';
  end
  if ( vary_sc )
    fprintf ( 1, '%c', next )
    fprintf ( 1, 'sc' )
    next = ',';
  end
  if ( vary_vc )
    fprintf ( 1, '%c', next )
    fprintf ( 1, 'vc' )
    next = ',';
  end
  fprintf ( 1, ')\n' )

  sample_num = 2000;
  diffusivity_seed = 123456789;
  ns = 50;
  [ xmin, xmax, ymin, ymax ] = region_box ( );

  fprintf ( 1, '  Generating %d random diffusivity cases.\n', sample_num );
  fprintf ( 1, '  The initial random number seed is %d\n', diffusivity_seed );
  fprintf ( 1, '  Each case involves:\n' );
  fprintf ( 1, '    1 diffusivity seed,\n' );
  fprintf ( 1, '    %d diffusivity parameters,\n', 4 );
  fprintf ( 1, '    %d sensor readings.\n', ns );

  data = zeros ( sample_num, 1 + 4 + ns );

  for i = 1 : sample_num

    rng ( diffusivity_seed );
    fprintf ( 1, '  Case %d, diffusivity_seed = %d\n', i, diffusivity_seed );

    if ( vary_xc )
      xc = xmin + rand ( 1, 1 ) * ( xmax - xmin );
    else
      xc = ( xmin + xmax ) / 2.0;
    end
    if ( vary_yc )
      yc = ymin + rand ( 1, 1 ) * ( ymax - ymin );
    else
      yc = ( ymin + ymax ) / 2.0;
    end
    if ( vary_sc )
      sc = 0.05 + 0.95 * rand ( 1, 1 );
    else
      sc = 0.5;
    end
    if ( vary_vc )
      vc = 0.5 + 4.5 * rand ( 1, 1 );
    else
      vc = 2.5;
    end

    [ ns, xs, ys, vs ] = paraheat_gaussian ( xc, yc, sc, vc );

    data(i,:) = [ diffusivity_seed, xc, yc, sc, vc, vs' ];

    diffusivity_seed = diffusivity_seed + 1;

  end
%
%  Write data to a file.
%
  filename = 'paraheat_gaussian_sample_data.txt';
  save ( filename, 'data', '-ascii' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  %d by %d array of data written to "%s"\n', ...
    sample_num, 1 + 4 + ns, filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'paraheat_gaussian_sample\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../paraheat_gaussian' );

  return
end
function [ xmin, xmax, ymin, ymax ] = region_box ( )

%*****************************************************************************80
%
%% region_box returns the minimum and maximum x and y values of the region.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    10 April 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Output, real XMIN, XMAX, YMIN, YMAX, the argument ranges.
%
  xmin = 0.0;
  xmax = 1.0;
  ymin = 0.0;
  ymax = 1.0;

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% TIMESTAMP prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end
