The rest of the updated test program:
! ctd.. subroutine get_next_line (unit, buffer, nc)
!
! detect Tab (replace with 3 spaces)
else if (ic == 9) then ! Horizontal Tab
do i = 1,3
if (num < len(this_line) ) then
c = ' '
num = num+1
this_line(num:num) = c
last_char = ichar (c)
else
write (*,*) 'Buffer_overflow'
exit
end if
end do
!
! Other non-printable character - replace with a ~ ( could be other valid characters ??)
else
write (*,1001) '<',ic,'> non-printable character ignored at ',num
if (num < len(this_line) ) then
c = '~'
num = num+1
this_line(num:num) = c
last_char = ic
else
write (*,*) 'Buffer_overflow'
end if
end if
end if
end do
!
1001 format (a,i2.2,a,i0)
end subroutine get_next_line
! Last change: JDC 26 Feb 2010 6:01 pm
integer*4 iostat, nc, nl, nb, mc
character buffer*132, file_name*132
!
call get_command_argument (1, file_name, nc, iostat)
if (iostat /= 0) then
write (*,*) 'No file provided'
stop
end if
!
open (unit=11, file=file_name, status='old', access='transparent', form='unformatted', iostat=iostat)
if (iostat /= 0) then
write (*,*) 'Unable to open ', trim(file_name)
stop
else
write (*,*) 'Scanning File ', trim(file_name)
end if
!
open (unit=98,file='get_line.log')
write (98,*) 'Scanning File ', trim(file_name)
nl = 0
nb = 0
mc = 0
do
call get_next_line (11, buffer, nc)
if (nc < 0) exit
write (98,'(a)') trim (buffer)
nl = nl+1
if (nc < 1) nb = nb+1
if (nc > mc) mc = nc
end do
write (*,*) nl,' lines recovered'
write (*,*) nb,' blank lines'
write (*,*) mc,' max line length'
end
subroutine get_next_character (unit, c, iostat)
!
integer*4 unit, iostat
character c, MESSAGE*128
INTEGER*2 ERROR_NUMBER
!
read (unit=unit, iostat=iostat) c
!
if (iostat /= 0) then
error_number = iostat
call FORTRAN_ERROR_MESSAGE@ (error_number, MESSAGE)
write (*,*) 'IOSTAT =',iostat, ' ', TRIM (MESSAGE)
end if
end subroutine get_next_character
It has had some and may need more changes!!, but does show most of the anticipated problems solved.