def read_wien2k_fermi(filename):
    """
    Read the Wien2K .scf file and return the Fermi energy in units of Rydberg
    The Fermi energy is given on lines starting with ":FER  :". The .scf file
    may contain multiple of such lines. We want to keep the last one and 
    extract the Fermi energy from that.
    """
    line       = ""
    line_fermi = ""
    with open(filename,"r") as fp:
        while True:
            line = fp.readline()
            if not line:
                break
            if line.find(":FER  :") > -1:
                line_fermi = line
    data = line_fermi.split("=")
    fermi_energy = float(data[1])
    return fermi_energy