import re


def parse_file_date(fname):
    """
    Extract the date from a CESM history file filename. Fails if unable to extract
    the date from the filename.
    
    Params
    -------
    fname : str
        CESM history filename
    
    Return
    -------
    str
        Date corresponding to the CESM history file in the format YYYYMM
    """
    pattern = r'\.(\d{4}-\d{2})\.nc'
    match = re.search(pattern, fname)
    if (match):
        ret_val = match.group(1)
    else:
        raise ValueError('Unable to extract date from CESM history filename: {}'.format(fname))
    return ret_val