def METHOD_NAME(
    fname_montage: Union[Path, str],
    fname_info: Union[Path, str],
    fname_trans: Union[None, Path, str] = None,
):
    """Prepare SimNIBS montage file from a FieldTrip data structure containing
    an `elec` field describing the electrode configuration.
    PARAMETERS
    ----------
    fname_montage :
        Name of the SimNIBS montage file to write.
    fname_info :
        Name of a MAT file containing the electrode information in the field
        `elec`.
    fname_trans :
        Affine transformation matrix to apply to the electrode positions before
        writing to `fname_montage`.
    RETURNS
    -------
    """
    fname_info = Path(fname_info)
    info = loadmat(fname_info)["elec"][0]
    info = dict(zip(info.dtype.names, info[0]))
    info["label"] = np.array([label[0] for label in info["label"].squeeze()])
    info["chantype"] = np.array([ct[0] for ct in info["chantype"].squeeze()])
    info["unit"] = info["unit"][0]
    scale = to_m[info["unit"]] * from_m["mm"]
    info["elecpos"] *= scale
    # info["chanpos"] *= scale  # unused
    if fname_trans:
        fname_trans = Path(fname_trans)
        if fname_trans.suffix == ".mat":
            trans = loadmat(fname_trans)["trans"]
        elif fname_trans.suffix == ".txt":
            trans = np.loadtxt(fname_trans)
        else:
            raise ValueError("`fname_trans` must be either a MAT or a TXT file.")
        info["elecpos"] = apply_affine(trans, info["elecpos"])
        # info["chanpos"] = apply_affine(trans, info["chanpos"])
    is_eeg = info["chantype"] == "eeg"
    write_csv_positions(
        fname_montage,
        ["Electrode"] * sum(is_eeg),
        info["elecpos"][is_eeg],
        info["label"][is_eeg].tolist(),
    )