code: def _split_header(fobj):
      """Split header into `version`, `gen_dict`, `image_lines`"""
      version = None
      gen_dict = {}
      image_lines = []
      # Small state-machine
      state = "top-header"
      for line in fobj:
          line = line.strip()
          if line == "":
              continue
          if state == "top-header":
              if not line.startswith("#"):
                  state = "general-info"
              elif "image export tool" in line:
                  version = line.split()[-1]
          if state == "general-info":
              if not line.startswith("."):
                  state = "comment-block"
              else:  # Let match raise error for unexpected field format
                  key, value = GEN_RE.match(line).groups()
                  gen_dict[key] = value
          if state == "comment-block":
              if not line.startswith("#"):
                  state = "image-info"
          if state == "image-info":
              if line.startswith("#"):
                  break
              image_lines.append(line)
      return version, gen_dict, image_lines
  
imports: import re
  import warnings
  from collections import OrderedDict
  from copy import deepcopy
  from io import StringIO
  from locale import getpreferredencoding
  import numpy
  from .affines import apply_affine, dot_reduce, from_matvec
  from .eulerangles import euler2mat
  from .fileslice import fileslice, strided_scalar
  from .nifti1 import unit_codes
  from .openers import ImageOpener
  from .spatialimages import SpatialHeader, SpatialImage
  from .volumeutils import Recoder, array_from_file
label_desc: Use image node_id 1 for calling a global function with example usage: _split_header(fobj) and returns: version,  gen_dict,  image_lines