import re


def get_cmip_file_info(filename):
    """
    From a CMIP6 filename, return the variable name as well as the start and end year
    """

    if filename[-3:] != '.nc':
        return False, False, False

    attrs = filename.split('_')
    var = attrs[0]

    pattern = r'\d{6}-\d{6}'
    match = re.match(pattern, attrs[-1])
    if not match:
        # this variable doesnt have time
        return var, False, False
    
    start = int(attrs[-1][:4])
    end = int(attrs[-1][7:11])

    return var, start, end