#
    # Run coincidence algorithm.
    #

    burca.burca(xmldoc=xmldoc,
                process_id=process.process_id,
                EventListType=EventListType,
                CoincTables=CoincTables,
                coinc_definer_row=CoincDef,
                thresholds=options.threshold,
                ntuple_comparefunc=ntuple_comparefunc,
                verbose=options.verbose)

    #
    # Close out the process table.
    #

    ligolw_process.set_process_end_time(process)

    #
    # Write back to disk, and clean up.
    #

    ligolw_utils.write_filename(xmldoc,
                                filename,
                                verbose=options.verbose,
                                gz=(filename or "stdout").endswith(".gz"))
    xmldoc.unlink()
    lsctables.reset_next_ids(lsctables.TableByName.values())
h5file.create_dataset("/sim_inspiral",
                      data=ligolw_table_to_array(sims),
                      compression='gzip',
                      compression_opts=1)
h5file.create_dataset("/sngl_inspiral",
                      data=ligolw_table_to_array(tmplts),
                      compression='gzip',
                      compression_opts=1)
h5file.create_dataset("/match_map",
                      data=match_map,
                      compression='gzip',
                      compression_opts=1)
h5file.flush()

# merge process and process_params tables, then complete ourselves
lsctables.reset_next_ids(
    (lsctables.ProcessTable, lsctables.ProcessParamsTable))
ligolw_add.reassign_ids(fake_xmldoc)
ligolw_add.merge_ligolws(fake_xmldoc)
ligolw_add.merge_compatible_tables(fake_xmldoc)
ligolw_process.set_process_end_time(process)

# output process
proc = lsctables.ProcessTable.get_table(fake_xmldoc)
for p in proc:
    p.cvs_entry_time = 0
    p.end_time = 0
h5file.create_dataset("/process", data=ligolw_table_to_array(proc))
pp = lsctables.ProcessParamsTable.get_table(fake_xmldoc)
h5file.create_dataset("/process_params", data=ligolw_table_to_array(pp))
h5file.close()
				print >>sys.stderr, "skipping (use --force to force)"
			continue
		if options.verbose:
			print >>sys.stderr, "continuing by --force"

	#
	# add process metadata to document
	#

	process = binjfind.append_process(xmldoc, match_algorithm = options.match_algorithm, comment = options.comment)

	#
	# run binjfind algorithm
	#

	binjfind.binjfind(xmldoc, process, search, snglcomparefunc, nearcoinccomparefunc, verbose = options.verbose)

	#
	# close out the process metadata
	#

	ligolw_process.set_process_end_time(process)

	#
	# done
	#

	utils.write_filename(xmldoc, filename, verbose = options.verbose, gz = (filename or "stdout").endswith(".gz"))
	xmldoc.unlink()
	lsctables.reset_next_ids(lsctables.TableByName.values())
    match_map[j] = (match_tup[0], inj_wf.sigmasq)
    tmplts.append(bank._templates[match_tup[1]].to_sngl())

if verbose:
    print "total number of match calculations:", bank._nmatch

# write out results
h5file = H5File("%s.h5" % usertag, "w")
h5file.create_dataset("/sim_inspiral", data=ligolw_table_to_array(sims), compression='gzip', compression_opts=1)
h5file.create_dataset("/sngl_inspiral", data=ligolw_table_to_array(tmplts), compression='gzip', compression_opts=1)
h5file.create_dataset("/match_map", data=match_map, compression='gzip', compression_opts=1)
h5file.flush()

# merge process and process_params tables, then complete ourselves
lsctables.reset_next_ids((lsctables.ProcessTable, lsctables.ProcessParamsTable))
ligolw_add.reassign_ids(fake_xmldoc)
ligolw_add.merge_ligolws(fake_xmldoc)
ligolw_add.merge_compatible_tables(fake_xmldoc)
ligolw_process.set_process_end_time(process)

# output process
proc = lsctables.ProcessTable.get_table(fake_xmldoc)
for p in proc:
    p.cvs_entry_time = 0
    p.end_time = 0
h5file.create_dataset("/process", data=ligolw_table_to_array(proc))
pp = lsctables.ProcessParamsTable.get_table(fake_xmldoc)
h5file.create_dataset("/process_params", data=ligolw_table_to_array(pp))
h5file.close()