x_comp_read_geom Subroutine

private subroutine x_comp_read_geom(xdatacfg, xstate, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_HConfig) :: xdatacfg
type(xdata_state), intent(inout), pointer :: xstate
integer, intent(out) :: rc

Source Code

  subroutine x_comp_read_geom(xdatacfg, xstate, rc)
    ! arguments
    type(ESMF_HConfig)                        :: xdatacfg
    type(xdata_state), pointer, intent(inout) :: xstate
    integer, intent(out)                      :: rc
    ! local variables
    logical            :: isPresent
    integer            :: stat
    logical            :: check
    type(ESMF_HConfig) :: geomcfg
    character(len=64)  :: cfgval
    character(:), allocatable :: badKey

    rc = ESMF_SUCCESS

    if (.not. associated(xstate)) then
      call ESMF_LogSetError(ESMF_RC_PTR_NOTALLOC, &
        msg='XDATA: xstate has not been associated', &
        line=__LINE__, file=__FILE__, rcToReturn=rc)
      return
    endif

    ! read geom configuration
    isPresent = ESMF_HConfigIsDefined(xdatacfg, &
      keyString="geom", rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, file=__FILE__)) return
    if (isPresent) then
      ! access geom
      geomcfg = ESMF_HConfigCreateAt(xdatacfg, &
        keyString="geom", rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      check = ESMF_HConfigValidateMapKeys(geomcfg, &
        vocabulary=["nx      ", &
                    "ny      ", &
                    "nz      ", &
                    "coordSys", &
                    "minx    ", &
                    "maxx    ", &
                    "miny    ", &
                    "maxy    "  &
                   ], badKey=badKey, 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=trim(xstate%cname)//": unknown geom option key - "//badKey, &
        line=__LINE__,file=__FILE__, rcToReturn=rc)
        return
      endif
      ! dimensions
      xstate%nx = x_comp_hconfig_i4(geomcfg, "nx", &
        defaultValue=64, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      xstate%ny = x_comp_hconfig_i4(geomcfg, "ny", &
        defaultValue=32, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      xstate%nz = x_comp_hconfig_i4(geomcfg, "nz", &
        defaultValue=4, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      ! coordinate system
      cfgval = x_comp_hconfig_str(geomcfg, "coordSys", &
        defaultValue="ESMF_COORDSYS_SPH_DEG", rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      cfgval = ESMF_UtilStringUpperCase(cfgval, rc=rc)
      select case (cfgval)
        case ("ESMF_COORDSYS_CART")
          xstate%coordSys = ESMF_COORDSYS_CART
        case ("ESMF_COORDSYS_SPH_DEG")
          xstate%coordSys = ESMF_COORDSYS_SPH_DEG
        case ("ESMF_COORDSYS_SPH_RAD")
          xstate%coordSys = ESMF_COORDSYS_SPH_RAD
        case default
          call ESMF_LogSetError(ESMF_RC_ARG_VALUE, &
            msg=trim(xstate%cname)//': invalid value - coordSys', &
            line=__LINE__, file=__FILE__, rcToReturn=rc)
          return
      endselect
      ! coordinates
      xstate%minx = x_comp_hconfig_r8(geomcfg, "minx", &
        defaultValue=-126.0_ESMF_KIND_R8, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      xstate%maxx = x_comp_hconfig_r8(geomcfg, "maxx", &
        defaultValue=-64.0_ESMF_KIND_R8, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      xstate%miny = x_comp_hconfig_r8(geomcfg, "miny", &
        defaultValue=22.0_ESMF_KIND_R8, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      xstate%maxy = x_comp_hconfig_r8(geomcfg, "maxy", &
        defaultValue=50.0_ESMF_KIND_R8, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      call ESMF_HConfigDestroy(geomcfg, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
    endif ! geomcfg

  endsubroutine x_comp_read_geom