human
Complete this python program:
def _read_coil_def_file(fname):
assistant
#Here is the Python code you requested.

    """Read a coil def file.
    """
    if (fname not in _coil_register):
        big_val = 0.5
        coils = list()
        with open(fname, 'r') as fid:
            lines = fid.readlines()
        lines = lines[::(-1)]
        while (len(lines) > 0):
            line = lines.pop()
            if (line[0] != '#'):
                vals = np.fromstring(line, sep='    ')
                assert (len(vals) in (6, 7))
                start = line.find('"')
                end = (len(line.strip()) - 1)
                assert (line.strip()[end] == '"')
                desc = line[start:end]
                npts = int(vals[3])
                coil = dict(coil_type=vals[1], coil_class=vals[0], desc=desc, accuracy=vals[2], size=vals[4], base=vals[5])
                rmag = list()
                cosmag = list()
                w = list()
                for p in range(npts):
                    line = lines.pop()
                    while (line[0] == '#'):
                        line = lines.pop()
                    vals = np.fromstring(line, sep='    ')
                    assert (len(vals) == 7)
                    w.append(vals[0])
                    rmag.append(vals[[1, 2, 3]])
                    cosmag.append(vals[[4, 5, 6]])
                w = np.array(w)
                rmag = np.array(rmag)
                cosmag = np.array(cosmag)
                size = np.sqrt(np.sum((cosmag ** 2), axis=1))
                if np.any((np.sqrt(np.sum((rmag ** 2), axis=1)) > big_val)):
                    raise RuntimeError('Unreasonable    integration    point')
                if np.any((size <= 0)):
                    raise RuntimeError('Unreasonable    normal')
                cosmag /= size[:, np.newaxis]
                coil.update(dict(w=w, cosmag=cosmag, rmag=rmag))
                coils.append(coil)
        _coil_register[fname] = coils
    coils = deepcopy(_coil_register[fname])
    logger.info('%d    coil    definitions    read', len(coils))
    return coils