function mark_points ( )

%*****************************************************************************80
%
%% mark_points() shows how to add marked points to a plot.
%
%  Discussion:
%
%    You can't add more items to a gnuplot() plot once it's created, 
%    so if you want to plot some points, and then include some markers,
%    then you have to create some auxilliary data files identifying those
%    marked points, and refer to them in an extra-long single plot() command.
%   
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 December 2025
%
%  Author:
%
%    John Burkardt
%
  n = 101;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'mark_points():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Plot a damped sine function over a range.\n' );
  fprintf ( 1, '  Mark the first data point green, and the last one red.\n' );
%
%  damped_sine
%
  rho0 = 1.0;
  rho = linspace ( -12.0, +12.0, n );
  c = correlation_damped_sine ( n, rho, rho0 );
  mark_points_plot ( n, rho, c, 'mark_points', 'Marking points in gnuplot' );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'mark_points():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
function c = correlation_damped_sine ( n, rho, rho0 )

%*****************************************************************************80
%
%% correlation_damped_sine() evaluates the damped sine correlation function.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 November 2012
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Petter Abrahamsen,
%    A Review of Gaussian Random Fields and Correlation Functions,
%    Norwegian Computing Center, 1997.
%
%  Input:
%
%    integer N, the number of arguments.
%
%    real RHO(N), the arguments.
%
%    real RHO0, the correlation length.
%
%  Output:
%
%    real C(N), the correlations.
%
  rho = rho(:);
  c = ones ( n, 1 );
  i = find ( rho ~= 0.0 );
  c(i) = rho0 * sin ( abs ( rho(i) ) / rho0 ) ./ abs ( rho(i) );

  return
end
function mark_points_plot ( n, rho, c, header, title )

%*****************************************************************************80
%
%% mark_points_plot() adds two marked points to a plot.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 December 2025
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of arguments.
%
%    real RHO(N), the arguments.
%
%    real C(N), the correlations.
%
%    string HEADER, an identifier for the files.
%
%    string TITLE, a title for the plot.
%

%
%  Create the main data file.
%
  data_filename = strcat ( header, '_data.txt' );
  data_unit = fopen ( data_filename, 'wt' );
  for i = 1 : n
    fprintf ( data_unit, '  %14.6g  %14.6g\n', rho(i), c(i) );
  end
  fclose ( data_unit );
  fprintf ( 1, '  Created data file "%s"\n', data_filename );
%
%  Create a data file for the green point.
%
  start_data_filename = strcat ( header, '_start_data.txt' );
  data_unit = fopen ( start_data_filename, 'wt' );
  fprintf ( data_unit, '  %14.6g  %14.6g\n', rho(1), c(1) );
  fclose ( data_unit );
  fprintf ( 1, '  Created data file "%s"\n', start_data_filename );
%
%  Create a data file for the red point.
%
  end_data_filename = strcat ( header, '_end_data.txt' );
  data_unit = fopen ( end_data_filename, 'wt' );
  fprintf ( data_unit, '  %14.6g  %14.6g\n', rho(n), c(n) );
  fclose ( data_unit );
  fprintf ( 1, '  Created data file "%s"\n', end_data_filename );
%
%  Create the command file.
%
  command_filename = strcat ( header, '_commands.txt' );
  command_unit = fopen ( command_filename, 'wt' );
  fprintf ( command_unit, '# %s\n', command_filename );
  fprintf ( command_unit, '#\n' );
  fprintf ( command_unit, '# Usage:\n' );
  fprintf ( command_unit, '#  gnuplot < %s\n', command_filename );
  fprintf ( command_unit, '#\n' );
  fprintf ( command_unit, 'set term png\n' );
  fprintf ( command_unit, 'set output "%s.png"\n', header );
  fprintf ( command_unit, 'set xlabel "Distance Rho"\n' );
  fprintf ( command_unit, 'set ylabel "Correlation C(Rho)"\n' );
  fprintf ( command_unit, 'set title "%s"\n', title );
  fprintf ( command_unit, 'set grid\n' );
  fprintf ( command_unit, 'set style data lines\n' );
  fprintf ( command_unit, ...
    'plot "%s" using 1:2 lw 3 linecolor rgb "blue", \\\n', data_filename );
  fprintf ( command_unit, ...
    '     "%s" using 1:2 with points pointtype 7 pointsize 3 linecolor rgb "green", \\\n', start_data_filename );
  fprintf ( command_unit, ...
    '    "%s"  using 1:2 with points pointtype 7 pointsize 3 linecolor rgb "red"\n', end_data_filename );
  fprintf ( command_unit, 'quit\n' );
  fclose ( command_unit );
  fprintf ( 1, '  Created command file "%s"\n', command_filename );

  return
end
 
