program filum_prb ! !******************************************************************************* ! !! FILUM_PRB tests routines from the FILUM library. ! implicit none ! call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'FILUM_PRB' write ( *, '(a)' ) ' A set of test programs for FILUM.' call test001 call test002 call test003 call test004 call test005 call test006 call test007 call test008 call test009 call test010 call test011 call test012 call test013 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'FILUM_PRB' write ( *, '(a)' ) ' Normal end of execution.' stop end subroutine test001 ! !******************************************************************************* ! !! TEST001 tests FILE_APPEND. ! implicit none ! integer ierror character ( len = 100 ) file_name integer ios integer iunit integer nrec character ( len = 100 ) old_file_name ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST001' write ( *, '(a)' ) ' FILE_APPEND makes a new version of a file' write ( *, '(a)' ) ' which is "appendable".' write ( *, '(a)' ) ' ' old_file_name = 'filprb_test.txt' file_name = 'filprb_append.txt' call file_copy ( old_file_name, file_name, ierror ) call get_unit ( iunit ) open ( unit = iunit, file = file_name, status = 'replace', iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST001' write ( *, '(a)' ) ' Could not open the file.' return end if write ( iunit, '(a)' ) 'This is the file: ' // trim ( file_name ) write ( iunit, '(a)' ) ' ' write ( iunit, '(a)' ) 'After the first pass, it has a total' write ( iunit, '(a)' ) 'of 4 lines of text.' close ( unit = iunit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'Current contents of ' // trim ( file_name ) write ( *, '(a)' ) ' ' call file_print ( file_name ) call file_append ( file_name, ierror, iunit, nrec ) write ( iunit, '(a)' ) ' ' write ( iunit, '(a)' ) 'This is new information that has been' write ( iunit, '(a)' ) 'written to the file during a separate pass.' write ( iunit, '(a)' ) ' ' write ( iunit, '(a)' ) 'The file should now contain a total of ' write ( iunit, '(a)' ) '11 lines of text.' close ( unit = iunit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'Contents of file after reopening in APPEND mode:' write ( *, '(a)' ) ' ' call file_print ( file_name ) return end subroutine test002 ! !******************************************************************************* ! !! TEST002 tests FILE_CHAR_COUNT. !! TEST002 tests FILE_LINE_COUNT. !! TEST002 tests FILE_PARA_COUNT. !! TEST002 tests FILE_WORD_COUNT. ! implicit none ! character ( len = 100 ) file_name integer ierror integer nchar integer nline integer npara integer nword ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST002' write ( *, '(a)' ) ' FILE_CHAR_COUNT counts the characters in a file.' write ( *, '(a)' ) ' FILE_LINE_COUNT counts the lines in a file.' write ( *, '(a)' ) ' FILE_PARA_COUNT counts the paragraphs in a file.' write ( *, '(a)' ) ' FILE_WORD_COUNT counts the words in a file.' write ( *, '(a)' ) ' ' file_name = 'filprb_test.txt' write ( *, '(a)' ) ' Examining file: ' // trim ( file_name ) write ( *, '(a)' ) ' ' call file_char_count ( file_name, nchar ) write ( *, '(a,i6)' ) ' Number of characters: ', nchar call file_line_count ( file_name, nline ) write ( *, '(a,i6)' ) ' Number of lines: ', nline call file_para_count ( file_name, npara ) write ( *, '(a,i6)' ) ' Number of paragraphs: ', npara call file_word_count ( file_name, nword ) write ( *, '(a,i6)' ) ' Number of words: ', nword return end subroutine test003 ! !******************************************************************************* ! !! TEST003 tests FILE_COPY. ! implicit none ! integer ierror character ( len = 100 ) new_file_name character ( len = 100 ) old_file_name ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST003' write ( *, '(a)' ) ' FILE_COPY makes a copy of a file.' write ( *, '(a)' ) ' ' old_file_name = 'filprb_test.txt' new_file_name = 'filprb_copy.txt' call file_copy ( old_file_name, new_file_name, ierror ) if ( ierror /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' FILE_COPY returned IERROR = ', ierror end if return end subroutine test004 ! !******************************************************************************* ! !! TEST004 tests FILE_GET_NEXT_WORD. ! implicit none ! character ( len = 100 ) file_name integer ierror integer ios integer iunit integer num_text integer num_text_old integer num_word character ( len = 100 ) text character ( len = 100 ) word ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST004' write ( *, '(a)' ) ' FILE_GET_NEXT_WORD gets the next word' write ( *, '(a)' ) ' from a file.' write ( *, '(a)' ) ' ' file_name = 'filprb_test.txt' call get_unit ( iunit ) open ( unit = iunit, file = file_name, status = 'old', iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'Could not open the file:' write ( *, '(a)' ) file_name return end if num_text = 0 num_word = 0 text = ' ' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Line Word ---WORD--- ---TEXT--------------' write ( *, '(a)' ) ' ' do num_text_old = num_text call file_get_next_word ( iunit, word, text, num_text, ierror ) if ( ierror /= 0 ) then exit end if if ( num_text == num_text_old ) then num_word = num_word + 1 else num_word = 1 end if write ( *, '(i6,2x,i6,2x,a,2x,a)' ) num_text, num_word, word(1:10), & trim ( text ) end do write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'End of file!' close ( unit = iunit ) return end subroutine test005 ! !******************************************************************************* ! !! TEST005 tests FILE_NAME_EXT_GET. ! implicit none ! integer, parameter :: ntest = 5 ! character ( len = 10 ) file_name integer i integer itest integer j character ( len = 10 ) string(ntest) ! string(1) = 'bob.for' string(2) = 'N.B.C.D' string(3) = 'Naomi.' string(4) = 'Arthur' string(5) = '.amos' write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST005' write ( *, '(a)' ) ' FILE_NAME_EXT_GET finds a file extension.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' FILE_NAME Begin End' write ( *, '(a)' ) ' ' do itest = 1, ntest file_name = string(itest) call file_name_ext_get ( file_name, i, j ) write ( *, '(2x,a,i3,i3)' ) string(itest), i, j end do return end subroutine test006 ! !******************************************************************************* ! !! TEST006 tests FILE_NAME_EXT_SWAP. ! implicit none ! integer, parameter :: ntest = 5 ! character ( len = 3 ) ext character ( len = 3 ) ext_test(ntest) character ( len = 12 ) file_name integer itest character ( len = 12 ) string(ntest) ! string(1) = 'bob.for' string(2) = 'bob.bob.bob' string(3) = 'bob.' string(4) = 'bob' string(5) = '.oops' ext_test(1) = 'obj' ext_test(2) = 'txt' ext_test(3) = 'yak' ext_test(4) = 'ps' ext_test(5) = 'eek' write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST006' write ( *, '(a)' ) ' FILE_NAME_EXT_SWAP changes a file extension.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'Input Output' write ( *, '(a)' ) 'FILE_NAME EXT FILE_NAME' write ( *, '(a)' ) ' ' do itest = 1, ntest file_name = string(itest) ext = ext_test(itest) call file_name_ext_swap ( file_name, ext ) write ( *, '(a,3x,a,4x,a)' ) string(itest), ext_test(itest), file_name end do return end subroutine test007 ! !******************************************************************************* ! !! TEST007 tests FILE_NAME_INC. ! implicit none ! integer, parameter :: ntest = 4 ! character ( len = 20 ) file_name integer i character ( len = 20 ) string(ntest) ! string(1) = 'file???.dat' string(2) = 'file072.dat' string(3) = '2cat9.dat' string(4) = 'fred99.txt' write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST007' write ( *, '(a)' ) ' FILE_NAME_INC increments a string' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Input Output' write ( *, '(a)' ) ' ' do i = 1, ntest file_name = string(i) call file_name_inc ( file_name ) write ( *, '(2x,a,a)' ) string(i), file_name end do return end subroutine test008 ! !******************************************************************************* ! !! TEST008 tests FILE_PAREN_CHECK. ! implicit none ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST008' write ( *, '(a)' ) ' FILE_PAREN_CHECK checks a file for parenthesis errors.' call file_paren_check ( 'filprb_parens1.txt' ) call file_paren_check ( 'filprb_parens2.txt' ) call file_paren_check ( 'filprb_parens3.txt' ) return end subroutine test009 ! !******************************************************************************* ! !! TEST009 tests FILE_REVERSE_COLUMNS. ! implicit none ! character ( len = 100 ) new_file_name character ( len = 100 ) old_file_name ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST009' write ( *, '(a)' ) ' FILE_REVERSE_COLUMNS makes a copy of a file with' write ( *, '(a)' ) ' each line reversed.' write ( *, '(a)' ) ' ' old_file_name = 'filprb_test.txt' new_file_name = 'filprb_reverse_columns.txt' call file_reverse_columns ( old_file_name, new_file_name ) return end subroutine test010 ! !******************************************************************************* ! !! TEST010 tests FILE_REVERSE_ROWS. ! implicit none ! character ( len = 100 ) new_file_name character ( len = 100 ) old_file_name ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST010' write ( *, '(a)' ) ' FILE_REVERSE_ROWS makes a copy of a file with the' write ( *, '(a)' ) ' lines in reverse order.' write ( *, '(a)' ) ' ' old_file_name = 'filprb_test.txt' new_file_name = 'filprb_reverse_rows.txt' call file_reverse_rows ( old_file_name, new_file_name ) return end subroutine test011 ! !******************************************************************************* ! !! TEST011 tests FILE_TAG_CHECK. ! implicit none ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST011' write ( *, '(a)' ) ' FILE_TAG_CHECK checks a file for tag errors.' call file_tag_check ( 'filprb_parens1.txt', '(', ')' ) call file_tag_check ( 'filprb_parens2.txt', '(', ')' ) call file_tag_check ( 'filprb_parens3.txt', '(', ')' ) call file_tag_check ( 'filprb_braces.txt', '{', '}' ) return end subroutine test012 ! !******************************************************************************* ! !! TEST012 tests FILE_COLUMN_COUNT. ! implicit none ! character ( len = 100 ) file_name integer ierror integer ncolumn ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST012' write ( *, '(a)' ) ' FILE_COLUMN_COUNT counts the columns in a file.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' It is assumed that the file contains a number of lines,' write ( *, '(a)' ) ' with each line containing the same number of words.' write ( *, '(a)' ) ' The task is to determine the number of words in a line,' write ( *, '(a)' ) ' that is, the number of "columns" of text.' file_name = 'filprb_4by5.txt' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Examining file: ' // trim ( file_name ) call file_column_count ( file_name, ncolumn ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' Number of columns: ', ncolumn return end subroutine test013 ! !******************************************************************************* ! !! TEST013 tests FILE_COLUMN_COUNT. !! TEST013 tests FILE_COLUMN_RANGE ! implicit none ! integer, parameter :: max_col = 5 ! real col_max(max_col) real col_min(max_col) character ( len = 100 ) file_name integer i integer ierror integer ncolumn ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST013' write ( *, '(a)' ) ' FILE_COLUMN_COUNT counts the columns in a file.' write ( *, '(a)' ) ' FILE_COLUMN_RANGE finds the range of the columns.' write ( *, '(a)' ) ' ' file_name = 'columns.txt' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Examining file: ' // trim ( file_name ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Contents of file:' write ( *, '(a)' ) ' ' call file_print ( file_name ) call file_column_count ( file_name, ncolumn ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' Number of columns in file: ', ncolumn call file_column_range ( file_name, ncolumn, col_min, col_max ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Col Minimum Maximum' write ( *, '(a)' ) ' ' do i = 1, ncolumn write ( *, '(i3,2f10.4)' ) i, col_min(i), col_max(i) end do return end