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, nb, 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
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
value = default
else
value = BLK
endif
if (present (eolFlag)) then
eolFlag = .false.
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
ib = config%cptr%next_item
ie = config%cptr%next_line-2
if ( config%cptr%eolflag ) then
! reached end of line
config%cptr%next_item = config%cptr%next_line-1
if ( present ( default )) then
value = default
else
value = BLK
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
nb = verify(config%cptr%buffer(ib:ie),BLK//TAB)
if (nb .eq. 0) then
! remainder of line is blank
value = BLK
config%cptr%eolflag = .true.
config%cptr%next_item = config%cptr%next_line-1
if (present (eolFlag)) then
eolFlag = .true.
end if
localrc = ESMF_SUCCESS
else
! shift to first non blank
ib = ib + nb - 1
ch = config%cptr%buffer(ib:ib)
if ( ch .eq. '"' .or. ch .eq. "'" ) then
! quotation separated list
ib = ib + 1
ie = index_(config%cptr%buffer(ib:ie),ch)
if (ie .eq. 0) then
! missing end quotation
ib = ib - 1
ie = config%cptr%next_line - 2
config%cptr%eolflag = .true.
config%cptr%next_item = config%cptr%next_line-1
else
ie = ib + ie - 2
config%cptr%next_item = ie + 2
nb = verify(config%cptr%buffer(config%cptr%next_item:config%cptr%next_line-2),BLK//TAB)
if (nb .eq. 0) config%cptr%eolflag = .true.
end if
else
! blank separated list
ie = index_(config%cptr%buffer(ib:ie),BLK)
if (ie .eq. 0) then
! last item
ie = config%cptr%next_line - 2
config%cptr%eolflag = .true.
config%cptr%next_item = config%cptr%next_line-1
else
ie = ib + ie - 2
config%cptr%next_item = ie + 2
nb = verify(config%cptr%buffer(config%cptr%next_item:config%cptr%next_line-2),BLK//TAB)
if (nb .eq. 0) config%cptr%eolflag = .true.
end if
end if
value = config%cptr%buffer(ib:ie)
! error if value truncated
if (len (value) >= ie-ib+1) then
localrc = ESMF_SUCCESS
else
localrc = ESMF_RC_ARG_SIZE
end if
end if
end if
if ( present (rc)) then
rc = localrc
endif
end subroutine ESMF_ConfigGetString