#!/usr/bin/env python

import sys

from pychips import *
from pychips.hlui import *
import chips_contrib as ctrb

def usage(progname):
    "Error out with a usage message"
    print "Usage: %s <infile> <outfile>" % progname
    sys.exit(1)

def plotfile(infile, outfile):
    """Plot up the lx versus z columns of infile
    and create a PNG version in outfile."""

    # Load in the data
    make_figure("%s[cols z,lx]" % infile)

    # Adjust the attributes/look of the plot
    ci = ChipsCurve()
    ci.line.style = "noline"
    ci.symbol.style = "circle"
    set_curve(ci)
    ctrb.ylog()
    set_plot_ylabel("L_x [10^{44} erg s^{-1}]")
    add_label(0.6, 0.1, "A spiffy plot", ["size", 18, "halign", 0.5])

    ofile = "%s.png" % outfile
    print_window(ofile, ["clobber", True])
    print "Created: %s" % ofile

# If run as a script, call the routine
if __name__ == "__main__":
    
    # Check script was called correctly
    if len(sys.argv) != 3:
        usage(sys.argv[0])

    # Call the routine whilst
    # emulating the "batch-mode" of ChIPS
    set_preference("window.display", "false")
    plotfile(sys.argv[1], sys.argv[2])
