#!/usr/bin/env python import sys, os from Numeric import * import Gnuplot g = Gnuplot.Gnuplot(persist=1) try: infilename = sys.argv[1] except: print "Usage of this script", sys.argv[0], "infile", sys.argv[1]; sys.exit(1) # Now run code, here c++ code which has been compiled and linked cmd = './program3.x out.dat' failure = os.system(cmd) if failure: print 'running program1 failed'; sys.exit(1) # Read file with data ifile = open(infilename, 'r') lines = ifile.readlines() # Fill in x and y x = [] ; y = [] # This are empty lists for line in lines: xvalue, yvalue = line.split() x.append(float(xvalue)); y.append(float(yvalue)) ifile.close() # convert to a form that the gnuplot interface can deal with #d = Gnuplot.Data(x, y, title='data from output file', with='lp') d = Gnuplot.Data(x, y, title='data from output file') g.xlabel('log10(h)') # make x label g.ylabel('log10(|Exact-Computed|)/|Exact|') g.plot(d) # plot the data g.hardcopy(filename="relerror.ps",terminal="postscript", enhanced=1, color=1) # Now prepare latex file, r in front avoids backslashes being treated # as control chars in strings preamb = r"""\documentclass[prc,aps,twocolumn,floatfix]{revtex4} \usepackage[dvips]{graphicx} \usepackage{epsfig} \usepackage{pst-plot} \usepackage{bm} """ title = "Test for Andreas" figure = r"""\begin{figure}[hbtp] \includegraphics[angle=270, scale=0.35]{relerror.ps} \caption{Simple plot} \label{fig:simpleplot} \end{figure} """ # Dump to file: filename = 'andreas' f = file(filename + '.tex', "w") f.write(preamb) f.write(r"""\begin{document}""") f.write(title) f.write(figure) f.write("""\end{document}""") f.close()