ESMF_HConfigCreateDefault Function

private function ESMF_HConfigCreateDefault(keywordEnforcer, content, filename, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
character(len=*), intent(in), optional :: content
character(len=*), intent(in), optional :: filename
integer, intent(out), optional :: rc

Return Value type(ESMF_HConfig)


Source Code

  function ESMF_HConfigCreateDefault(keywordEnforcer, content, filename, rc)
!
! !RETURN VALUE:
    type(ESMF_HConfig) :: ESMF_HConfigCreateDefault
!
! !ARGUMENTS:
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
    character(len=*),   intent(in),  optional :: content
    character(len=*),   intent(in),  optional :: filename
    integer,            intent(out), optional :: rc
!
! !DESCRIPTION:
!   Create a new HConfig object. The object is empty unless either the
!   {\tt content} or {\tt filename} argument is specified.
!
!   The arguments are:
!   \begin{description}
!   \item[{[content]}]
!     String containing the YAML text. Mutually exclusive with
!     {\tt filename} argument.
!   \item[{[filename]}]
!     Name of the YAML file to be loaded. Mutually exclusive with
!     {\tt content} argument.
!   \item[{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP
!------------------------------------------------------------------------------
    integer               :: localrc        ! local return code
    type(ESMF_HConfig)    :: hconfig        ! opaque pointer to new C++ HConfig

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

    ! invalidate return value
    hconfig%shallowMemory = 0
    ESMF_HConfigCreateDefault = hconfig

    if (present(content) .and. present(filename)) then
      call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
        msg="The 'content' and 'filename' arguments are mutual exclusive", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif

    ! call into the C++ interface, which will sort out optional arguments
    call c_ESMC_HConfigCreate(hconfig, localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Set return value
    ESMF_HConfigCreateDefault = hconfig

    ! Set init code
    ESMF_INIT_SET_CREATED(ESMF_HConfigCreateDefault)

    ! handle content and filename
    if (present(content)) then
      ! load content
      call ESMF_HConfigLoad(ESMF_HConfigCreateDefault, content=content, &
        rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    else if (present(filename)) then
      ! load filename
      call ESMF_HConfigFileLoad(ESMF_HConfigCreateDefault, filename=filename, &
        rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    ! return successfully
    if (present(rc)) rc = ESMF_SUCCESS

  end function ESMF_HConfigCreateDefault