ESMF_ConfigFindNextLabel Subroutine

public subroutine ESMF_ConfigFindNextLabel(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_ConfigFindNextLabel(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

!
! !DESCRIPTION: Finds the {\tt label} (key) string in the {\tt config} object,
!   starting from the current position pointer.
!
!   This method is equivalent to {\tt ESMF\_ConfigFindLabel}, but the search
!   is performed starting from the current position pointer.
!
!   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, ptr

      ! 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 from current position onward
!     -----------------------------------------------------------
      ptr = max(config%cptr%next_line-1, 1)
      i = index_ ( config%cptr%buffer(ptr: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 ) + ptr - 1
      j = i + index_ ( config%cptr%buffer(i:config%cptr%nbuf),EOL ) - 2
      config%cptr%this_line = config%cptr%buffer(ptr:j) // BLK // EOL

      config%cptr%next_line = j + 2

      config%cptr%value_begin = i

      if ( present (rc )) rc = ESMF_SUCCESS

    end subroutine ESMF_ConfigFindNextLabel