code: def write_named_matrix(fid, kind, mat):
      """Write named matrix from the given node.
  
      Parameters
      ----------
      fid : file
          The opened file descriptor.
      kind : int
          The kind of the matrix.
      matkind : int
          The type of matrix.
      """
      # let's save ourselves from disaster
      n_tot = mat["nrow"] * mat["ncol"]
      if mat["data"].size != n_tot:
          ratio = n_tot / float(mat["data"].size)
          if n_tot < mat["data"].size and ratio > 0:
              ratio = 1 / ratio
          raise ValueError(
              "Cannot write matrix: row (%i) and column (%i) "
              "total element (%i) mismatch with data size (%i), "
              "appears to be off by a factor of %gx"
              % (
                  mat["nrow"],
                  mat["ncol"],
                  n_tot,
                  mat["data"].size,
                  ratio,
              )
          )
      start_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
      write_int(fid, FIFF.FIFF_MNE_NROW, mat["nrow"])
      write_int(fid, FIFF.FIFF_MNE_NCOL, mat["ncol"])
  
      if len(mat["row_names"]) > 0:
          # let's prevent unintentional stupidity
          if len(mat["row_names"]) != mat["nrow"]:
              raise ValueError('len(mat["row_names"]) != mat["nrow"]')
          write_name_list(
              fid, FIFF.FIFF_MNE_ROW_NAMES, mat["row_names"]
          )
  
      if len(mat["col_names"]) > 0:
          # let's prevent unintentional stupidity
          if len(mat["col_names"]) != mat["ncol"]:
              raise ValueError('len(mat["col_names"]) != mat["ncol"]')
          write_name_list(
              fid, FIFF.FIFF_MNE_COL_NAMES, mat["col_names"]
          )
  
      write_float_matrix(fid, kind, mat["data"])
      end_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
  
imports: from ..utils import logger
  from .constants import FIFF
  from .tag import find_tag, has_tag
  from .write import end_block, start_block, write_float_matrix, write_int, write_name_list
label_desc: Use image node_id 3 for calling a global function with example usage: write_named_matrix(fid, kind, mat) without return types