# include # include # include using namespace std; # include "filum.H" int main ( void ); void test02 ( void ); void test06 ( void ); void test085 ( void ); void test11 ( void ); void test12 ( void ); void test13 ( void ); void test14 ( void ); void test15 ( void ); void test17 ( void ); void test22 ( void ); void test24 ( void ); //****************************************************************************80 int main ( void ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for FILUM_PRB. // // Discussion: // // FILUM_PRB calls the FILUM tests. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "FILUM_PRB:\n"; cout << " C++ version\n"; cout << "\n"; cout << " Test routines in the FILUM library.\n"; test02 ( ); test06 ( ); test085 ( ); test11 ( ); test12 ( ); test13 ( ); test14 ( ); test15 ( ); test17 ( ); test22 ( ); test24 ( ); cout << "\n"; cout << "FILUM_PRB:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test02 ( void ) //****************************************************************************80 // // Purpose: // // TEST02 tests FILE_CHAR_COUNT. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; cout << "\n"; cout << "TEST02\n"; cout << " FILE_CHAR_COUNT counts the characters in a file.\n"; strcpy ( file_name, "filum_prb_test.txt" ); cout << "\n"; cout << " Examining file \"" << file_name << "\".\n"; cout << "\n"; cout << " Number of characters: " << file_char_count ( file_name ) << ".\n"; return; } //****************************************************************************80 void test06 ( void ) //****************************************************************************80 // // Purpose: // // TEST0035 tests FILE_EXIST. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; cout << "\n"; cout << "TEST06\n"; cout << " FILE_EXIST reports whether a file 'exists'.\n"; cout << "\n"; cout << " Exist? File_name\n"; cout << "\n"; strcpy ( file_name, "filum_prb.cc" ); cout << " " << file_exist ( file_name ) << " " << file_name << "\n"; strcpy ( file_name, "filum.cc" ); cout << " " << file_exist ( file_name ) << " " << file_name << "\n"; strcpy ( file_name, "raisin.txt" ); cout << " " << file_exist ( file_name ) << " " << file_name << "\n"; strcpy ( file_name, "make.money.fast" ); cout << " " << file_exist ( file_name ) << " " << file_name << "\n"; return; } //****************************************************************************80 void test085 ( void ) //****************************************************************************80 // // Purpose: // // TEST085 tests FILE_LINE_WIDTH. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; cout << "\n"; cout << "TEST085\n"; cout << " FILE_LINE_WIDTH counts the longest line in a file.\n"; strcpy ( file_name, "filum_prb_test.txt" ); cout << "\n"; cout << " Examining file \"" << file_name << "\".\n"; cout << "\n"; cout << " Longest line is: " << file_line_width ( file_name ) << " characters.\n"; return; } //****************************************************************************80 void test11 ( void ) //****************************************************************************80 // // Purpose: // // TEST11 tests FILE_NAME_DEC. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { int i; int j; char string[20]; cout << "\n"; cout << "TEST11\n"; cout << " FILE_NAME_DEC decrements a string\n"; cout << "\n"; cout << " Input Output\n"; for ( i = 0; i < 4; i++ ) { if ( i == 0 ) { strcpy ( string, "file???.dat" ); } else if ( i == 1 ) { strcpy ( string, "file076.dat" ); } else if ( i == 2 ) { strcpy ( string, "3cat3.dat " ); } else if ( i == 3 ) { strcpy ( string, "fred03.txt " ); } cout << "\n"; for ( j = 1; j <= 4; j++ ) { cout << " " << setw(11) << string << " "; file_name_dec ( string ); cout << " " << setw(11) << string << "\n"; if ( s_len_trim ( string ) == 0 ) { cout << " (Empty output string. Quit loop!)\n"; break; } } } return; } //****************************************************************************80 void test12 ( void ) //****************************************************************************80 // // Purpose: // // TEST12 tests FILE_NAME_EXT_GET. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { int i; int itest; int j; int ntest = 5; char string[10]; cout << "\n"; cout << "TEST12\n"; cout << " FILE_NAME_EXT_GET finds a file extension.\n"; cout << "\n"; cout << " FILE_NAME Begin End\n"; cout << "\n"; for ( itest = 0; itest < ntest; itest++ ) { if ( itest == 0 ) { strcpy ( string, "bob.for" ); } else if ( itest == 1 ) { strcpy ( string, "N.B.C.D" ); } else if ( itest == 2 ) { strcpy ( string, "Naomi." ); } else if ( itest == 3 ) { strcpy ( string, "Arthur" ); } else if ( itest == 4 ) { strcpy ( string, ".amos" ); } file_name_ext_get ( string, &i, &j ); cout << " " << setw(10) << string << " " << setw(6) << i << " " << setw(6) << j << "\n"; } return; } //****************************************************************************80 void test13 ( void ) //****************************************************************************80 // // Purpose: // // TEST13 tests FILE_NAME_EXT_SWAP. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char ext[4]; char file_name[13]; char *file_name2; int itest; int ntest = 5; cout << "\n"; cout << "TEST13\n"; cout << " FILE_NAME_EXT_SWAP changes a file extension.\n"; cout << "\n"; cout << " FILE_NAME EXT FILE_NAME_EXT_SWAP\n"; cout << "\n"; for ( itest = 0; itest < ntest; itest++ ) { if ( itest == 0 ) { strcpy ( file_name, "bob.for" ); strcpy ( ext, "obj" ); } else if ( itest == 1 ) { strcpy ( file_name, "bob.bob.bob" ); strcpy ( ext, "txt" ); } else if ( itest == 2 ) { strcpy ( file_name, "bob." ); strcpy ( ext, "yak" ); } else if ( itest == 3 ) { strcpy ( file_name, "bob" ); strcpy ( ext, "ps" ); } else if ( itest == 4 ) { strcpy ( file_name, ".oops" ); strcpy ( ext, "eek" ); } cout << " " << setw(12) << file_name << " " << setw(3) << ext << " "; file_name2 = file_name_ext_swap ( file_name, ext ); cout << " " << setw(12) << file_name2 << "\n"; delete [] file_name2; } return; } //****************************************************************************80 void test14 ( void ) //****************************************************************************80 // // Purpose: // // TEST14 tests FILE_NAME_INC. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { int i; int j; char string[20]; cout << "\n"; cout << "TEST14\n"; cout << " FILE_NAME_INC increments a string\n"; cout << "\n"; cout << " Input Output\n"; for ( i = 0; i < 4; i++ ) { if ( i == 0 ) { strcpy ( string, "file???.dat" ); } else if ( i == 1 ) { strcpy ( string, "file072.dat" ); } else if ( i == 2 ) { strcpy ( string, "2cat9.dat " ); } else if ( i == 3 ) { strcpy ( string, "fred99.txt " ); } cout << "\n"; for ( j = 1; j <= 4; j++ ) { cout << " " << setw(11) << string << " "; file_name_inc ( string ); cout << " " << setw(11) << string << "\n"; if ( s_len_trim ( string ) == 0 ) { cout << " (Empty output string. Quit loop!)\n"; break; } } } return; } //****************************************************************************80 void test15 ( void ) //****************************************************************************80 // // Purpose: // // TEST15 tests FILE_NAME_INC. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { int sim; char string[20]; char string1[20]; char string2[20]; int time_step; cout << "\n"; cout << "TEST15\n"; cout << " FILE_NAME_INC increments a string.\n"; cout << "\n"; cout << "\n"; cout << " In this example, the string is a file name.\n"; cout << " The user is going to carry out several simulations.\n"; cout << " For each simulation, a consecutive series of file\n"; cout << " names is desired.\n"; strcpy ( string1, "file_00" ); strcpy ( string2, "_000.txt" ); for ( sim = 1; sim < 5; sim++ ) { cout << "\n"; cout << " Simulation " << sim << " begins.\n"; cout << "\n"; file_name_inc ( string1 ); strcpy ( string, string1 ); strcat ( string, string2 ); for ( time_step = 0; time_step < 4; time_step++ ) { file_name_inc ( string ); cout << " " << setw(11) << string << "\n"; } } return; } //****************************************************************************80 void test17 ( void ) //****************************************************************************80 // // Purpose: // // TEST17 tests FILE_PARA_COUNT. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; int para_num; cout << "\n"; cout << "TEST17\n"; cout << " FILE_PARA_COUNT counts the paragraphs in a file.\n"; strcpy ( file_name, "story.txt" ); cout << "\n"; cout << " Examining file:\n"; cout << " \"" << file_name << "\".\n"; cout << "\n"; para_num = file_para_count ( file_name ); cout << " Number of paragraphs: " << para_num << "\n"; return; } //****************************************************************************80 void test22 ( void ) //****************************************************************************80 // // Purpose: // // TEST22 tests FILE_ROW_COUNT. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; cout << "\n"; cout << "TEST22\n"; cout << " FILE_ROW_COUNT counts the lines in a file.\n"; strcpy ( file_name, "filum_prb_test.txt" ); cout << "\n"; cout << " Examining file \"" << file_name << "\".\n"; cout << "\n"; cout << " Number of lines: " << file_row_count ( file_name ) << ".\n"; return; } //****************************************************************************80 void test24 ( void ) //****************************************************************************80 // // Purpose: // // TEST24 tests FILE_WORD_COUNT. // // Modified: // // 06 June 2007 // // Author: // // John Burkardt // { char file_name[100]; cout << "\n"; cout << "TEST24\n"; cout << " FILE_WORD_COUNT counts the words in a file.\n"; strcpy ( file_name, "filum_prb_test.txt" ); cout << "\n"; cout << " Examining file \"" << file_name << "\".\n"; cout << "\n"; cout << " Number of words: " << file_word_count ( file_name ) << ".\n"; return; }