get_delimiter_mode Subroutine

private subroutine get_delimiter_mode(unit, delim, iostat, iomsg)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: unit

The unit for the connection.

character(kind=len=1,CK), intent(out) :: delim

Represents the value of the DELIM mode.

integer, intent(out) :: iostat

IOSTAT error code, non-zero on error.

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

IOMSG explanatory message - only defined if iostat is non-zero.

Description

Get the DELIM changeable connection mode for the given unit.

If the unit is connected to an internal file, then the default value of NONE is always returned.


Variables

TypeVisibility AttributesNameInitial
character(len=10), public :: delim_buffer

Buffer for INQUIRE about DELIM, sized for APOSTROHPE.

character(len=len(iomsg)), public :: local_iomsg

Local variant of iomsg, so it doesn't get inappropriately redefined.


Source Code

  subroutine get_delimiter_mode(unit, delim, iostat, iomsg)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Get the DELIM changeable connection mode for the given unit.
  !<
  !< If the unit is connected to an internal file, then the default value of NONE is always returned.
  !---------------------------------------------------------------------------------------------------------------------------------
  use, intrinsic :: iso_fortran_env, only : iostat_inquire_internal_unit
  !---------------------------------------------------------------------------------------------------------------------------------
  integer,                   intent(in)    :: unit         !< The unit for the connection.
  character(len=1, kind=CK), intent(out)   :: delim        !< Represents the value of the DELIM mode.
  integer,                   intent(out)   :: iostat       !< IOSTAT error code, non-zero on error.
  character(*),              intent(inout) :: iomsg        !< IOMSG explanatory message - only defined if iostat is non-zero.
  character(10)                            :: delim_buffer !< Buffer for INQUIRE about DELIM, sized for APOSTROHPE.
  character(len(iomsg))                    :: local_iomsg  !< Local variant of iomsg, so it doesn't get inappropriately redefined.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  ! get the string representation of the changeable mode
  inquire(unit, delim=delim_buffer, iostat=iostat, iomsg=local_iomsg)
  if (iostat == iostat_inquire_internal_unit) then
    ! no way of determining the DELIM mode for an internal file
    iostat = 0
    delim = ''
    return
  elseif (iostat /= 0) then
    iomsg = local_iomsg
    return
  endif
  ! interpret the DELIM string
  if (delim_buffer == 'QUOTE') then
    delim = '"'
  elseif (delim_buffer == 'APOSTROPHE') then
    delim = ''''
  else
    delim = '"'
  endif
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine get_delimiter_mode