def sort(l, cmp):
    """Sort the list l (in place) according to the comparison function
    cmp.  The comparison function, cmp(x, y), should return something
    less than 0 when x < y, 0 when x == y, something greater than 0 when
    x > y.  The sort is ascending in the following sense:  For the sorted
    list: When i < j, cmp(l[i], l[j]) <= 0.

    This sort is not stable.  In fact it is a deliberate emulation of
    the O(n**2) sort implemented in the SORT subroutine of
    to.SBBXgrid.f.  This is necessary to achieve results that are as
    close as possible to the GISS code.  We should switch to using
    Python's built-in sort routine.
    """
    for n in range(len(l) - 1):
        nlmax = n
        for nn in range(n + 1, len(l)):
            if cmp(l[nn], l[nlmax]) < 0:
                nlmax = nn
        t = l[nlmax]
        l[nlmax] = l[n]
        l[n] = t
    return
