def parse_AHF_file(filename, pars, sep=None):
    """
    Parse an AHF log or parameter file.
    """
    npars = len(pars.keys())
    vals = {}
    f = open(filename, 'r')
    for line in f.readlines():
        line = line.strip()
        if line is None:
            break
        if len(vals.keys()) == npars:
            break
        for par in pars:
            key = pars[par]
            if key in vals:
                continue
            if line.startswith('%s ' % par):
                val = float(line.split(sep)[1])
                vals[key] = val
    f.close()
    if len(vals) < npars:
        raise RuntimeError('%s missing these parameters: %s.' % (filename,
            ', '.join(set(pars.values()).difference(vals))))
    return vals
