subroutine ESMF_ConfigGetString(config, value, &
keywordEnforcer, label, default, eolFlag, rc)
! !ARGUMENTS:
type(ESMF_Config), intent(inout) :: config
character(len=*), intent(out) :: value
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
character(len=*), intent(in), optional :: label
character(len=*), intent(in), optional :: default
logical, intent(out), optional :: eolFlag
integer, intent(out), optional :: rc
!
! !DESCRIPTION: Gets a sequence of characters. It will be
! terminated by the first white space.
!
! The arguments are:
! \begin{description}
! \item [config]
! Already created {\tt ESMF\_Config} object.
! \item [value]
! Returned value.
! \item [{[label]}]
! Identifing label.
! \item [{[default]}]
! Default value if {\tt label} is not found in {\tt config} object.
! \item [{[eolFlag]}]
! Returns {\tt .true.} when end of line is encountered.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!EOPI ------------------------------------------------------------------
character(len=1) :: ch
integer :: ib, ie, localrc
logical :: found
! Initialize return code; assume routine not implemented
if (present(rc)) rc = ESMF_RC_NOT_IMPL
localrc = ESMF_SUCCESS
!check variables
ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)
! Default setting
if( present( default ) ) then
value = default
else
value = BLK
endif
if (present (eolFlag)) then
eolFlag = .false.
end if
if (present (default)) then
if (len (value) < len (default)) then
if (ESMF_LogFoundError (ESMF_RC_ARG_BAD, &
msg='default length too long for value string', &
ESMF_CONTEXT, rcToReturn=rc)) return
end if
end if
! Processing
if(present( label )) then
call ESMF_ConfigFindLabel( config, label=label, &
isPresent=found, rc=localrc)
if (ESMF_LogFoundError (localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (.not. found) then
if (present(default)) then
localrc = ESMF_SUCCESS
else
localrc = ESMF_RC_NOT_FOUND
end if
if ( present (rc )) then
rc = localrc
endif
return
endif
endif
call ESMF_Config_trim ( config%cptr%this_line )
ch = config%cptr%this_line(1:1)
if ( ch .eq. '"' .or. ch .eq. "'" ) then
ib = 2
ie = index_ ( config%cptr%this_line(ib:), ch )
else
ib = 1
ie = min(index_(config%cptr%this_line,BLK), &
index_(config%cptr%this_line,EOL)) - 1
end if
if ( ie .lt. ib ) then
value = BLK
if ( present ( default )) then
value = default
endif
if (present (eolFlag)) then
eolFlag = .true.
localrc = ESMF_SUCCESS
else
localrc = ESMF_RC_NOT_FOUND
end if
if ( present (rc )) then
rc = localrc
endif
return
else
! Get the string, and shift the rest of %this_line to
! the left
value = config%cptr%this_line(ib:ie)
config%cptr%this_line = config%cptr%this_line(ie+2:)
if (len (value) >= ie-ib+1) then
localrc = ESMF_SUCCESS
else
localrc = ESMF_RC_ARG_SIZE
end if
end if
if ( present (rc)) then
rc = localrc
endif
end subroutine ESMF_ConfigGetString