# include # include # include # include # include # include # include using namespace std; int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // humps_plot() plots y=humps(x) directly from the formula. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 Sepember 2026 // // Author: // // John Burkardt // { string command_filename; string graphic_filename; string header = "humps"; ofstream command_unit; timestamp ( ); cout << "\n"; cout << "humps_plot():\n"; cout << " C++ version\n"; cout << " Plot y=humps(x) directly from the formula.\n"; // // Set filenames. // command_filename = header + "_commands.txt"; graphic_filename = header + "_plot.png"; // // Create the command file. // command_unit.open ( command_filename.c_str ( ) ); command_unit << "# " << command_filename << "\n"; command_unit << "#\n"; command_unit << "# Usage:\n"; command_unit << "# gnuplot < " << command_filename << "\n"; command_unit << "#\n"; command_unit << "set term png\n"; command_unit << "set output '" << graphic_filename << "'\n"; command_unit << "set xlabel '<--- x --->'\n"; command_unit << "set ylabel '<--- y=humps(x) --->'\n"; command_unit << "set title 'The humps() function'\n"; command_unit << "set grid\n"; command_unit << "set timestamp\n"; command_unit << "set style data lines\n"; command_unit << "set xrange [0.0:2.0]\n"; command_unit << "set samples 51\n"; command_unit << "set xtics 4\n"; command_unit << "f(x)=1.0/((x-0.3)**2+0.01)+1.0/((x-0.9)**2+0.04)-6.0\n"; command_unit << "plot f(x) with linespoints pt 7 ps 2\n" ; command_unit << "quit\n"; command_unit.close ( ); cout << "\n"; cout << " Plot commands stored in '" << command_filename << "'\n"; // // Terminate. // cout << "\n"; cout << "humps_plot():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }