def get_cavity_phases(fn):
    """ Given an OPAL input file, extract phi1, phi2, phi3, phi4 (rad) """
    with open (fn, 'r') as f:
        getvars = {'t_offset': None, 
                   'dphi': None, 
                   'phi_correction': None, 
                   'phi0': None, 
                   'phi1': None, 
                   'phi2': None, 
                   'phi3': None, 
                   'phi4': None}
        locals().update(getvars)
        for line in f:
            if not line.startswith("//") and any(line.startswith(v) for v in getvars.keys()):
                varname, varvalue = [l.strip().strip(';') for l in line.split('=')]
                varvalue = eval(varvalue)
                if varname == 'phi_correction':
                    varvalue *= 1e-6  # MHz vs Hz
                locals()[varname] = varvalue
    
    return [locals()['phi%d' % i] for i in range(1, 5)]