recursive character function pop_char(unit, eof, skip_ws) result(popped)
integer, intent(in) :: unit
logical, intent(out) :: eof
logical, intent(in), optional :: skip_ws
integer :: ios
character :: c
logical :: ignore
!+PJK
ios = 0
!-PJK
eof = .false.
if (.not.present(skip_ws)) then
ignore = .false.
else
ignore = skip_ws
end if
do
if (pushed_index > 0) then
! there is a character pushed back on, most likely from the number parsing
c = pushed_char(pushed_index:pushed_index)
pushed_index = pushed_index - 1
else
read (unit=unit, fmt="(a)", advance="no", iostat=ios) c
end if
if (ios == end_of_record) then
cycle
else if (ios == end_of_file) then
eof = .true.
exit
else if (iachar(c) <= 31) then ! PJK from 32
! non printing ascii characters
cycle
else if (ignore .and. c == " ") then
cycle
else
popped = c
exit
end if
end do
end function pop_char