ESMF_UtilIOUnitFlush Subroutine

public subroutine ESMF_UtilIOUnitFlush(unit, keywordEnforcer, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
integer, intent(out), optional :: rc

Source Code

  subroutine ESMF_UtilIOUnitFlush(unit, keywordEnforcer, rc)
!
! !PARAMETERS:
    integer, intent(in)            :: unit
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    integer, intent(out), optional :: rc
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION:
!   Call the system-dependent routine to force output on a specific
!   Fortran unit number.
!
!     The arguments are:
!     \begin{description}
!     \item[unit]
!       A Fortran I/O unit number.  If the unit is not connected to a file,
!       no flushing occurs.
!     \item[{[rc]}]
!       Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     \end{description}
!EOP
    integer :: localrc
    integer :: localstat
    logical :: connected


    inquire (unit=unit, opened=connected)
    if (.not. connected) then
      if (present (rc)) then
        rc = ESMF_SUCCESS
      end if
      return
    end if


!   By default, use the F2003 FLUSH statement.  For older compilers,
!   use a macro defined in the configuration-specific ESMF_Conf.inc
!   include file.  This is needed because the name of the flush routine
!   and exact number of its arguements vary between implementations.

#if !defined (ESMF_IOFlushMacro)

    flush (unit, iostat=localstat)

    ! Convert Fortran iostat to ESMF rc

    localrc = merge (ESMF_SUCCESS, ESMF_FAILURE, localstat == 0)

#else
!   Preset localrc in advance, since some library versions of FLUSH do
!   not support a status argument for detecting errors.

    localstat = 0

ESMF_IOFlushMacro(unit, localstat)

    ! Convert status return to ESMF rc

    localrc = merge (ESMF_SUCCESS, ESMF_FAILURE, localstat == 0)

#endif

    if (present(rc)) then
      rc = localrc
    end if

  end subroutine ESMF_UtilIOUnitFlush