docs: def td_is_finished(tomodir):
      """Return the state of modeling and inversion for a given tomodir. The
      result does not take into account sensitivities or potentials, as
      optionally generated by CRMod.
  
      Parameters
      ----------
      tomodir: string
          Directory to check
  
      Returns
      -------
      crmod_is_finished: bool
          True if a successful CRMod result is contained in the tomodir
          directory.
      crtomo_is_finished: bool
          True if a successful CRTomo inversion results is contained in the
          tomodir directory.
      """
      if not is_tomodir(tomodir):
          raise Exception('Supplied directory is not a tomodir!')
  
      # crmod finished is determined by:
      # config.dat/rho.dat/crmod.cfg are present
      # volt.dat is present
      if(os.path.isfile(tomodir + os.sep + 'config/config.dat') and
         os.path.isfile(tomodir + os.sep + 'rho/rho.dat') and
         os.path.isfile(tomodir + os.sep + 'grid/elem.dat') and
         os.path.isfile(tomodir + os.sep + 'grid/elec.dat') and
         os.path.isfile(tomodir + os.sep + 'exe/crmod.cfg') and
         os.path.isfile(tomodir + os.sep + 'mod/volt.dat')):
          crmod_is_finished = True
      else:
          crmod_is_finished = False
  
      # crtomo is finished if
      # crtomo.cfg/volt.dat/elem.dat/elec.dat are present
      # inv/run.ctr contains the word "CPU" in the last line
      if(os.path.isfile(tomodir + os.sep + 'grid/elem.dat') and
         os.path.isfile(tomodir + os.sep + 'grid/elec.dat') and
         os.path.isfile(tomodir + os.sep + 'exe/crtomo.cfg') and
         os.path.isfile(tomodir + os.sep + 'inv/inv.ctr') and
         os.path.isfile(tomodir + os.sep + 'inv/run.ctr') and
         os.path.isfile(tomodir + os.sep + 'mod/volt.dat')):
          with open(tomodir + os.sep + 'inv/run.ctr', 'r') as fid:
              lines = fid.readlines()
              crtomo_is_finished = False
              # check the last 5 lines
              for line in lines[-5:]:
                  test_line = line.strip()
                  regex = re.compile('CPU')
                  result = regex.match(test_line)
                  if result is not None:
                      crtomo_is_finished = True
      else:
          crtomo_is_finished = False
      return crmod_is_finished, crtomo_is_finished