with con:
    cur = con.cursor()
    plot_xlabel = "benchmarks solved"
    plot_ylabel = "cummulative time"

    gnuplot_command = cStringIO.StringIO()

    data_file = open(data_file_name, 'w')
    util.setupPlot(gnuplot_command, plot_xlabel, plot_ylabel, "")
    util.setupCanvasPlot(gnuplot_command, "gnuplot_canvas")
    util.setupCactusPlot(gnuplot_command)

    util.startPlot(gnuplot_command)
    
    for i in range(len(job_ids)) :
        job_id = job_ids[i]
        result_i = util.getSortedResults(cur, job_id)
        util.dumpCactusToFile(data_file, util.getJobName(cur, job_id), result_i)

    for i in range(len(job_ids)) :
        util.plotOneCactus(gnuplot_command, data_file_name, i, 1, 2)
        if ( i < len(job_ids) - 1) :
            util.plotSeparator(gnuplot_command)

    data_file.close()
    val =  gnuplot_command.getvalue()
    print val
                       
con.close()
    script.write("set xlabel \"" + xlabel + "\"\n")
    script.write("set ylabel \"" + ylabel + "\"\n")
    script.write("set xtic auto\n")
    script.write("set ytic auto\n")
    script.write("set terminal pdf size 6, 4.5 \n")
    script.write("set key outside\n")
    script.write("set output \"" + plot_output + "\"\n")

def generateScatterBaseName(xjob, yjob, xfield, yfield) :
    return "scatter_" + str(xjob) + "_" + xfield + "_vs_" + str(yjob) + "_" +yfield
    
con = mdb.connect(server, user, password, database);
with con:
    cur = con.cursor()
    
    plot_xlabel = util.getJobName(cur, xjob)
    plot_ylabel = util.getJobName(cur, yjob)
    plot_title = plot_xlabel + " vs " + plot_ylabel
    
    base_name = path + generateScatterBaseName(xjob, yjob, xfield, yfield)

    gnuplot_file_name = base_name + ".gnuplot"
    gnuplot_file = open(gnuplot_file_name, 'w')

    data_file_name = base_name + ".dat"
    data_file = open(data_file_name, 'w')
    
    pdf_file_name = base_name + ".pdf"

    util.setupPlot(gnuplot_file, plot_xlabel, plot_ylabel, plot_title)
    util.setupPdfPlot(gnuplot_file, pdf_file_name)
    filtered_results = []
    for result in results_and_answers :
        path = result[0]
        xvalue = result[1]
        yvalue = result[2]
        res1 = result[3]
        res2 = result[4]
        if (res1 != "unknown" or res2 != "unknown") :
            filtered_results.append((path, xvalue, yvalue))
    return filtered_results
    
con = mdb.connect(server, user, password, database);
with con:
    cur = con.cursor()
    
    plot_xlabel = util.getJobName(cur, xjob) + " ("+ str(xjob) + ")"
    plot_ylabel = util.getJobName(cur, yjob) + " ("+ str(yjob) + ")"
    plot_title = plot_xlabel + " vs " + plot_ylabel
    
    data_file = open(data_file_name, 'w')
    javascript_file = open(javascript_file_name, 'w')
    gnuplot_command = cStringIO.StringIO()
    
    util.setupPlot(gnuplot_command, plot_xlabel, plot_ylabel, plot_title)
    util.setupCanvasPlot(gnuplot_command, "gnuplot_canvas")

    util.startPlot(gnuplot_command)

    results_and_answers = util.getRunTimesAndAnswer(cur, xjob, yjob)
    results = filterUnknowns(results_and_answers)
    families = util.groupByFamilies(results)
        family_results = families[family]
        dumpResultsToFiles(data_file, jsmap_file, family, family_results)
        sys.stdout.write("\"< cat "+data_name+"\" index " + str(i) +" using 2:3 with points pt 9 pointsize 1 linecolor " + str(i) + ", ")
        i = i + 1
    sys.stdout.write("x with line linecolor rgb \"gray\" \n")
    data_file.close()
    jsmap_file.close()

def setupGnuPlot(title, xlabel, ylabel) :
    sys.stdout.write("set autoscale\n")
    sys.stdout.write("set title \"" + title + "\"\n")
    sys.stdout.write("set xlabel \"" + xlabel + "\"\n")
    sys.stdout.write("set ylabel \"" + ylabel + "\"\n")
    sys.stdout.write("set xtic auto\n")
    sys.stdout.write("set ytic auto\n")
    sys.stdout.write("set terminal canvas size 800, 600 name \"gnuplot_canvas\"\n")
    sys.stdout.write("set key outside autotitle columnheader\n")
    
con = mdb.connect(server, user, password, table);
with con:
    cur = con.cursor()
    plot_title = pu.getJobName(cur, xjob) + " vs " + pu.getJobName(cur, yjob)
    plot_xlabel = "time " + pu.getJobName(cur, xjob)
    plot_ylabel = "time " + pu.getJobName(cur, yjob)

    results = getResults(cur, xjob, yjob)
    families = pu.groupByFamilies(results)
    setupGnuPlot(plot_title, plot_xlabel, plot_ylabel)
    generatePlots(data_file, js_map_file, families)
con.close()