write_line Subroutine

private subroutine write_line(self, unit, form, iostat, iomsg)

Arguments

Type IntentOptional AttributesName
class(string), intent(in) :: self

The string.

integer, intent(in) :: unit

Logical unit.

character(len=*), intent(in), optional :: form

Format of unit.

integer, intent(out), optional :: iostat

IO status code.

character(len=*), intent(inout), optional :: iomsg

IO status message.

Description

Write line (record) to a connected unit.


Variables

TypeVisibility AttributesNameInitial
type(string), public :: form_

Format of unit, local variable.

integer, public :: iostat_

IO status code, local variable.

character(len=:), public, allocatable:: iomsg_

IO status message, local variable.


Source Code

  subroutine write_line(self, unit, form, iostat, iomsg)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Write line (record) to a connected unit.
  !<
  !< @note If the connected unit is unformatted a `new_line()` character is added at the end (if necessary) to mark the end of line.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string),    intent(in)              :: self    !< The string.
  integer,          intent(in)              :: unit    !< Logical unit.
  character(len=*), intent(in),    optional :: form    !< Format of unit.
  integer,          intent(out),   optional :: iostat  !< IO status code.
  character(len=*), intent(inout), optional :: iomsg   !< IO status message.
  type(string)                              :: form_   !< Format of unit, local variable.
  integer                                   :: iostat_ !< IO status code, local variable.
  character(len=:), allocatable             :: iomsg_  !< IO status message, local variable.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  iostat_ = 0
  iomsg_ = repeat(' ', 99) ; if (present(iomsg)) iomsg_ = iomsg
  if (allocated(self%raw)) then
    form_ = 'FORMATTED' ; if (present(form)) form_ = form ; form_ = form_%upper()
    select case(form_%chars())
    case('FORMATTED')
      write(unit, "(A)", iostat=iostat_, iomsg=iomsg_) self%raw
    case('UNFORMATTED')
      if (self%end_with(new_line('a'))) then
        write(unit, iostat=iostat_, iomsg=iomsg_) self%raw
      else
        write(unit, iostat=iostat_, iomsg=iomsg_) self%raw//new_line('a')
      endif
    endselect
  endif
  if (present(iostat)) iostat = iostat_
  if (present(iomsg)) iomsg = iomsg_
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine write_line