ESMF_ConfigLoadFile Subroutine

public subroutine ESMF_ConfigLoadFile(config, filename, keywordEnforcer, delayout, unique, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
character(len=*), intent(in) :: filename
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
type(ESMF_DELayout), intent(in), optional :: delayout
logical, intent(in), optional :: unique
integer, intent(out), optional :: rc

Source Code

    subroutine ESMF_ConfigLoadFile(config, filename, &
      keywordEnforcer, delayout, & ! DEPRECATED ARGUMENT
      unique, rc)

! !ARGUMENTS:
      type(ESMF_Config),   intent(inout)         :: config
      character(len=*),    intent(in)            :: filename
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      type(ESMF_DELayout), intent(in),  optional :: delayout  ! DEPRECATED ARGUMENT
      logical,             intent(in),  optional :: unique
      integer,             intent(out), optional :: rc
!
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \item\apiStatusModifiedSinceVersion{5.2.0r}
! \begin{description}
! \item[8.5.0] Added support for loading basic YAML files.\newline
!    Marked argument {\tt delayout} as deprecated. This argument was
!    never used internally, and it is unclear what the original intention was.
! \end{description}
! \end{itemize}
!
! !DESCRIPTION: 
!  The resource file named {\tt filename} is loaded into memory. Both the
!  classic Config file format, described in this document, and the YAML file
!  format are supported. YAML support is limited to a small subset of the full
!  YAML language specification, allowing access through the classic Config API.
!  Specifically, in YAML mode, the top level is expected to be a mapping
!  (dictionary) of scalar keys to the following value options:
!  \begin{itemize}
!  \item Scalars
!  \item List of scalars
!  \item List of lists of scalars
!  \end{itemize}
!  All other YAML constructs are silently ignored when loaded through this
!  interface. Constructs successfully ingested become available in the
!  {\tt config} object, and can be accessed via the regular {\tt ESMF\_Config}
!  methods.
!
!   The arguments are:
!   \begin{description}
!   \item [config]
!     Already created {\tt ESMF\_Config} object.
!   \item [filename]
!     Name of the configuration file. Files ending in {\tt .yaml}, {\tt .yml},
!     or any combination of upper and lower case letters that can be mapped
!     to these two options, are interpreted as YAML files. All other names
!     are interpreted as classic Config files.
!   \item [{[delayout]}] ! DEPRECATED ARGUMENT
!     {\tt ESMF\_DELayout} associated with this {\tt config} object.
!     This argument is not currently used.
!   \item [{[unique]}]
!     If specified as true, uniqueness of labels are checked and 
!     error code set if duplicates found.
!   \item [{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP -------------------------------------------------------------------

      integer :: localrc
      character(len=len(filename))  :: lower_filename
      character(len=*), parameter   :: dotYaml=".yaml"
      character(len=*), parameter   :: dotYml=".yml"

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

      !check variables
      ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)

      lower_filename = ESMF_UtilStringLowerCase(trim(filename), rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

      if ((lower_filename(len(lower_filename)-len(dotYaml)+1:)==dotYaml) &
        .or. (lower_filename(len(lower_filename)-len(dotYml)+1:)==dotYml)) &
        then
        ! This is a YAML file

        call ESMF_HConfigFileLoad(config%cptr%hconfig, trim(filename), &
          rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return

        ! construct a regular Config from HConfig to the level possible
        call c_ESMC_HConfigToConfig(config%cptr%hconfig, config, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
      else
        ! Assume this is an old Config resource file

        call ESMF_ConfigLoadFile_1proc_( config, filename, localrc )
        if (ESMF_LogFoundError(localrc, &
          msg="unable to load file: " // trim (filename), &
          ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      call ESMF_ConfigParseAttributes( config, unique, localrc )
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

      if ( present (delayout) ) then
       call ESMF_LogWrite("DELayout not used yet", ESMF_LOGMSG_WARNING, &
                           ESMF_CONTEXT)
      endif

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

    end subroutine ESMF_ConfigLoadFile