ESMF_LogClose Subroutine

public subroutine ESMF_LogClose(log, keywordEnforcer, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Log), intent(inout), optional :: log
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
integer, intent(out), optional :: rc

Source Code

      subroutine ESMF_LogClose(log, keywordEnforcer, rc)
!
! !ARGUMENTS:
      type(ESMF_Log), intent(inout), optional :: log
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:
!      This routine closes the log file(s) associated with {\tt log}.
!      If the log is not explicitly closed, it will be closed by
!      {\tt ESMF\_Finalize}.
!
!      The arguments are:
!      \begin{description}
!
!      \item [{[log]}]
!            An {\tt ESMF\_Log} object.  If not specified, the default log is closed.
!      \item [{[rc]}]
!            Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!      \end{description}
!
!EOP

    integer::rc2,status
    type(ESMF_LogPrivate),pointer     :: alog

    ! Initialize return code; assume routine not implemented
    if (present(rc)) then
      rc=ESMF_FAILURE
    endif

    alog => null ()
    if (present(log)) then
      if (log%logTableIndex > 0) then
         alog => ESMF_LogTable(log%logTableIndex)
      endif
    else
      if (ESMF_LogDefault%logTableIndex > 0) then
        alog => ESMF_LogTable(ESMF_LogDefault%logTableIndex)
      end if
    endif

    ESMF_INIT_CHECK_SET_SHALLOW(ESMF_LogGetInit,ESMF_LogInit,log)

    if(associated (alog)) then
      ESMF_INIT_CHECK_SET_SHALLOW(ESMF_LogPrivateGetInit,ESMF_LogPrivateInit,alog)

      if (alog%logkindflag /= ESMF_LOGKIND_NONE) then
        if (alog%FileIsOpen == ESMF_TRUE) then
          call ESMF_LogFlush(log,rc=rc2)
          CLOSE (UNIT=alog%unitNumber)
          alog%FileIsOpen=ESMF_FALSE
          deallocate (alog%LOG_ENTRY,stat=status)
        endif
      endif

      if (alog%errorMaskCount > 0) then
        deallocate(alog%errorMask)
      endif
      if (associated (alog%logmsgList)) then
        deallocate (alog%logmsgList)
      end if
      if (associated (alog%logmsgAbort)) then
        deallocate (alog%logmsgAbort)
      end if
    endif

    if (present(rc)) then
      rc=ESMF_SUCCESS
    endif

end subroutine ESMF_LogClose