# include # include # include # include # include # include using namespace std; # include "shepard_interp_2d.hpp" # include "test_interp_2d.hpp" # include "r8lib.hpp" int main ( ); void test01 ( int prob, int g, double p ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // shepard_interp_2d_test() tests shepard_interp_2d(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 15 October 2012 // // Author: // // John Burkardt // { int g; int j; double p; double p_test[4] = { 1.0, 2.0, 4.0, 8.0 }; int p_test_num = 4; int prob; int prob_num; timestamp ( ); cout << "\n"; cout << "shepard_interp_2d_test():\n"; cout << " C++ version\n"; cout << " Test SHEPARD_INTERP_2D().\n"; cout << " The R8LIB library is needed.\n"; cout << " This test also needs the TEST_INTERP_2D library.\n"; prob_num = f00_num ( ); g = 1; for ( prob = 1; prob <= prob_num; prob++ ) { for ( j = 0; j < p_test_num; j++ ) { p = p_test[j]; test01 ( prob, g, p ); } } // // Terminate. // cout << "\n"; cout << "SHEPARD_INTERP_2D_TEST:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test01 ( int prob, int g, double p ) //****************************************************************************80 // // Purpose: // // TEST01 tests SHEPARD_INTERP_2D. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 02 October 2012 // // Author: // // John Burkardt // // Parameters: // // Input, int PROB, the problem number. // // Input, int G, the grid number. // // Input, double P, the power used in the distance weighting. // { bool debug = false; double int_error; int nd; int ni; double *xd; double *xi; double *yd; double *yi; double *zd; double *zi; cout << "\n"; cout << "TEST01:\n"; cout << " Interpolate data from TEST_INTERP_2D problem #" << prob << "\n"; cout << " using grid #" << g << "\n"; cout << " using Shepard interpolation with P = " << p << "\n"; nd = g00_size ( g ); cout << " Number of data points = " << nd << "\n"; xd = new double[nd]; yd = new double[nd]; g00_xy ( g, nd, xd, yd ); zd = new double[nd]; f00_f0 ( prob, nd, xd, yd, zd ); if ( debug ) { r8vec3_print ( nd, xd, yd, zd, " X, Y, Z data:" ); } // // #1: Does interpolant match function at interpolation points? // ni = nd; xi = r8vec_copy_new ( ni, xd ); yi = r8vec_copy_new ( ni, yd ); zi = shepard_interp_2d ( nd, xd, yd, zd, p, ni, xi, yi ); int_error = r8vec_norm_affine ( ni, zi, zd ) / ( double ) ( ni ); cout << "\n"; cout << " L2 interpolation error averaged per interpolant node = " << int_error << "\n"; delete [] xd; delete [] xi; delete [] yd; delete [] yi; delete [] zd; delete [] zi; return; } //****************************************************************************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 }