# include # include # include # include # include # include # include using namespace std; int main ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // correlation_heat_map() creates a heat map of a correlation matrix. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 April 2025 // // Author: // // John Burkardt // { double cmax; double cmin; string command_filename; ofstream command_unit; double xmax; double xmin; double ymax; double ymin; timestamp ( ); cout << "\n"; cout << "correlation_heat_map():\n"; cout << " C++ version\n"; cout << " Heat map of a correlation matrix using gnuplot().\n"; cmin = 0.28; cmax = 1.00; command_filename = "correlation_heat_map_commands.txt"; command_unit.open ( command_filename.c_str ( ) ); command_unit << "# correlation_heat_map_commands.txt\n"; command_unit << "#\n"; command_unit << "# Usage:\n"; command_unit << "# gnuplot < correlation_heat_map_commands.txt\n"; command_unit << "#\n"; command_unit << "set term png\n"; command_unit << "set output 'correlation_heat_map.png'\n"; command_unit << "set xlabel '<--- X --->'\n"; command_unit << "set ylabel '<--- Y --->'\n"; command_unit << "set title 'Heat map of correlation data'\n"; command_unit << "unset key\n"; command_unit << "set tic scale 0\n"; command_unit << "set palette rgbformula 21, 22, 23\n"; command_unit << "set cbrange [" << cmin << ":" << cmax << "]\n"; command_unit << "unset cbtics\n"; // // These relate to the 1x8 range of i and j. // xmin = -0.5; xmax = 7.5; ymin = -0.5; ymax = 7.5; command_unit << "set xrange [" << xmin << ":" << xmax << "]\n"; command_unit << "set yrange [" << ymax << ":" << ymin << "]\n"; command_unit << "set size square\n"; command_unit << "set view map\n"; command_unit << "splot 'correlation_data.txt' matrix with image\n"; command_unit << "quit\n"; command_unit.close ( ); cout << " Created command file 'correlation_heat_map_commands.txt'\n"; // // Terminate. // cout << "\n"; cout << "correlation_heat_map():\n"; cout << " Normal end of execution.\n"; timestamp ( ); return 0; } //****************************************************************************80 double *r8vec_linspace_new ( int n, double a_first, double a_last ) //****************************************************************************80 // // Purpose: // // r8vec_linspace_new() creates a vector of linearly spaced values. // // Discussion: // // An R8VEC is a vector of R8's. // // 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. // // In other words, the interval is divided into N-1 even subintervals, // and the endpoints of intervals are used as the points. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 March 2011 // // Author: // // John Burkardt // // Input: // // int N, the number of entries in the vector. // // double A_FIRST, A_LAST, the first and last entries. // // Output: // // double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. // { double *a; int i; a = new double[n]; if ( n == 1 ) { a[0] = ( a_first + a_last ) / 2.0; } else { for ( i = 0; i < n; i++ ) { a[i] = ( ( double ) ( n - 1 - i ) * a_first + ( double ) ( i ) * a_last ) / ( double ) ( n - 1 ); } } return a; } //****************************************************************************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 }