code: def _read_nihon_header(fname):
      # Read the Nihon Kohden EEG file header
      fname = _ensure_path(fname)
      _chan_labels = _read_21e_file(fname)
      header = {}
      logger.info(f"Reading header from {fname}")
      with open(fname) as fid:
          version = np.fromfile(fid, "|S16", 1).astype("U16")[0]
          if version not in _valid_headers:
              raise ValueError(
                  f"Not a valid Nihon Kohden EEG file ({version})"
              )
  
          fid.seek(0x0081)
          control_block = np.fromfile(fid, "|S16", 1).astype("U16")[0]
          if control_block not in _valid_headers:
              raise ValueError(
                  f"Not a valid Nihon Kohden EEG file (control block {version})"
              )
  
          fid.seek(0x17FE)
          waveform_sign = np.fromfile(fid, np.uint8, 1)[0]
          if waveform_sign != 1:
              raise ValueError(
                  "Not a valid Nihon Kohden EEG file "
                  "(waveform block)"
              )
          header["version"] = version
  
          fid.seek(0x0091)
          n_ctlblocks = np.fromfile(fid, np.uint8, 1)[0]
          header["n_ctlblocks"] = n_ctlblocks
          controlblocks = []
          for i_ctl_block in range(n_ctlblocks):
              t_controlblock = {}
              fid.seek(0x0092 + i_ctl_block * 20)
              t_ctl_address = np.fromfile(fid, np.uint32, 1)[0]
              t_controlblock["address"] = t_ctl_address
              fid.seek(t_ctl_address + 17)
              n_datablocks = np.fromfile(fid, np.uint8, 1)[0]
              t_controlblock["n_datablocks"] = n_datablocks
              t_controlblock["datablocks"] = []
              for i_data_block in range(n_datablocks):
                  t_datablock = {}
                  fid.seek(t_ctl_address + i_data_block * 20 + 18)
                  t_data_address = np.fromfile(fid, np.uint32, 1)[0]
                  t_datablock["address"] = t_data_address
  
                  fid.seek(t_data_address + 0x26)
                  t_n_channels = np.fromfile(fid, np.uint8, 1)[
                      0
                  ].astype(np.int64)
                  t_datablock["n_channels"] = t_n_channels
  
                  t_channels = []
                  for i_ch in range(t_n_channels):
                      fid.seek(t_data_address + 0x27 + (i_ch * 10))
                      t_idx = np.fromfile(fid, np.uint8, 1)[0]
                      t_channels.append(_chan_labels[t_idx])
  
                  t_datablock["channels"] = t_channels
  
                  fid.seek(t_data_address + 0x1C)
                  t_record_duration = np.fromfile(fid, np.uint32, 1)[
                      0
                  ].astype(np.int64)
                  t_datablock["duration"] = t_record_duration
  
                  fid.seek(t_data_address + 0x1A)
                  sfreq = np.fromfile(fid, np.uint16, 1)[0] & 0x3FFF
                  t_datablock["sfreq"] = sfreq.astype(np.int64)
  
                  t_datablock["n_samples"] = np.int64(
                      t_record_duration * sfreq // 10
                  )
                  t_controlblock["datablocks"].append(t_datablock)
              controlblocks.append(t_controlblock)
          header["controlblocks"] = controlblocks
  
      # Now check that every data block has the same channels and sfreq
      chans = []
      sfreqs = []
      nsamples = []
      for t_ctl in header["controlblocks"]:
          for t_dtb in t_ctl["datablocks"]:
              chans.append(t_dtb["channels"])
              sfreqs.append(t_dtb["sfreq"])
              nsamples.append(t_dtb["n_samples"])
      for i_elem in range(1, len(chans)):
          if chans[0] != chans[i_elem]:
              raise ValueError(
                  "Channel names in datablocks do not match"
              )
          if sfreqs[0] != sfreqs[i_elem]:
              raise ValueError(
                  "Sample frequency in datablocks do not match"
              )
      header["ch_names"] = chans[0]
      header["sfreq"] = sfreqs[0]
      header["n_samples"] = np.sum(nsamples)
  
      # TODO: Support more than one controlblock and more than one datablock
      if header["n_ctlblocks"] != 1:
          raise NotImplementedError(
              "I dont know how to read more than one "
              "control block for this type of file :("
          )
      if header["controlblocks"][0]["n_datablocks"] > 1:
          # Multiple blocks, check that they all have the same kind of data
          datablocks = header["controlblocks"][0]["datablocks"]
          block_0 = datablocks[0]
          for t_block in datablocks[1:]:
              if block_0["n_channels"] != t_block["n_channels"]:
                  raise ValueError(
                      "Cannot read NK file with different number of channels "
                      "in each datablock"
                  )
              if block_0["channels"] != t_block["channels"]:
                  raise ValueError(
                      "Cannot read NK file with different channels in each "
                      "datablock"
                  )
              if block_0["sfreq"] != t_block["sfreq"]:
                  raise ValueError(
                      "Cannot read NK file with different sfreq in each "
                      "datablock"
                  )
  
      return header
  
imports: from collections import OrderedDict
  from datetime import datetime, timezone
  from pathlib import Path
  import numpy
  from ..._fiff.meas_info import create_info
  from ..._fiff.utils import _mult_cal_one
  from ...annotations import Annotations
  from ...utils import _check_fname, fill_doc, logger, verbose, warn
  from ..base import BaseRaw
label_desc: Use image node_id 5 for calling a global function with example usage: _read_nihon_header(fname) and returns: header