Read a character sequence from a connected formatted unit into the string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(string_type), | intent(inout) | :: | string | |||
| integer, | intent(in) | :: | unit | |||
| character(len=*), | intent(in) | :: | iotype | |||
| integer, | intent(in) | :: | v_list(:) | |||
| integer, | intent(out) | :: | iostat | |||
| character(len=*), | intent(inout) | :: | iomsg |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=:), | private, | allocatable | :: | line |
Internal routine to read a whole record from a formatted unit
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit | |||
| character(len=:), | intent(out), | allocatable | :: | line | ||
| integer, | intent(out) | :: | iostat | |||
| character(len=*), | intent(inout) | :: | iomsg |
subroutine read_formatted(string, unit, iotype, v_list, iostat, iomsg) type(string_type), intent(inout) :: string integer, intent(in) :: unit character(len=*), intent(in) :: iotype integer, intent(in) :: v_list(:) integer, intent(out) :: iostat character(len=*), intent(inout) :: iomsg character(len=:), allocatable :: line call unused_dummy_argument(v_list) select case (iotype) case ("LISTDIRECTED") call read_line(unit, line, iostat, iomsg) case ("NAMELIST") error stop "[Fatal] This implementation does not support namelist input" case default ! DT* error stop "[Fatal] This implementation does not support dt formatters" end select string%raw = line contains !> Internal routine to read a whole record from a formatted unit subroutine read_line(unit, line, iostat, iomsg) integer, intent(in) :: unit character(len=:), allocatable, intent(out) :: line integer, intent(out) :: iostat character(len=*), intent(inout) :: iomsg integer, parameter :: buffer_size = 512 character(len=buffer_size) :: buffer integer :: chunk line = '' do read (unit, '(a)', iostat=iostat, iomsg=iomsg, size=chunk, advance='no') & buffer if (iostat > 0) exit line = line//buffer(:chunk) if (iostat < 0) exit end do if (is_iostat_eor(iostat)) then iostat = 0 end if end subroutine read_line end subroutine read_formatted