code: def _read_coil_def_file(fname, use_registry=True):
      """Read a coil def file."""
      if not use_registry or fname not in _coil_registry:
          big_val = 0.5
          coils = list()
          with open(fname) as fid:
              lines = fid.readlines()
          lines = lines[::-1]
          while len(lines) > 0:
              line = lines.pop().strip()
              if line[0] == "#" and len(line) > 0:
                  continue
              desc_start = line.find('"')
              desc_end = len(line) - 1
              assert line.strip()[desc_end] == '"'
              desc = line[desc_start:desc_end]
              vals = np.fromstring(
                  line[:desc_start].strip(), dtype=float, sep=" "
              )
              assert len(vals) == 6
              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],
              )
              # get parameters of each component
              rmag = list()
              cosmag = list()
              w = list()
              for p in range(npts):
                  # get next non-comment line
                  line = lines.pop()
                  while line[0] == "#":
                      line = lines.pop()
                  vals = np.fromstring(line, sep=" ")
                  if len(vals) != 7:
                      raise RuntimeError(
                          f"Could not interpret line {p + 1} as 7 points:\n"
                          f"{line}"
                      )
                  # Read and verify data for each integration point
                  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)
          if use_registry:
              _coil_registry[fname] = coils
      if use_registry:
          coils = deepcopy(_coil_registry[fname])
      logger.info("%d coil definition%s read", len(coils), _pl(coils))
      return coils
  
imports: import os
  import os.path
  from contextlib import contextmanager
  from copy import deepcopy
  from pathlib import Path
  import numpy
  from .._fiff.compensator import get_current_comp, make_compensator
  from .._fiff.constants import FIFF, FWD
  from .._fiff.meas_info import Info, read_info
  from .._fiff.pick import _has_kit_refs, pick_info, pick_types
  from .._fiff.tag import _loc_to_coil_trans, _loc_to_eeg_loc
  from ..bem import ConductorModel, _bem_find_surface, read_bem_solution
  from ..source_estimate import VolSourceEstimate
  from ..source_space._source_space import _complete_vol_src, _ensure_src, _filter_source_spaces, _make_discrete_source_space
  from ..surface import _CheckInside, _normalize_vectors
  from ..transforms import Transform, _coord_frame_name, _ensure_trans, _get_trans, _print_coord_trans, apply_trans, invert_transform, transform_surface_to
  from ..utils import _check_fname, _pl, _validate_type, logger, verbose, warn
  from ._compute_forward import _compute_forwards
  from .forward import _FWD_ORDER, Forward, _merge_fwds, convert_forward_solution
label_desc: Use image node_id 2 for calling a global function with example usage: _read_coil_def_file(fname, use_registry) and returns: coils