def _cmpFrames(x, y):
    """
    Function to compare two frames and sort by stand/beam number (TBN, DRX)
    or by channel number (TBF).
    """
    try:
        idsX = x.parseID()
        idsY = y.parseID()
    except AttributeError:
        idsX = x.header.firstChan
        idsY = y.header.firstChan
    try:
        len1 = len(idsX)
        if len1 == 2:
            sX = 2 * (idsX[0] - 1) + idsX[1]
            sY = 2 * (idsY[0] - 1) + idsY[1]
        else:
            sX = 16777216 * (idsX[0] - 1) + 4096 * (idsX[1] - 1) + idsX[2]
            sY = 16777216 * (idsY[0] - 1) + 4096 * (idsY[1] - 1) + idsY[2]
    except TypeError:
        sX = idsX
        sY = idsY
    if sY > sX:
        return -1
    elif sX > sY:
        return 1
    else:
        return 0
