def linear_interp(x, coords, at, dim='model_level_number', keep_attrs=True):
    """
    Perform simple linear interpolation to get values at specified
    points.
    
    Arguments:
    
        - x: Data set to interpolate.
        - coords: Coordinate value for each point in x.
        - at: Points at which to interpolate.
        - dim: The dimension along which to interpolate.
        - keep_attrs: Keep attributes?
    
    It is assumed that x[coords] is sorted and does not contain
    duplicate values along the selected dimension.
    """
    
    coords_before = coords.where(coords >= at).min(dim=dim)
    coords_after = coords.where(coords <= at).max(dim=dim)
    assert dim not in coords_before.coords, 'Duplicates detected in coords.'
    assert dim not in coords_after.coords, 'Duplicates detected in coords.'

    x_before = x.where(coords == coords_before).max(dim=dim)
    x_after = x.where(coords == coords_after).max(dim=dim)

    # The interpolated values.
    res = x_before + (x_after - x_before) * ((at - coords_before) /
                                             (coords_after - coords_before))
    
    # When the interpolated x exists already, return it.
    res = x_before.where(x_before == x_after, other=res)

    if keep_attrs:
        res.attrs = x.attrs
    
    return(res)