x_comp_hconfig_str Function

private function x_comp_hconfig_str(hconfig, key, defaultValue, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_HConfig), intent(in) :: hconfig
character(len=*), intent(in) :: key
character(len=*), intent(in), optional :: defaultValue
integer, intent(out) :: rc

Return Value character(len=:), allocatable


Source Code

  function x_comp_hconfig_str(hconfig, key, defaultValue, rc)
    ! return value
    character(:), allocatable :: x_comp_hconfig_str
    ! arguments
    type(ESMF_HConfig), intent(in)     :: hconfig
    character(*), intent(in)           :: key
    character(*), intent(in), optional :: defaultValue
    integer, intent(out)               :: rc
    ! local variables
    logical :: isPresent
    logical :: check

    rc = ESMF_SUCCESS
    x_comp_hconfig_str = ' '

    isPresent = ESMF_HConfigIsDefined(hconfig, keyString=key, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, file=__FILE__)) return

    if (isPresent) then
      x_comp_hconfig_str = ESMF_HConfigAsString(hconfig, keyString=key, &
        asOkay=check, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      if (.not.check) then
        call ESMF_LogSetError(ESMF_RC_NOT_VALID, &
          msg="XDATA: Value cannot be converted to String - "//trim(key), &
          line=__LINE__, file=__FILE__, rcToReturn=rc)
        return
      endif
    elseif (present(defaultValue)) then
      x_comp_hconfig_str = defaultValue
    else
      call ESMF_LogSetError(ESMF_RC_NOT_FOUND, &
        msg="XDATA: Key not found - "//trim(key), &
        line=__LINE__, file=__FILE__, rcToReturn=rc)
      return
    endif
  endfunction x_comp_hconfig_str