ESMF_LogFoundAllocError Function

public function ESMF_LogFoundAllocError(statusToCheck, keywordEnforcer, msg, line, file, method, rcToReturn, log)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: statusToCheck
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
character(len=*), intent(in), optional :: msg
integer, intent(in), optional :: line
character(len=*), intent(in), optional :: file
character(len=*), intent(in), optional :: method
integer, intent(inout), optional :: rcToReturn
type(ESMF_Log), intent(inout), optional :: log

Return Value logical


Source Code

      function ESMF_LogFoundAllocError(statusToCheck, keywordEnforcer,  &
                                       msg,line,file, &
                                       method,rcToReturn,log)
!
! !RETURN VALUE:
      logical                                    :: ESMF_LogFoundAllocError
!
! !ARGUMENTS:
!
      integer,          intent(in)              :: statusToCheck
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      character(len=*), intent(in),    optional :: msg
      integer,          intent(in),    optional :: line
      character(len=*), intent(in),    optional :: file
      character(len=*), intent(in),    optional :: method
      integer,          intent(inout), optional :: rcToReturn
      type(ESMF_Log),   intent(inout), optional :: log

!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION:
!      This function returns {\tt .true.} when {\tt statusToCheck} indicates
!      an allocation error, otherwise it returns {\tt .false.}.  The status
!      value is typically returned from a Fortran ALLOCATE statement.
!      If an error is indicated, a ESMF memory allocation error message
!      will be written to the {\tt ESMF\_Log} along with a user added {\tt msg},
!      {\tt line}, {\tt file} and {\tt method}.
!
!      The arguments are:
!      \begin{description}
!
!      \item [statusToCheck]
!            Fortran allocation status to check.  Fortran specifies
!            that a status of 0 (zero) indicates success.
!      \item [{[msg]}]
!            User-provided message string.
!      \item [{[line]}]
!            Integer source line number.  Expected to be set by
!            using the preprocessor {\tt \_\_LINE\_\_} macro.
!      \item [{[file]}]
!            User-provided source file name.
!      \item [{[method]}]
!            User-provided method string.
!      \item [{[rcToReturn]}]
!            If specified, when the allocation status indicates an error,
!            set the {\tt rcToReturn} value to {\tt ESMF\_RC\_MEM}.  Otherwise,
!            {\tt rcToReturn} is not modified.
!      \item [{[log]}]
!            An optional {\tt ESMF\_Log} object that can be used instead
!            of the default Log.
!
!      \end{description}
!
!EOP
    character(len=ESMF_MAXSTR)::allocmsg
    integer::msglen
    type(ESMF_LogPrivate), pointer  :: alog

    ESMF_INIT_CHECK_SET_SHALLOW(ESMF_LogGetInit,ESMF_LogInit,log)
    ESMF_LogFoundAllocError=.FALSE.

    nullify(alog) ! ensure that the association status is well defined

    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

    if (alog%traceFlag) then
      call ESMF_LogWrite ('called: ' // ESMF_METHOD, ESMF_LOGMSG_TRACE,  &
        line=line, file=file, method=method, log=log)
    end if

!   The Fortran Standard requires that a successful allocate return a stat value
!   of 0.  Any other value indicates a processor-defined error.
    if (statusToCheck .NE. 0) then
        call ESMF_Breakpoint()  ! no-op to assist debugging
        call ESMF_LogRc2Msg (ESMF_RC_MEM_ALLOCATE, allocmsg, msglen)
        if (present(rcToReturn)) then
            rcToReturn=ESMF_RC_MEM_ALLOCATE
        endif
        if (present(msg)) then
          allocmsg = allocmsg(:msglen) // " - " // msg // ' (status = '
          write (allocmsg,'(a,i5,a)') trim (allocmsg), statusToCheck, ')'
          msglen = len_trim (allocmsg)
        end if
        call ESMF_LogWrite(allocmsg(:msglen), ESMF_LOGMSG_ERROR,  &
            line=line, file=file, method=method, log=log)
        ESMF_LogFoundAllocError=.TRUE.
    endif

end function ESMF_LogFoundAllocError