def lat_to_yindex(lat, res=1):
    """
    For a given latitude return the y index in a 1x1x5-day global grid
    
    :param lat: Latitude of the point
    :param res: resolution of the grid
    :type lat: float
    :type res: float
    :return: grid box index
    :rtype: integer
    
    The routine assumes that the structure of the SST array is a grid that is 360 x 180 x 73 
    i.e. one year of 1degree lat x 1degree lon data split up into pentads. The west-most box is at 180degrees with
    index 0 and the northern most box also has index zero. Inputs on the border between grid cells are pushed south.
    """
    if res == 1:
        yindex = int(90 - lat)
        if yindex >= 180:
            yindex = 179
        if yindex < 0:
            yindex = 0
        return yindex
    else:
        yindex = int((90 - lat) / res)
        if yindex >= 180 / res:
            yindex = int(180 / res - 1)
        if yindex < 0:
            yindex = 0
        return yindex