# include # include # include # include using namespace std; # include "table_io.H" int main ( void ); void test01 ( void ); void test02 ( void ); void test03 ( void ); void test04 ( void ); void test05 ( void ); void test06 ( void ); //****************************************************************************80 int main ( void ) //****************************************************************************80 // // Purpose: // // TABLE_IO_PRB calls the TABLE_IO test routines. // // Modified: // // 09 November 2006 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "TABLE_IO_PRB\n"; cout << " C++ version\n"; cout << "\n"; cout << " Tests the routines in the TABLE_IO library.\n"; test01 ( ); test02 ( ); test03 ( ); test04 ( ); test05 ( ); test06 ( ); cout << "\n"; cout << "TABLE_IO_PRB\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test01 ( void ) //****************************************************************************80 // // Purpose: // // TEST01 tests DTABLE_WRITE. // // Modified: // // 13 January 2007 // // Author: // // John Burkardt // { # define M 5 # define N 20 bool header; int i; int j; char *output_filename = "dtable_05_00020.txt"; double table[M*N]; cout << "\n"; cout << "TEST01\n"; cout << " DTABLE_WRITE writes a real TABLE file.\n"; for ( i = 0; i < M; i++ ) { for ( j = 0; j < N; j++ ) { table[i+j*M] = ( double ) ( 100 * ( j + 1 ) + ( i + 1 ) ) / 10.0E+00; } } cout << "\n"; cout << " Spatial dimension M = " << M << "\n"; cout << " Number of points N = " << N << "\n"; r8mat_print_some ( M, N, table, 1, 1, 5, 5, " 5x5 portion of the data written to file:" ); r8mat_transpose_print_some ( M, N, table, 1, 1, 5, 5, " 5x5 portion of the TRANSPOSED data:" ); header = true; dtable_write ( output_filename, M, N, table, header ); cout << "\n"; cout << " Wrote the header and data for \"" << output_filename << "\"\n"; return; # undef M # undef N } //****************************************************************************80 void test02 ( void ) //****************************************************************************80 // // Purpose: // // TEST02 tests DTABLE_HEADER_READ and DTABLE_DATA_READ. // // Modified: // // 13 January 2007 // // Author: // // John Burkardt // { char *input_filename = "dtable_05_00020.txt"; int i; int j; int m; int n; double *table; cout << "\n"; cout << "TEST02\n"; cout << " For real data stored in a TABLE file,\n"; cout << " DTABLE_HEADER_READ reads the header\n"; cout << " (Information about the dimension of the data)\n"; cout << " DTABLE_DATA_READ reads the data.\n"; dtable_header_read ( input_filename, &m, &n ); cout << "\n"; cout << " Read the header of \"" << input_filename << "\".\n"; cout << "\n"; cout << " Spatial dimension M = " << m << "\n"; cout << " Number of points N = " << n << "\n"; table = dtable_data_read ( input_filename, m, n ); cout << "\n"; cout << " Read the data in \"" << input_filename << "\".\n"; r8mat_print_some ( m, n, table, 1, 1, 5, 5, " 5x5 portion of data read from file:" ); delete [] table; return; } //****************************************************************************80 void test03 ( void ) //****************************************************************************80 // // Purpose: // // TEST03 tests ITABLE_WRITE. // // Modified: // // 13 January 2007 // // Author: // // John Burkardt // { # define M 5 # define N 20 bool header; int i; int j; char *output_filename = "itable_05_00020.txt"; int table[M*N]; cout << "\n"; cout << "TEST03\n"; cout << " ITABLE_WRITE writes an integer TABLE file.\n"; for ( i = 0; i < M; i++ ) { for ( j = 0; j < N; j++ ) { table[i+j*M] = ( 100 * ( j + 1 ) + ( i + 1 ) ); } } cout << "\n"; cout << " Spatial dimension M = " << M << "\n"; cout << " Number of points N = " << N << "\n"; i4mat_print_some ( M, N, table, 1, 1, 5, 5, " 5 x 5 portion of data written to file:" ); header = true; itable_write ( output_filename, M, N, table, header ); cout << "\n"; cout << " Wrote the header and data for \"" << output_filename << "\"\n"; return; # undef M # undef N } //****************************************************************************80 void test04 ( void ) //****************************************************************************80 // // Purpose: // // TEST04 tests ITABLE_HEADER_READ, ITABLE_DATA_READ. // // Modified: // // 13 January 2007 // // Author: // // John Burkardt // { char *input_filename = "itable_05_00020.txt"; int m; int n; int *table; cout << "\n"; cout << "TEST04\n"; cout << " For integer data stored in a TABLE file,\n"; cout << " ITABLE_HEADER_READ reads the header\n"; cout << " (Information about the dimension of the data)\n"; cout << " ITABLE_DATA_READ reads the data.\n"; itable_header_read ( input_filename, &m, &n ); cout << "\n"; cout << " Read the header of \"" << input_filename << "\".\n"; cout << "\n"; cout << " Spatial dimension M = " << m << "\n"; cout << " Number of points N = " << n << "\n"; table = itable_data_read ( input_filename, m, n ); cout << "\n"; cout << " Read the data in \"" << input_filename << "\".\n"; i4mat_print_some ( m, n, table, 1, 1, 5, 5, " 5x5 portion of data read from file:" ); delete [] table; return; } //****************************************************************************80 void test05 ( void ) //****************************************************************************80 // // Purpose: // // TEST05 tests R8MAT_UNIFORM_01. // // Modified: // // 27 September 2006 // // Author: // // John Burkardt // { # define M 2 # define N 10 int seed = 123456789; double *table; cout << "\n"; cout << "TEST05\n"; cout << " R8MAT_UNIFORM_01 sets a random double precision\n"; cout << " table dataset.\n"; cout << "\n"; cout << " Spatial dimension M = " << M << "\n"; cout << " Number of points N = " << N << "\n"; table = r8mat_uniform_01 ( M, N, &seed ); r8mat_print_some ( M, N, table, 1, 1, 5, 10, " 5x10 portion of random real table dataset:" ); delete [] table; return; # undef M # undef N } //****************************************************************************80 void test06 ( void ) //****************************************************************************80 // // Purpose: // // TEST06 tests ITABLE_DATA_BORDER_CUT and ITABLE_DATA_BORDER_ADD. // // Modified: // // 13 January 2007 // // Author: // // John Burkardt // { int m = 6; int n = 4; int *table; int *table2; int *table3; cout << "\n"; cout << "TEST06\n"; cout << " ITABLE_DATA_BORDER_CUT cuts off the border;\n"; cout << " ITABLE_DATA_BORDER_ADD adds a zero border;\n"; cout << "\n"; cout << " Spatial dimension M = " << m << "\n"; cout << " Number of points N = " << n << "\n"; table = i4mat_indicator ( m, n ); i4mat_print ( m, n, table, " Initial dataset:" ); table2 = itable_data_border_cut ( m, n, table ); i4mat_print ( m-2, n-2, table2, " 'Cut' dataset:" ); table3 = itable_data_border_add ( m-2, n-2, table2 ); i4mat_print ( m, n, table3, " 'Added' dataset:" ); delete [] table; delete [] table2; delete [] table3; return; }