write_file Subroutine

public subroutine write_file(file, lines, form, iostat, iomsg)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: file

File name.

type(string), intent(in) :: lines(1:)

The lines.

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 a single string stream into file.

Calls

proc~~write_file~~CallsGraph proc~write_file write_file proc~write_lines write_lines proc~write_file->proc~write_lines
Help

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.

integer, public :: unit

Logical unit.


Source Code

  subroutine write_file(file, lines, form, iostat, iomsg)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Write a single string stream into file.
  !<
  !< @note For unformatted read only `access='stream'` is supported with new_line as line terminator.
  !---------------------------------------------------------------------------------------------------------------------------------
  character(len=*), intent(in)              :: file      !< File name.
  type(string),     intent(in)              :: lines(1:) !< The lines.
  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.
  integer                                   :: unit      !< Logical unit.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  iomsg_ = repeat(' ', 99) ; if (present(iomsg)) iomsg_ = iomsg
  form_ = 'FORMATTED' ; if (present(form)) form_ = form ; form_ = form_%upper()
  select case(form_%chars())
  case('FORMATTED')
    open(newunit=unit, file=file, action='WRITE', iomsg=iomsg_, iostat=iostat_, err=10)
  case('UNFORMATTED')
    open(newunit=unit, file=file, action='WRITE', form='UNFORMATTED', access='STREAM', iomsg=iomsg_, iostat=iostat_, err=10)
  endselect
  call write_lines(unit=unit, lines=lines, form=form, iomsg=iomsg_, iostat=iostat_)
  10 close(unit)
  if (present(iostat)) iostat = iostat_
  if (present(iomsg)) iomsg = iomsg_
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine write_file