# include # include # include # include # include # include # include using namespace std; int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // nile_histogram() creates a histogram of Nile flood heights. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 28 September 2026 // // Author: // // John Burkardt // { string command_filename = "nile_commands.txt"; ofstream command; string data_filename = "nile_data.txt"; string plot_filename = "nile_histogram.png"; timestamp ( ); cout << "\n"; cout << "nile_histogram():\n"; cout << " C++ version\n"; cout << " Histogram of Nile flood heights.\n"; // // Create the command file. // command.open ( command_filename.c_str ( ) ); command << "# "<< command_filename << "\n"; command << "#\n"; command << "# Usage:\n"; command << "# gnuplot < " << command_filename << "\n"; command << "#\n"; command << "set term png\n"; command << "set output '" << plot_filename << "'\n"; command << "set xlabel '<--- Height of Nile at Maximum Flood --->'\n"; command << "set ylabel '<--- Frequency --->'\n"; command << "set title 'Yearly Nile Flood Height'\n"; command << "set grid\n"; command << "set timestamp\n"; command << "set style fill solid\n"; command << "unset key\n"; command << "binwidth = 0.25\n"; command << "binstart = 5.0\n"; command << "set boxwidth 0.9*binwidth\n"; command << "plot '" << data_filename << "' i 0 using (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart):(1.0) smooth freq with boxes lc rgb 'red'\n"; command << "quit\n"; command.close ( ); cout << " Plot commands stored in \"" << command_filename << "\".\n"; // // Terminate. // cout << "\n"; cout << "nile_histogram():\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 }