import re


def parse_header(line, line_num):
    """
    Parses a header line from hurricane data file.
    Documentation on header formats is available in the NOAA HURDAT2 format
    file:

    http://www.nhc.noaa.gov/data/hurdat/hurdat2-format-atlantic.pdf

    The first group indicates the basin, cyclone number within the year, and
    year of the hurricane (or other storm). The next group indicates either the
    hurricane name or "UNNAMED". The final group indicates the number of
    rows to follow that pertain to this record.
    """

    header_row = re.compile(
        '[A-Z]{2}[0-9]{6},\s+\w+,\s+\d+'
        )

    header = header_row.search(line)

    #if this isn't a header line, return None before trying to do regex
    #stuff to None
    if not header:
        return

    return {line[4:8] + line[2:4] + line[18:28].strip(): {
        'indname': (
            line[18:28].strip(), line[:2], int(line[4:8]), int(line[2:4])
        ),
        'nrows': int(line[33:36]),
        'start_line': line_num
    }}