Read a whole line from a formatted unit into a deferred length character variable
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | io |
Formatted IO unit |
||
character(kind=tfc, len=:), | intent(out), | allocatable | :: | string |
Line to read |
|
integer, | intent(out) | :: | stat |
Status of operation |
subroutine read_whole_line(io, string, stat) !> Formatted IO unit integer, intent(in) :: io !> Line to read character(:, tfc), allocatable, intent(out) :: string !> Status of operation integer, intent(out) :: stat integer, parameter :: bufsize = 4096 character(bufsize, tfc) :: buffer, msg integer :: chunk logical :: opened if (io /= -1) then inquire(unit=io, opened=opened) else opened = .false. end if if (opened) then open(unit=io, pad="yes", iostat=stat) else stat = 1 msg = "Unit is not connected" end if string = "" do while (stat == 0) read(io, '(a)', advance='no', iostat=stat, size=chunk) buffer if (stat > 0) exit string = string // buffer(:chunk) end do if (is_iostat_eor(stat)) stat = 0 end subroutine read_whole_line