# include # include # include # include "ppc_array.h" # include "ppc_haar.h" int main ( ); void haar_vector_test ( int n ); void haar_matrix_test ( int m, int n ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: ppc_haar_test() tests ppc_haar(). Licensing: This code is distributed under the MIT license. Modified: 12 September 2023 Author: John Burkardt */ { int m; int n; timestamp ( ); printf ( "\n" ); printf ( "ppc_haar_test():\n" ); printf ( " C version\n" ); printf ( " Test ppc_haar().\n" ); n = 8; haar_vector_test ( n ); m = 4; n = 8; haar_matrix_test ( m, n ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_haar_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void haar_vector_test ( int n ) /******************************************************************************/ /* Purpose: haar_vector_test() tests haar_vector_forward() and haar_vector_reverse(). Licensing: This code is distributed under the MIT license. Modified: 11 September 2023 Author: John Burkardt */ { int i; double *v; printf ( "\n" ); printf ( "haar_vector_test():\n" ); /* Define a vector. */ make_vector ( v, n ); for ( i = 0; i < n; i++ ) { v[i] = 1.0 / ( i + 1 ); } printf ( "\n" ); printf ( " vector v:\n" ); printf ( "\n" ); print_vector ( " %g", v, n ); /* Compute forward transform. */ haar_transform_vector ( v, n, WT_FWD ); printf ( "\n" ); printf ( " vector v after forward transform:\n" ); printf ( "\n" ); print_vector ( " %g", v, n ); /* Compute reverse transform. */ haar_transform_vector ( v, n, WT_REV ); printf ( "\n" ); printf ( " vector v after reverse transform:\n" ); printf ( "\n" ); print_vector ( " %g", v, n ); /* Free memory. */ free_vector ( v ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_haar_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return; } /******************************************************************************/ void haar_matrix_test ( int m, int n ) /******************************************************************************/ /* Purpose: haar_matrix_test() tests haar_matrix_forward() and haar_matrix_reverse(). Licensing: This code is distributed under the MIT license. Modified: 12 September 2023 Author: John Burkardt */ { double **a; int i; int j; printf ( "\n" ); printf ( "haar_matrix_test():\n" ); /* Define a matrix. */ make_matrix ( a, m, n ); for ( j = 0; j < n; j++ ) { for ( i = 0; i < m; i++ ) { a[i][j] = 1.0 / ( i + j + 1 ); } } printf ( "\n" ); printf ( " matrix a:\n" ); printf ( "\n" ); print_matrix ( " %g", a, m, n ); /* Compute forward transform. */ haar_transform_matrix ( a, m, n, WT_FWD ); printf ( "\n" ); printf ( " matrix a after forward transform:\n" ); printf ( "\n" ); print_matrix ( " %g", a, m, n ); /* Compute reverse transform. */ haar_transform_matrix ( a, m, n, WT_REV ); printf ( "\n" ); printf ( " matrix a after reverse transform:\n" ); printf ( "\n" ); print_matrix ( " %g", a, m, n ); /* Free memory. */ free_matrix ( a ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_haar_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return; } /******************************************************************************/ 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: 17 June 2014 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 }