def parse_beam_file_header(fname):
    """
    Parses a Genesis beam file header. 
    
    Helper routine for parse_beam_file
    """
    
    params = {}
    with open(fname) as f:
        i = 0
        for line in f:
            i += 1
            x = line.strip()
            # Skip comments
            if x.startswith('#') or x == '':
                continue
            # parameter 
            
            if x.startswith('?'):
                x = x[1:].strip()
                if '=' in x:
                    a = x.split('=')
                    params[a[0].strip().lower()] = a[1].strip()
                else:
                    # Should be columns
                    col = [a.lower() for a in x.split()]
                    assert col[0] == 'columns', f'Unknown parameter: {x}'
                    params['columns'] = col[1:]
            else:
                #print(x)
                # Finished. 
                params['n_headerlines'] = i-1
                if 'size' in params:
                    params['size'] = int(params['size'])
                return params