ESMF_ConfigFindLabel Subroutine

public subroutine ESMF_ConfigFindLabel(config, label, keywordEnforcer, isPresent, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
character(len=*), intent(in) :: label
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
logical, intent(out), optional :: isPresent
integer, intent(out), optional :: rc

Source Code

    subroutine ESMF_ConfigFindLabel(config, label, keywordEnforcer, isPresent, rc)

! !ARGUMENTS:
      type(ESMF_Config), intent(inout)           :: config 
      character(len=*),  intent(in)              :: label
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      logical,           intent(out),  optional  :: isPresent
      integer,           intent(out),  optional  :: rc 

!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \item\apiStatusModifiedSinceVersion{5.2.0r}
! \begin{description}
! \item[6.1.0] Added the {\tt isPresent} argument.  Allows detection of
!  end-of-line condition to be separate from the {\tt rc}.
! \end{description}
! \end{itemize}
!
! !DESCRIPTION: Finds the {\tt label} (key) string in the {\tt config} object
!   starting from the beginning of its content.
!
!   Since the search is done by looking for a string, possibly multi-worded,
!   in the whole {\tt Config} object, it is important to use special 
!   conventions to distinguish {\tt labels} from other words. This is done 
!   in the Resource File by using the NASA/DAO convention to finish
!   line labels with a colon (:) and table labels with a double colon (::).
!
!
!   The arguments are:
!   \begin{description}
!   \item [config]
!     Already created {\tt ESMF\_Config} object.
!   \item [label]
!     Identifying label. 
!   \item [{[isPresent]}]
!     Set to {\tt .true.} if the item is found.
!   \item [{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     If the label is not found, and the {\tt isPresent} argument is
!     not present, an error is returned.
!   \end{description}
!
!EOP -------------------------------------------------------------------

      integer :: i, j

      ! Initialize return code; assume routine not implemented
      if (present(rc)) rc = ESMF_RC_NOT_IMPL

      !check variables
      ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)

      if (present (isPresent)) then
        isPresent = .false.
      end if

!     Determine whether label exists
!     ------------------------------    

      i = index_ ( config%cptr%buffer(1:config%cptr%nbuf), EOL//label ) + 1
      if ( i .eq. 1 ) then
         config%cptr%this_line = BLK // EOL
         if (present (isPresent)) then
           if (present (rc)) rc = ESMF_SUCCESS
           return
         end if
         if (ESMF_LogFoundError(ESMF_RC_NOT_FOUND, &
                                msg="label " // trim (label) // " not found", &
                                 ESMF_CONTEXT, rcToReturn=rc)) return
      elseif(i.le.0) then
         if (ESMF_LogFoundError(ESMF_RC_ARG_BAD, &
                                msg="invalid operation with index_", &
                                 ESMF_CONTEXT, rcToReturn=rc)) return
      end if

      if (present (isPresent)) then
        isPresent = .true.
      end if

!     Save current attribute label without colon,
!       to associate with subsequent GetAttribute() or GetChar()
!     -------------------------------------------
       config%cptr%current_attr = label(1:(index_(label, ":") - 1))


!     Extract the line associated with this label
!     -------------------------------------------
      i = i + len ( label )
      j = i + index_(config%cptr%buffer(i:config%cptr%nbuf),EOL) - 2
      config%cptr%this_line = config%cptr%buffer(i:j) // BLK // EOL
      
      config%cptr%next_line = j + 2
      
      config%cptr%value_begin = i

      if ( present (rc )) rc = ESMF_SUCCESS
      
    end subroutine ESMF_ConfigFindLabel