# include # include # include # include # include # include # include using namespace std; int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // brownian_2d_plot() creates a line plot of two-dimensional Brownian motion. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 17 September 2026 // // Author: // // John Burkardt // { string command_filename; string data_filename; string graphic_filename; string header = "brownian_2d"; ofstream command_unit; timestamp ( ); cout << "\n"; cout << "brownian_2d_plot():\n"; cout << " C++ version\n"; cout << " Create a line plot two-dimensional Brownian motion.\n"; // // Set filenames. // command_filename = header + "_commands.txt"; graphic_filename = header + "_plot.png"; data_filename = header + "_data.txt"; // // 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 --->'\n"; command_unit << "set title '1000 steps of Brownian Motion'\n"; command_unit << "set grid\n"; command_unit << "set timestamp\n"; command_unit << "set style data lines\n"; command_unit << "plot '" << data_filename << "' using 1:2 with lines lw 3\n" ; command_unit << "quit\n"; command_unit.close ( ); cout << "\n"; cout << " Plot commands stored in '" << command_filename << "'\n"; // // Terminate. // cout << "\n"; cout << "brownian_2d_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 }