# include # include # include # include # include int main ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* 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; FILE *command_unit; double xmax; double xmin; double ymax; double ymin; timestamp ( ); printf ( "\n" ); printf ( "correlation_heat_map():\n" ); printf ( " C version\n" ); printf ( " Heat map of a correlation matrix using gnuplot().\n" ); cmin = 0.28; cmax = 1.00; command_unit = fopen ( "correlation_heat_map_commands.txt", "wt" ); fprintf ( command_unit, "# correlation_heat_map_commands.txt\n" ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "# Usage:\n" ); fprintf ( command_unit, "# gnuplot < correlation_heat_map_commands.txt\n" ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set output 'correlation_heat_map.png'\n" ); fprintf ( command_unit, "set xlabel '<--- X --->'\n" ); fprintf ( command_unit, "set ylabel '<--- Y --->'\n" ); fprintf ( command_unit, "set title 'Heat map of correlation data'\n" ); fprintf ( command_unit, "unset key\n" ); fprintf ( command_unit, "set tic scale 0\n" ); fprintf ( command_unit, "set palette rgbformula 21, 22, 23\n" ); fprintf ( command_unit, "set cbrange [%f:%f]\n", cmin, cmax ); fprintf ( 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; fprintf ( command_unit, "set xrange [%f:%f]\n", xmin, xmax ); fprintf ( command_unit, "set yrange [%f:%f]\n", ymax, ymin ); fprintf ( command_unit, "set size square\n" ); fprintf ( command_unit, "set view map\n" ); fprintf ( command_unit, "splot 'correlation_data.txt' matrix with image\n" ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Created command file 'correlation_heat_map_commands.txt'\n" ); /* Terminate. */ printf ( "\n" ); printf ( "correlation_heat_map():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ double *r8vec_linspace_new ( int n, double a, double b ) /******************************************************************************/ /* 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, B, the first and last entries. Output: double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. */ { int i; double *x; x = ( double * ) malloc ( n * sizeof ( double ) ); if ( n == 1 ) { x[0] = ( a + b ) / 2.0; } else { for ( i = 0; i < n; i++ ) { x[i] = ( ( double ) ( n - 1 - i ) * a + ( double ) ( i ) * b ) / ( double ) ( n - 1 ); } } return x; } /******************************************************************************/ 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: 01 May 2021 Author: John Burkardt */ { # 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 }