code: def _read_config(fname):
      """Read BTi system config file.
  
      Parameters
      ----------
      fname : str
          The absolute path to the config file
  
      Returns
      -------
      cfg : dict
          The config blocks found.
      """
      with _bti_open(fname, "rb") as fid:
          cfg = dict()
          cfg["hdr"] = {
              "version": read_int16(fid),
              "site_name": read_str(fid, 32),
              "dap_hostname": read_str(fid, 16),
              "sys_type": read_int16(fid),
              "sys_options": read_int32(fid),
              "supply_freq": read_int16(fid),
              "total_chans": read_int16(fid),
              "system_fixed_gain": read_float(fid),
              "volts_per_bit": read_float(fid),
              "total_sensors": read_int16(fid),
              "total_user_blocks": read_int16(fid),
              "next_der_chan_no": read_int16(fid),
          }
  
          fid.seek(2, 1)
  
          cfg["checksum"] = read_uint32(fid)
          cfg["reserved"] = read_char(fid, 32)
          cfg["transforms"] = [
              read_transform(fid)
              for t in range(cfg["hdr"]["total_sensors"])
          ]
  
          cfg["user_blocks"] = dict()
          for block in range(cfg["hdr"]["total_user_blocks"]):
              ub = dict()
  
              ub["hdr"] = {
                  "nbytes": read_uint32(fid),
                  "kind": read_str(fid, 20),
                  "checksum": read_int32(fid),
                  "username": read_str(fid, 32),
                  "timestamp": read_uint32(fid),
                  "user_space_size": read_uint32(fid),
                  "reserved": read_char(fid, 32),
              }
  
              _correct_offset(fid)
              start_bytes = fid.tell()
              kind = ub["hdr"].pop("kind")
              if (
                  not kind
              ):  # make sure reading goes right. Should never be empty
                  raise RuntimeError(
                      "Could not read user block. Probably you "
                      "acquired data using a BTi version "
                      "currently not supported. Please contact "
                      "the mne-python developers."
                  )
              dta, cfg["user_blocks"][kind] = dict(), ub
              if kind in [
                  v for k, v in BTI.items() if k[:5] == "UB_B_"
              ]:
                  if kind == BTI.UB_B_MAG_INFO:
                      dta["version"] = read_int32(fid)
                      fid.seek(20, 1)
                      dta["headers"] = list()
                      for hdr in range(6):
                          d = {
                              "name": read_str(fid, 16),
                              "transform": read_transform(fid),
                              "units_per_bit": read_float(fid),
                          }
                          dta["headers"] += [d]
                          fid.seek(20, 1)
  
                  elif kind == BTI.UB_B_COH_POINTS:
                      dta["n_points"] = read_int32(fid)
                      dta["status"] = read_int32(fid)
                      dta["points"] = []
                      for pnt in range(16):
                          d = {
                              "pos": read_double_matrix(fid, 1, 3),
                              "direction": read_double_matrix(
                                  fid, 1, 3
                              ),
                              "error": read_double(fid),
                          }
                          dta["points"] += [d]
  
                  elif kind == BTI.UB_B_CCP_XFM_BLOCK:
                      dta["method"] = read_int32(fid)
                      # handle difference btw/ linux (0) and solaris (4)
                      size = (
                          0
                          if ub["hdr"]["user_space_size"] == 132
                          else 4
                      )
                      fid.seek(size, 1)
                      dta["transform"] = read_transform(fid)
  
                  elif kind == BTI.UB_B_EEG_LOCS:
                      dta["electrodes"] = []
                      while True:
                          d = {
                              "label": read_str(fid, 16),
                              "location": read_double_matrix(fid, 1, 3),
                          }
                          if not d["label"]:
                              break
                          dta["electrodes"] += [d]
  
                  elif kind in [
                      BTI.UB_B_WHC_CHAN_MAP_VER,
                      BTI.UB_B_WHS_SUBSYS_VER,
                  ]:
                      dta["version"] = read_int16(fid)
                      dta["struct_size"] = read_int16(fid)
                      dta["entries"] = read_int16(fid)
  
                      fid.seek(8, 1)
  
                  elif kind == BTI.UB_B_WHC_CHAN_MAP:
                      num_channels = None
                      for name, data in cfg["user_blocks"].items():
                          if name == BTI.UB_B_WHC_CHAN_MAP_VER:
                              num_channels = data["entries"]
                              break
  
                      if num_channels is None:
                          raise ValueError(
                              "Cannot find block %s to determine "
                              "number of channels"
                              % BTI.UB_B_WHC_CHAN_MAP_VER
                          )
  
                      dta["channels"] = list()
                      for i in range(num_channels):
                          d = {
                              "subsys_type": read_int16(fid),
                              "subsys_num": read_int16(fid),
                              "card_num": read_int16(fid),
                              "chan_num": read_int16(fid),
                              "recdspnum": read_int16(fid),
                          }
                          dta["channels"] += [d]
                          fid.seek(8, 1)
  
                  elif kind == BTI.UB_B_WHS_SUBSYS:
                      num_subsys = None
                      for name, data in cfg["user_blocks"].items():
                          if name == BTI.UB_B_WHS_SUBSYS_VER:
                              num_subsys = data["entries"]
                              break
  
                      if num_subsys is None:
                          raise ValueError(
                              "Cannot find block %s to determine"
                              " number of subsystems"
                              % BTI.UB_B_WHS_SUBSYS_VER
                          )
  
                      dta["subsys"] = list()
                      for sub_key in range(num_subsys):
                          d = {
                              "subsys_type": read_int16(fid),
                              "subsys_num": read_int16(fid),
                              "cards_per_sys": read_int16(fid),
                              "channels_per_card": read_int16(fid),
                              "card_version": read_int16(fid),
                          }
  
                          fid.seek(2, 1)
  
                          d.update(
                              {
                                  "offsetdacgain": read_float(fid),
                                  "squid_type": read_int32(fid),
                                  "timesliceoffset": read_int16(fid),
                                  "padding": read_int16(fid),
                                  "volts_per_bit": read_float(fid),
                              }
                          )
  
                          dta["subsys"] += [d]
  
                  elif kind == BTI.UB_B_CH_LABELS:
                      dta["version"] = read_int32(fid)
                      dta["entries"] = read_int32(fid)
                      fid.seek(16, 1)
  
                      dta["labels"] = list()
                      for label in range(dta["entries"]):
                          dta["labels"] += [read_str(fid, 16)]
  
                  elif kind == BTI.UB_B_CALIBRATION:
                      dta["sensor_no"] = read_int16(fid)
                      fid.seek(2, 1)
                      dta["timestamp"] = read_int32(fid)
                      dta["logdir"] = read_str(fid, 256)
  
                  elif kind == BTI.UB_B_SYS_CONFIG_TIME:
                      # handle difference btw/ linux (256) and solaris (512)
                      size = (
                          256
                          if ub["hdr"]["user_space_size"] == 260
                          else 512
                      )
                      dta["sysconfig_name"] = read_str(fid, size)
                      dta["timestamp"] = read_int32(fid)
  
                  elif kind == BTI.UB_B_DELTA_ENABLED:
                      dta["delta_enabled"] = read_int16(fid)
  
                  elif kind in [
                      BTI.UB_B_E_TABLE_USED,
                      BTI.UB_B_E_TABLE,
                  ]:
                      dta["hdr"] = {
                          "version": read_int32(fid),
                          "entry_size": read_int32(fid),
                          "n_entries": read_int32(fid),
                          "filtername": read_str(fid, 16),
                          "n_e_values": read_int32(fid),
                          "reserved": read_str(fid, 28),
                      }
  
                      if dta["hdr"]["version"] == 2:
                          size = 16
                          dta["ch_names"] = [
                              read_str(fid, size)
                              for ch in range(dta["hdr"]["n_entries"])
                          ]
                          dta["e_ch_names"] = [
                              read_str(fid, size)
                              for ch in range(dta["hdr"]["n_e_values"])
                          ]
  
                          rows = dta["hdr"]["n_entries"]
                          cols = dta["hdr"]["n_e_values"]
                          dta["etable"] = read_float_matrix(
                              fid, rows, cols
                          )
                      else:  # handle MAGNES2500 naming scheme
                          dta["ch_names"] = ["WH2500"] * dta["hdr"][
                              "n_e_values"
                          ]
                          dta["hdr"]["n_e_values"] = 6
                          dta["e_ch_names"] = BTI_WH2500_REF_MAG
                          rows = dta["hdr"]["n_entries"]
                          cols = dta["hdr"]["n_e_values"]
                          dta["etable"] = read_float_matrix(
                              fid, rows, cols
                          )
  
                  elif any(
                      [
                          kind == BTI.UB_B_WEIGHTS_USED,
                          kind[:4] == BTI.UB_B_WEIGHT_TABLE,
                      ]
                  ):
                      dta["hdr"] = dict(
                          version=read_int32(fid),
                          n_bytes=read_uint32(fid),
                          n_entries=read_uint32(fid),
                          name=read_str(fid, 32),
                      )
                      if dta["hdr"]["version"] == 2:
                          dta["hdr"].update(
                              description=read_str(fid, 80),
                              n_anlg=read_uint32(fid),
                              n_dsp=read_uint32(fid),
                              reserved=read_str(fid, 72),
                          )
                          dta["ch_names"] = [
                              read_str(fid, 16)
                              for ch in range(dta["hdr"]["n_entries"])
                          ]
                          dta["anlg_ch_names"] = [
                              read_str(fid, 16)
                              for ch in range(dta["hdr"]["n_anlg"])
                          ]
  
                          dta["dsp_ch_names"] = [
                              read_str(fid, 16)
                              for ch in range(dta["hdr"]["n_dsp"])
                          ]
                          dta["dsp_wts"] = read_float_matrix(
                              fid,
                              dta["hdr"]["n_entries"],
                              dta["hdr"]["n_dsp"],
                          )
                          dta["anlg_wts"] = read_int16_matrix(
                              fid,
                              dta["hdr"]["n_entries"],
                              dta["hdr"]["n_anlg"],
                          )
                      else:  # handle MAGNES2500 naming scheme
                          fid.seek(
                              start_bytes
                              + ub["hdr"]["user_space_size"]
                              - dta["hdr"]["n_bytes"]
                              * dta["hdr"]["n_entries"],
                              0,
                          )
  
                          dta["hdr"]["n_dsp"] = (
                              dta["hdr"]["n_bytes"] // 4 - 2
                          )
                          assert dta["hdr"]["n_dsp"] == len(
                              BTI_WH2500_REF_MAG
                          ) + len(BTI_WH2500_REF_GRAD)
                          dta["ch_names"] = ["WH2500"] * dta["hdr"][
                              "n_entries"
                          ]
                          dta["hdr"]["n_anlg"] = 3
                          # These orders could be wrong, so don't set them
                          # for now
                          # dta['anlg_ch_names'] = BTI_WH2500_REF_MAG[:3]
                          # dta['dsp_ch_names'] = (BTI_WH2500_REF_GRAD +
                          #                        BTI_WH2500_REF_MAG)
                          dta["anlg_wts"] = np.zeros(
                              (
                                  dta["hdr"]["n_entries"],
                                  dta["hdr"]["n_anlg"],
                              ),
                              dtype="i2",
                          )
                          dta["dsp_wts"] = np.zeros(
                              (
                                  dta["hdr"]["n_entries"],
                                  dta["hdr"]["n_dsp"],
                              ),
                              dtype="f4",
                          )
                          for n in range(dta["hdr"]["n_entries"]):
                              dta["anlg_wts"][n] = read_int16_matrix(
                                  fid, 1, dta["hdr"]["n_anlg"]
                              )
                              read_int16(fid)
                              dta["dsp_wts"][n] = read_float_matrix(
                                  fid, 1, dta["hdr"]["n_dsp"]
                              )
  
                  elif kind == BTI.UB_B_TRIG_MASK:
                      dta["version"] = read_int32(fid)
                      dta["entries"] = read_int32(fid)
                      fid.seek(16, 1)
  
                      dta["masks"] = []
                      for entry in range(dta["entries"]):
                          d = {
                              "name": read_str(fid, 20),
                              "nbits": read_uint16(fid),
                              "shift": read_uint16(fid),
                              "mask": read_uint32(fid),
                          }
                          dta["masks"] += [d]
                          fid.seek(8, 1)
  
              else:
                  dta["unknown"] = {
                      "hdr": read_char(
                          fid, ub["hdr"]["user_space_size"]
                      )
                  }
  
              n_read = fid.tell() - start_bytes
              if n_read != ub["hdr"]["user_space_size"]:
                  raise RuntimeError(
                      "Internal MNE reading error, read size %d "
                      "!= %d expected size for kind %s"
                      % (n_read, ub["hdr"]["user_space_size"], kind)
                  )
              ub.update(dta)  # finally update the userblock data
              _correct_offset(fid)  # after reading.
  
          cfg["chs"] = list()
  
          # prepare reading channels
          for channel in range(cfg["hdr"]["total_chans"]):
              ch = {
                  "name": read_str(fid, 16),
                  "chan_no": read_int16(fid),
                  "ch_type": read_uint16(fid),
                  "sensor_no": read_int16(fid),
                  "data": dict(),
              }
  
              fid.seek(2, 1)
              ch.update(
                  {
                      "gain": read_float(fid),
                      "units_per_bit": read_float(fid),
                      "yaxis_label": read_str(fid, 16),
                      "aar_val": read_double(fid),
                      "checksum": read_int32(fid),
                      "reserved": read_str(fid, 32),
                  }
              )
  
              cfg["chs"] += [ch]
              _correct_offset(fid)  # before and after
              dta = dict()
              if ch["ch_type"] in [
                  BTI.CHTYPE_MEG,
                  BTI.CHTYPE_REFERENCE,
              ]:
                  dev = {
                      "device_info": read_dev_header(fid),
                      "inductance": read_float(fid),
                      "padding": read_str(fid, 4),
                      "transform": _correct_trans(
                          read_transform(fid), False
                      ),
                      "xform_flag": read_int16(fid),
                      "total_loops": read_int16(fid),
                  }
  
                  fid.seek(4, 1)
                  dev["reserved"] = read_str(fid, 32)
                  dta.update({"dev": dev, "loops": []})
                  for loop in range(dev["total_loops"]):
                      d = {
                          "position": read_double_matrix(fid, 1, 3),
                          "orientation": read_double_matrix(fid, 1, 3),
                          "radius": read_double(fid),
                          "wire_radius": read_double(fid),
                          "turns": read_int16(fid),
                      }
                      fid.seek(2, 1)
                      d["checksum"] = read_int32(fid)
                      d["reserved"] = read_str(fid, 32)
                      dta["loops"] += [d]
  
              elif ch["ch_type"] == BTI.CHTYPE_EEG:
                  dta = {
                      "device_info": read_dev_header(fid),
                      "impedance": read_float(fid),
                      "padding": read_str(fid, 4),
                      "transform": read_transform(fid),
                      "reserved": read_char(fid, 32),
                  }
  
              elif ch["ch_type"] == BTI.CHTYPE_EXTERNAL:
                  dta = {
                      "device_info": read_dev_header(fid),
                      "user_space_size": read_int32(fid),
                      "reserved": read_str(fid, 32),
                  }
  
              elif ch["ch_type"] == BTI.CHTYPE_TRIGGER:
                  dta = {
                      "device_info": read_dev_header(fid),
                      "user_space_size": read_int32(fid),
                  }
                  fid.seek(2, 1)
                  dta["reserved"] = read_str(fid, 32)
  
              elif ch["ch_type"] in [
                  BTI.CHTYPE_UTILITY,
                  BTI.CHTYPE_DERIVED,
              ]:
                  dta = {
                      "device_info": read_dev_header(fid),
                      "user_space_size": read_int32(fid),
                      "reserved": read_str(fid, 32),
                  }
  
              elif ch["ch_type"] == BTI.CHTYPE_SHORTED:
                  dta = {
                      "device_info": read_dev_header(fid),
                      "reserved": read_str(fid, 32),
                  }
  
              ch.update(dta)  # add data collected
              _correct_offset(fid)  # after each reading
  
      return cfg
  
imports: import functools
  import os.path
  from io import BytesIO
  from itertools import count
  import numpy
  from ..._fiff._digitization import _make_bti_dig_points
  from ..._fiff.constants import FIFF
  from ..._fiff.meas_info import _empty_info
  from ..._fiff.tag import _coil_trans_to_loc, _loc_to_coil_trans
  from ..._fiff.utils import _mult_cal_one, read_str
  from ...transforms import Transform, combine_transforms, invert_transform
  from ...utils import _stamp_to_dt, _validate_type, logger, path_like, verbose
  from ..base import BaseRaw
  from .constants import BTI
  from .read import read_char, read_dev_header, read_double, read_double_matrix, read_float, read_float_matrix, read_int16, read_int16_matrix, read_int32, read_int64, read_transform, read_uint16, read_uint32
label_desc: Use image node_id 9 for calling a global function with example usage: _read_config(fname) and returns: cfg