def read_header(lines, i, log):
    """reads the header and stores it as a dictionary"""
    i0 = i
    headers = {}
    line = lines[i]
    while '=' not in line:
        line = line.split('%')[0].strip()
        if line == '':
            i += 1
            line = lines[i]
            continue
        raise RuntimeError('expected a header; found=%r' % line)
    while '=' in line:
        word, value = line.split('=')
        if word == 'NDIME':
            headers['ndim'] = int(value)
        elif word == 'NELEM':
            headers['nelem'] = int(value)
        elif word == 'NZONE':
            headers['nzones'] = int(value)
        elif word == 'IZONE':
            headers['izone'] = int(value)
        elif word == 'NMARK':
            headers['nmark'] = int(value)
        elif word == 'MARKER_TAG':
            headers['marker_tag'] = value.strip()
        elif word == 'MARKER_ELEMS':
            headers['marker_elems'] = int(value)
        elif word == 'NPOIN':
            headers['npoints'] = int(value)
        else:
            raise NotImplementedError('word=%r' % word)
        i += 1
        line = lines[i]
    assert len(headers) > 0, headers
    if i0 == 0 and 'nzones' not in headers and ('izone' in headers or 
        'ndim' in headers):
        headers['nzones'] = 1
    line = lines[i]
    log.debug(str(headers))
    return i, headers
