ESMF_ConfigCreateDefault Function

private function ESMF_ConfigCreateDefault(keywordEnforcer, hconfig, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
type(ESMF_HConfig), intent(in), optional :: hconfig
integer, intent(out), optional :: rc

Return Value type(ESMF_Config)


Source Code

    type(ESMF_Config) function ESMF_ConfigCreateDefault(keywordEnforcer, hconfig, rc)

! !ARGUMENTS:
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      type(ESMF_HConfig), intent(in),  optional   :: hconfig
      integer,            intent(out), optional   :: rc
!
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \item\apiStatusModifiedSinceVersion{5.2.0r}
! \begin{description}
! \item[8.6.0] Added the {\tt hconfig} argument to support creation from HConfig
!    object.
! \end{description}
! \end{itemize}
!
! !DESCRIPTION: 
!   Instantiates an {\tt ESMF\_Config} object. Optionally create from HConfig.
!
!   The arguments are:
!   \begin{description}
!   \item [{[hconfig]}]
!     If specified, create Config from HConfig. By default create an empty
!     Config object.
!   \item [{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP -------------------------------------------------------------------
      integer :: localrc
      integer :: memstat
      type(ESMF_ConfigClass), pointer :: config_local
      type(ESMF_ConfigAttrUsed), dimension(:), pointer :: attr_used_local

      ! Initialize return code; assume routine not implemented
      if (present(rc)) rc = ESMF_RC_NOT_IMPL
 
! Initialization
      allocate(config_local, stat=memstat)
      ESMF_ConfigCreateDefault%cptr => config_local
      if (ESMF_LogFoundAllocError(memstat, msg="Allocating config class", &
                                        ESMF_CONTEXT, rcToReturn=rc)) return

      allocate(config_local%buffer, config_local%this_line, stat = memstat)
      if (ESMF_LogFoundAllocError(memstat, msg="Allocating local buffer 1", &
                                        ESMF_CONTEXT, rcToReturn=rc)) return

      ! TODO: Absoft 8 compiler bug necessitates allocating pointer within
      ! derived type via local pointer first.  Absoft 9/Jazz bug necessitates
      ! this must be a separate allocate statement.
      allocate(attr_used_local(NATT_MAX), stat=memstat)
      if (ESMF_LogFoundAllocError(memstat, msg="Allocating local buffer 2", &
                                        ESMF_CONTEXT, rcToReturn=rc)) return

      config_local%nbuf = 2
      config_local%buffer(1:1) = EOL
      config_local%buffer(2:2) = EOB
      config_local%next_line = 2

      config_local%attr_used => attr_used_local

      if (present(hconfig)) then
        ! Config from HConfig (reference)
        config_local%hconfig_owner = .false.
        config_local%hconfig = hconfig
        call c_ESMC_HConfigToConfig(config_local%hconfig, &
          ESMF_ConfigCreateDefault, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
      else
        ! Config empty
        config_local%hconfig_owner = .true.
        config_local%hconfig = ESMF_HConfigCreate(rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      if (present( rc ))  rc = ESMF_SUCCESS

      ESMF_INIT_SET_CREATED(ESMF_ConfigCreateDefault)
      return

    end function ESMF_ConfigCreateDefault