# include # include # include # include # include int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: humps_plot_gnuplot() makes a line plot of y=humps(x). Licensing: This code is distributed under the MIT license. Modified: 28 September 2024 Author: John Burkardt */ { char command_filename[] = "humps_plot_gnuplot_commands.txt"; FILE *command; char header[] = "humps"; timestamp ( ); printf ( "\n" ); printf ( "humps_plot_gnuplot():\n" ); printf ( " C version\n" ); printf ( " Create a line plot of y=humps(x).\n" ); printf ( " Create corresponding gnuplot() input files.\n" ); /* Create the command file. */ command = fopen ( command_filename, "wt" ); fprintf ( command, "# %s\n", command_filename ); fprintf ( command, "#\n" ); fprintf ( command, "# Usage:\n" ); fprintf ( command, "# gnuplot < %s\n", command_filename ); fprintf ( command, "#\n" ); fprintf ( command, "set term png\n" ); fprintf ( command, "set output '%s_plot_gnuplot.png'\n", header ); fprintf ( command, "set xlabel '<--- x --->'\n" ); fprintf ( command, "set ylabel '<--- y=humps(x) --->'\n" ); fprintf ( command, "set title 'y=humps(x)\n" ); fprintf ( command, "set grid\n" ); fprintf ( command, "set style data lines\n" ); fprintf ( command, "set xrange [0.0:2.0]\n" ); fprintf ( command, "set samples 51\n" ); fprintf ( command, "set xtics 4\n" ); fprintf ( command, "f(x)=1.0/((x-0.3)**2+0.01)+1.0/((x-0.9)**2+0.04)-6.0\n" ); fprintf ( command, "plot f(x) with linespoints pt 7 ps 2\n" ); fprintf ( command, "quit\n" ); fclose ( command ); printf ( "\n" ); printf ( " Plot commands stored in \"%s\".\n", command_filename ); printf ( " To create plot:\n" ); printf ( " gnuplot < %s\n", command_filename ); /* Terminate. */ printf ( "\n" ); printf ( "humps_plot_gnuplot():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }