read_formatted Subroutine

private subroutine read_formatted(string, unit, iotype, v_list, iostat, iomsg)

Read a character sequence from a connected formatted unit into the string.

Arguments

Type IntentOptional 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

Calls

proc~~read_formatted~~CallsGraph proc~read_formatted read_formatted none~read_line read_line proc~read_formatted->none~read_line proc~unused_dummy_argument unused_dummy_argument proc~read_formatted->proc~unused_dummy_argument

Called by

proc~~read_formatted~~CalledByGraph proc~read_formatted read_formatted interface~read (formatted) read (formatted) interface~read (formatted)->proc~read_formatted

Variables

Type Visibility Attributes Name Initial
character(len=:), private, allocatable :: line

Subroutines

subroutine read_line(unit, line, iostat, iomsg)

Internal routine to read a whole record from a formatted unit

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
character(len=:), intent(out), allocatable :: line
integer, intent(out) :: iostat
character(len=*), intent(inout) :: iomsg

Source Code

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