Language:
Fortran-95
Dialect:
Salford Fortran Personal Edition
Discussion:
Reading a text file and writing it to the
screen is trivial in most programming languages. Not so in Fortran,
which was invented to crunch numbers and still doesn't handle strings
very well. But this routine accomplishes that task.
Note: You need to put the whole line in quotes to have Fortran read a line at a time. The routine then strips out the quotes before displaying.
! readAndWrite reads a text file and prints it to the screen. subroutine readAndWrite(fName, maxLin, doUPause) use fCursor use MultiSciGlobals implicit none character*(*), intent(in) :: fName integer, intent(in) :: maxLin logical, intent(in) :: doUPause integer :: i, j character(45) :: text call cls open (unit=inUnit, file='C:\MultiSci\'//fName) do i = 1, maxLin read (inUnit, '(a)', end=10) text do j = 1, 45 if (text(j:j) == '"') then write(text(j:j), '(a1)') ' ' end if end do write (*, '(a)') text end do 10 close (inUnit) if (doUPause) then call uPause end if end subroutine readAndWrite
Page created: | 06/28/2017 |
Last modified: | 06/28/2017 |
Author: | BPL |