def METHOD_NAME(varname):
    ''' Find a variable and its parent object in the registered varlist set, based
        on varname, as passed by the stack.
        Variables can be searched in two ways:
        By name only: e.g., varname lat returns (traf, lat)
        By object: e.g., varname traf.lat returns (traf, lat)
        '''
    try:
        # Find a string matching 'a.b.c[d]', where everything except a is optional
        varset = re.findall(r'(\w+)(?<=.)*(?:\[(\w+)\])?', varname)
        # The actual variable is always the last
        name, index = varset[-1]
        # is a parent object passed? (e.g., traf.lat instead of just lat)
        if len(varset) > 1:
            obj = None
            # The first object should be in the varlist of Plot
            # As either a top-level object:
            if varset[0][0] in varlist:
                obj = varlist.get(varset[0][0])[0]
            else:
                for objname, objset in varlist.items():
                    if varset[0][0] in objset[1]:
                        obj = getattr(objset[0], varset[0][0])
            # Iterate over objectname,index pairs in varset
            for pair in varset[1:-1]:
                if obj is None:
                    break
                obj = getattr(obj, pair[0], None)
            if obj and hasattr(obj, name):
                return Variable(obj, varset[-2][0], name, index)
        else:
            # A parent object is not passed, we only have a variable name
            # this name should exist in Plot.vlist
            for objname, objset in varlist.items():
                if name in objset[1]:
                    return Variable(objset[0], objname, name, index)
    except:
        pass
    return None