[Swift-commit] r4628 - in usertools/plotter: . old_scripts samples/dual samples/lines src/plotter
jonmon at ci.uchicago.edu
jonmon at ci.uchicago.edu
Fri Jun 17 14:28:46 CDT 2011
Author: jonmon
Date: 2011-06-17 14:28:46 -0500 (Fri, 17 Jun 2011)
New Revision: 4628
Added:
usertools/plotter/old_scripts/
usertools/plotter/old_scripts/dual.zsh
usertools/plotter/old_scripts/lines.zsh
usertools/plotter/src/plotter/Plotter.java
usertools/plotter/swift_plotter.zsh
Removed:
usertools/plotter/dual.zsh
usertools/plotter/lines.zsh
Modified:
usertools/plotter/README.txt
usertools/plotter/build.xml
usertools/plotter/samples/dual/About.txt
usertools/plotter/samples/lines/About.txt
usertools/plotter/src/plotter/Bits.java
usertools/plotter/src/plotter/Dual.java
usertools/plotter/src/plotter/LineReader.java
usertools/plotter/src/plotter/Lines.java
usertools/plotter/src/plotter/Plots.java
usertools/plotter/src/plotter/Util.java
Log:
o moved the old lines.zsh and dual.zsh into the old_scripts directory.
o Changes to the java source files, prints to stderr where appropriate.
o Added Plotter class. Depending on what option you give at the command line will generate a single y-axis labeled(-s) or double y-axis labeled(-d) plot.
o Added swift_plotter.zsh script that will call the Plotter class.
o Added clean target to the build.xml script.
Modified: usertools/plotter/README.txt
===================================================================
--- usertools/plotter/README.txt 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/README.txt 2011-06-17 19:28:46 UTC (rev 4628)
@@ -3,4 +3,4 @@
Produces EPS output from two-column data sets using JFreeChart.
-User interface is lines.zsh
+User interface is swift_plotter.zsh
Modified: usertools/plotter/build.xml
===================================================================
--- usertools/plotter/build.xml 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/build.xml 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,5 +1,3 @@
-
-
<project name="plots"
default="all">
@@ -13,13 +11,20 @@
depends="compile" />
<target name="compile">
- <javac srcdir="src"
- classpath="${classpath}"
- listfiles="${lf}"
- debug="true"
- debuglevel="source,lines,vars">
- <compilerarg value="-Xlint"/>
- </javac>
+ <javac includeAntRuntime="false"
+ srcdir="src"
+ classpath="${classpath}"
+ listfiles="${lf}"
+ debug="true"
+ debuglevel="source,lines,vars">
+ <compilerarg value="-Xlint"/>
+ </javac>
</target>
+ <target name="clean">
+ <delete>
+ <fileset dir="src/plotter" includes="**/*.class"/>
+ </delete>
+ </target>
+
</project>
Deleted: usertools/plotter/dual.zsh
===================================================================
--- usertools/plotter/dual.zsh 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/dual.zsh 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,16 +0,0 @@
-#!/bin/zsh
-
-# DUAL.ZSH
-
-# Create plot with two data sets, two Y axes
-# Arguments passed directly to Dual.java - see there for details
-# usage: dual.zsh <properties> <output file> <data file>*
-
-PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
-
-# declare -p PLOTTERS
-
-source ${PLOTTERS}/classpath.zsh
-[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
-
-java -ea -cp ${CP} plotter.Dual ${*}
Deleted: usertools/plotter/lines.zsh
===================================================================
--- usertools/plotter/lines.zsh 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/lines.zsh 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,14 +0,0 @@
-#!/bin/zsh
-
-# LINES.ZSH
-# Arguments passed directly to Lines.java - see there for details
-# usage: lines.zsh <properties> <output file> <data file>*
-
-PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
-
-# declare -p PLOTTERS
-
-source ${PLOTTERS}/classpath.zsh
-[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
-
-java -ea -cp ${CP} plotter.Lines ${*}
Added: usertools/plotter/old_scripts/dual.zsh
===================================================================
--- usertools/plotter/old_scripts/dual.zsh (rev 0)
+++ usertools/plotter/old_scripts/dual.zsh 2011-06-17 19:28:46 UTC (rev 4628)
@@ -0,0 +1,16 @@
+#!/bin/zsh
+
+# DUAL.ZSH
+
+# Create plot with two data sets, two Y axes
+# Arguments passed directly to Dual.java - see there for details
+# usage: dual.zsh <properties> <output file> <data file>*
+
+PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
+
+# declare -p PLOTTERS
+
+source ${PLOTTERS}/classpath.zsh
+[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
+
+java -ea -cp ${CP} plotter.Dual ${*}
Property changes on: usertools/plotter/old_scripts/dual.zsh
___________________________________________________________________
Added: svn:executable
+ *
Added: usertools/plotter/old_scripts/lines.zsh
===================================================================
--- usertools/plotter/old_scripts/lines.zsh (rev 0)
+++ usertools/plotter/old_scripts/lines.zsh 2011-06-17 19:28:46 UTC (rev 4628)
@@ -0,0 +1,14 @@
+#!/bin/zsh
+
+# LINES.ZSH
+# Arguments passed directly to Lines.java - see there for details
+# usage: lines.zsh <properties> <output file> <data file>*
+
+PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
+
+# declare -p PLOTTERS
+
+source ${PLOTTERS}/classpath.zsh
+[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
+
+java -ea -cp ${CP} plotter.Lines ${*}
Property changes on: usertools/plotter/old_scripts/lines.zsh
___________________________________________________________________
Added: svn:executable
+ *
Modified: usertools/plotter/samples/dual/About.txt
===================================================================
--- usertools/plotter/samples/dual/About.txt 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/samples/dual/About.txt 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,5 +1,5 @@
To run:
-../../dual.zsh plot.cfg tmp.eps set*.data
+../../swift_plotter.zsh -d plot.cfg tmp.eps set*.data
Modified: usertools/plotter/samples/lines/About.txt
===================================================================
--- usertools/plotter/samples/lines/About.txt 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/samples/lines/About.txt 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,5 +1,5 @@
To run:
-../../lines.zsh plot.cfg tmp.eps set*.data
+../../swift_plotter.zsh -s plot.cfg tmp.eps set*.data
Modified: usertools/plotter/src/plotter/Bits.java
===================================================================
--- usertools/plotter/src/plotter/Bits.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/Bits.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -10,141 +10,141 @@
public class Bits
{
- public static Random rng = null;
- static boolean locked = false;
- static boolean ready = false;
+ public static Random rng = null;
+ static boolean locked = false;
+ static boolean ready = false;
- /**
- If not locked, seed the generator with the clock.
- */
- public static void init()
- {
- init(System.currentTimeMillis());
- }
+ /**
+ If not locked, seed the generator with the clock.
+ */
+ public static void init()
+ {
+ init(System.currentTimeMillis());
+ }
- /**
- If not locked, seed the generator with the clock mod 1000.
- Useful for debugging.
- @param print If true, print the seed.
- */
- public static long init(boolean print)
- {
- long seed = System.currentTimeMillis() % 1000;
- init(seed);
+ /**
+ If not locked, seed the generator with the clock mod 1000.
+ Useful for debugging.
+ @param print If true, print the seed.
+ */
+ public static long init(boolean print)
+ {
+ long seed = System.currentTimeMillis() % 1000;
+ init(seed);
- if (print)
- System.out.println("Bits.seed: " + seed);
+ if (print)
+ System.out.println("Bits.seed: " + seed);
- return seed;
- }
+ return seed;
+ }
- /**
- If not locked, seed the generator
- @param seed The seed.
- */
- public static void init(long seed)
- {
- assert (!locked) : "Bits locked!";
- // System.out.println("Seeding RNG...");
- rng = new Random(seed);
- ready = true;
- }
+ /**
+ If not locked, seed the generator
+ @param seed The seed.
+ */
+ public static void init(long seed)
+ {
+ assert (!locked) : "Bits locked!";
+ // System.out.println("Seeding RNG...");
+ rng = new Random(seed);
+ ready = true;
+ }
- /**
- Lock the generator to prevent seeding
- */
- public static void lock()
- {
- locked = true;
- }
+ /**
+ Lock the generator to prevent seeding
+ */
+ public static void lock()
+ {
+ locked = true;
+ }
- /**
- Unlock the generator
- */
- public static void unlock()
- {
- locked = false;
- }
+ /**
+ Unlock the generator
+ */
+ public static void unlock()
+ {
+ locked = false;
+ }
- public static double nextDouble()
- {
- if (! ready)
+ public static double nextDouble()
{
- System.err.println("Bits not ready!");
- System.exit(2);
+ if (! ready)
+ {
+ System.err.println("Bits not ready!");
+ System.exit(2);
+ }
+ return rng.nextDouble();
}
- return rng.nextDouble();
- }
- public static double nextDouble(double d)
- {
- return rng.nextDouble() * d;
- }
+ public static double nextDouble(double d)
+ {
+ return rng.nextDouble() * d;
+ }
- public static int nextInt()
- {
- if (! ready)
+ public static int nextInt()
{
- System.err.println("Bits not ready!");
- System.exit(2);
+ if (! ready)
+ {
+ System.err.println("Bits not ready!");
+ System.exit(2);
+ }
+ return rng.nextInt();
}
- return rng.nextInt();
- }
- /**
- Return a integer in [0..t).
- */
- public static int nextInt(int t)
- {
- double d = nextDouble();
- int i = (new Double(d * t)).intValue();
- return i;
- }
+ /**
+ Return a integer in [0..t).
+ */
+ public static int nextInt(int t)
+ {
+ double d = nextDouble();
+ int i = (new Double(d * t)).intValue();
+ return i;
+ }
- public static boolean nextBoolean()
- {
- if (! ready)
+ public static boolean nextBoolean()
{
- System.err.println("Bits not ready!");
- System.exit(2);
+ if (! ready)
+ {
+ System.err.println("Bits not ready!");
+ System.exit(2);
+ }
+ return rng.nextBoolean();
}
- return rng.nextBoolean();
- }
- public static long nextLong()
- {
- if (! ready)
+ public static long nextLong()
{
- System.err.println("Bits not ready!");
- System.exit(2);
+ if (! ready)
+ {
+ System.err.println("Bits not ready!");
+ System.exit(2);
+ }
+ return rng.nextLong();
}
- return rng.nextLong();
- }
- public static long nextLong(long t)
- {
- double d = nextDouble();
- long i = (new Double(d * t)).longValue();
- return i;
- }
+ public static long nextLong(long t)
+ {
+ double d = nextDouble();
+ long i = (new Double(d * t)).longValue();
+ return i;
+ }
- public static BigInteger nextBigInteger(BigInteger i)
- {
- if (i.equals(BigInteger.ZERO))
- return BigInteger.ZERO;
-
- int b = i.bitLength()+1;
- BigInteger result;
- do
+ public static BigInteger nextBigInteger(BigInteger i)
{
- result = BigInteger.valueOf(b);
- } while (result.compareTo(i) >= 0);
+ if (i.equals(BigInteger.ZERO))
+ return BigInteger.ZERO;
- return result;
- }
+ int b = i.bitLength()+1;
+ BigInteger result;
+ do
+ {
+ result = BigInteger.valueOf(b);
+ } while (result.compareTo(i) >= 0);
- public static void nextBytes(byte[] bytes)
- {
- rng.nextBytes(bytes);
- }
+ return result;
+ }
+
+ public static void nextBytes(byte[] bytes)
+ {
+ rng.nextBytes(bytes);
+ }
}
Modified: usertools/plotter/src/plotter/Dual.java
===================================================================
--- usertools/plotter/src/plotter/Dual.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/Dual.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -27,405 +27,409 @@
* */
public class Dual
{
- static Properties properties;
+ static Properties properties;
- public static boolean bw = false;
+ public static boolean bw = false;
- static int width = 400;
- static int height = 400;
+ static int width = 400;
+ static int height = 400;
- // null indicates the value was not set by the user
- static Double xmin = null;
- static Double xmax = null;
- static Double ymin1 = null;
- static Double ymax1 = null;
- static Double ymin2 = null;
- static Double ymax2 = null;
+ // null indicates the value was not set by the user
+ static Double xmin = null;
+ static Double xmax = null;
+ static Double ymin1 = null;
+ static Double ymax1 = null;
+ static Double ymin2 = null;
+ static Double ymax2 = null;
- /**
- Generate simple plot
- @param collection The x,y data
- @param title Plot title
- @param xlabel X label text
- @param ylabel1 Y label text
- @param ylabel2 Y label text
- @param output EPS filename
- */
- public static boolean plot(XYSeriesCollection[] collections,
- String title, String xlabel,
- String ylabel1, String ylabel2,
- String output)
- {
- EPSDocumentGraphics2D g2d = null;
- Rectangle2D.Double rectangle = null;
- OutputStream out = null;
-
- try
+ /**
+ Generate simple plot
+ @param collection The x,y data
+ @param title Plot title
+ @param xlabel X label text
+ @param ylabel1 Y label text
+ @param ylabel2 Y label text
+ @param output EPS filename
+ @return true/false depending if the method completed without error or not
+ */
+ public static boolean plot(XYSeriesCollection[] collections,
+ String title, String xlabel,
+ String ylabel1, String ylabel2,
+ String output)
{
- out = new FileOutputStream(output);
- out = new BufferedOutputStream(out);
+ EPSDocumentGraphics2D g2d = null;
+ Rectangle2D.Double rectangle = null;
+ OutputStream out = null;
- g2d = new EPSDocumentGraphics2D(false);
- g2d.setGraphicContext
- (new org.apache.xmlgraphics.java2d.GraphicContext());
+ try
+ {
+ out = new FileOutputStream(output);
+ out = new BufferedOutputStream(out);
- rectangle = new Rectangle2D.Double(0, 0, width, height);
+ g2d = new EPSDocumentGraphics2D(false);
+ g2d.setGraphicContext
+ (new org.apache.xmlgraphics.java2d.GraphicContext());
- g2d.setGraphicContext
- (new org.apache.xmlgraphics.java2d.GraphicContext());
- g2d.setupDocument(out, width, height);
- }
- catch (IOException e)
- {
- System.out.println("Problem with file: " + output);
- return false;
- }
+ rectangle = new Rectangle2D.Double(0, 0, width, height);
- final boolean withLegend = true;
+ g2d.setGraphicContext
+ (new org.apache.xmlgraphics.java2d.GraphicContext());
+ g2d.setupDocument(out, width, height);
+ }
+ catch (IOException e)
+ {
+ System.err.println("Problem with file: " + output);
+ return false;
+ }
- JFreeChart chart =
- ChartFactory.createXYLineChart
- (title, xlabel, ylabel1, collections[0],
- PlotOrientation.VERTICAL, withLegend, false, false);
+ final boolean withLegend = true;
- setupPlot(chart, collections, ylabel1, ylabel2);
- chart.draw(g2d, rectangle);
+ JFreeChart chart =
+ ChartFactory.createXYLineChart
+ (title, xlabel, ylabel1, collections[0],
+ PlotOrientation.VERTICAL, withLegend, false, false);
- try
- {
- g2d.finish();
- }
- catch (Exception e)
- {
- System.out.println("Err!");
- }
+ setupPlot(chart, collections, ylabel1, ylabel2);
+ chart.draw(g2d, rectangle);
- IOUtils.closeQuietly(out);
- System.out.println("PLOTTED: " + output);
+ try
+ {
+ g2d.finish();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Err!" + e);
+ }
- return true;
- }
+ IOUtils.closeQuietly(out);
+ System.out.println("PLOTTED: " + output);
- private static void setupPlot(JFreeChart chart,
- XYSeriesCollection[] collections,
- String ylabel1, String ylabel2)
- {
- XYPlot plot = chart.getXYPlot();
- XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
- XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
+ return true;
+ }
- int count = plot.getSeriesCount();
- if (bw)
- for (int i = 0; i < count; i++)
- {
- renderer1.setSeriesPaint(i, Color.BLACK);
- renderer2.setSeriesPaint(i, Color.BLACK);
- }
- Series series1 = collections[0].getSeries(0);
- if (! showShape(series1.getDescription()))
- renderer1.setSeriesShapesVisible(0, false);
- Series series2 = collections[1].getSeries(0);
- if (! showShape(series2.getDescription()))
- renderer2.setSeriesShapesVisible(1, false);
+ private static void setupPlot(JFreeChart chart,
+ XYSeriesCollection[] collections,
+ String ylabel1, String ylabel2)
+ {
+ XYPlot plot = chart.getXYPlot();
+ XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
+ XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
- Plots.setupLegend(chart, properties);
- setAxes(plot, ylabel1, ylabel2, collections[1]);
- plot.setRenderer(0, renderer1);
- plot.setRenderer(1, renderer2);
- plot.setBackgroundPaint(Color.WHITE);
- }
+ int count = plot.getSeriesCount();
+ if (bw)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ renderer1.setSeriesPaint(i, Color.BLACK);
+ renderer2.setSeriesPaint(i, Color.BLACK);
+ }
+ }
- static void setAxes(XYPlot plot, String ylabel1, String ylabel2,
- XYSeriesCollection collection)
- {
- plot.setDataset(1, collection);
+ Series series1 = collections[0].getSeries(0);
+ if (! showShape(series1.getDescription()))
+ renderer1.setSeriesShapesVisible(0, false);
+ Series series2 = collections[1].getSeries(0);
+ if (! showShape(series2.getDescription()))
+ renderer2.setSeriesShapesVisible(1, false);
- // Actual values: modify if necessary
- double axmin, axmax, aymin1, aymax1, aymin2, aymax2;
-
- if (xmin != null || xmax != null)
- {
- NumberAxis axis = new NumberAxis();
- plot.setDomainAxis(axis);
- Range range = axis.getRange();
- axmin = range.getLowerBound();
- axmax = range.getUpperBound();
- if (xmin != null) axmin = xmin;
- if (xmax != null) axmax = xmax;
- axis.setRange(axmin, axmax);
+ Plots.setupLegend(chart, properties);
+ setAxes(plot, ylabel1, ylabel2, collections[1]);
+ plot.setRenderer(0, renderer1);
+ plot.setRenderer(1, renderer2);
+ plot.setBackgroundPaint(Color.WHITE);
}
- // Left Y axis
- if (ymin1 != null || ymax1 != null)
+ static void setAxes(XYPlot plot, String ylabel1, String ylabel2,
+ XYSeriesCollection collection)
{
- NumberAxis axis = new NumberAxis(ylabel1);
- plot.setRangeAxis(0, axis);
- Range range = axis.getRange();
- aymin1 = range.getLowerBound();
- aymax1 = range.getUpperBound();
- if (ymin1 != null) aymin1 = ymin1;
- if (ymax1 != null) aymax1 = ymax1;
- axis.setRange(aymin1, aymax1);
- }
+ plot.setDataset(1, collection);
- // Right Y axis setup
- Font font = plot.getRangeAxis().getLabelFont();
- final NumberAxis rightAxis = new NumberAxis(ylabel2);
- rightAxis.setLabelFont(font);
- plot.setRangeAxis(1, rightAxis);
+ // Actual values: modify if necessary
+ double axmin, axmax, aymin1, aymax1, aymin2, aymax2;
- // Right Y axis
- if (ymin2 != null || ymax2 != null)
- {
- Range range = rightAxis.getRange();
- aymin2 = range.getLowerBound();
- aymax2 = range.getUpperBound();
- if (ymin2 != null) aymin2 = ymin2;
- if (ymax2 != null) aymax2 = ymax2;
- rightAxis.setRange(aymin2, aymax2);
- }
+ if (xmin != null || xmax != null)
+ {
+ NumberAxis axis = new NumberAxis();
+ plot.setDomainAxis(axis);
+ Range range = axis.getRange();
+ axmin = range.getLowerBound();
+ axmax = range.getUpperBound();
+ if (xmin != null) axmin = xmin;
+ if (xmax != null) axmax = xmax;
+ axis.setRange(axmin, axmax);
+ }
- plot.mapDatasetToRangeAxis(0, 0);
- plot.mapDatasetToRangeAxis(1, 1);
- plot.configureRangeAxes();
- }
+ // Left Y axis
+ if (ymin1 != null || ymax1 != null)
+ {
+ NumberAxis axis = new NumberAxis(ylabel1);
+ plot.setRangeAxis(0, axis);
+ Range range = axis.getRange();
+ aymin1 = range.getLowerBound();
+ aymax1 = range.getUpperBound();
+ if (ymin1 != null) aymin1 = ymin1;
+ if (ymax1 != null) aymax1 = ymax1;
+ axis.setRange(aymin1, aymax1);
+ }
- /**
- Args: Lines <properties> <output file> <data file>*
- Reads settings from properties: see scanProperties()
- Produces EPS output file
- Data files are two-columns of numbers each -
- see LineReader.read() and LineReader.array()
- */
- public static void main(String[] args)
- {
- // Settings:
- boolean verbose = false;
+ // Right Y axis setup
+ Font font = plot.getRangeAxis().getLabelFont();
+ final NumberAxis rightAxis = new NumberAxis(ylabel2);
+ rightAxis.setLabelFont(font);
+ plot.setRangeAxis(1, rightAxis);
- Getopt g = new Getopt("testprog", args, "v");
- int c = -1;
- while ((c = g.getopt()) != -1)
- {
- switch (c)
- {
- case 'v':
- verbose = true;
- }
+ // Right Y axis
+ if (ymin2 != null || ymax2 != null)
+ {
+ Range range = rightAxis.getRange();
+ aymin2 = range.getLowerBound();
+ aymax2 = range.getUpperBound();
+ if (ymin2 != null) aymin2 = ymin2;
+ if (ymax2 != null) aymax2 = ymax2;
+ rightAxis.setRange(aymin2, aymax2);
+ }
+
+ plot.mapDatasetToRangeAxis(0, 0);
+ plot.mapDatasetToRangeAxis(1, 1);
+ plot.configureRangeAxes();
}
- if (args.length < 3)
+ /**
+ Args: Lines <properties> <output file> <data file>*
+ Reads settings from properties: see scanProperties()
+ Produces EPS output file
+ Data files are two-columns of numbers each -
+ see LineReader.read() and LineReader.array()
+ */
+ public void plotter(String[] args)
{
- System.out.println
- ("usage: [<options>] <properties> <output> <data>*");
- System.exit(2);
- }
+ // Settings:
+ boolean verbose = false;
- Bits.init();
- Util.verbose(verbose);
+ Getopt g = new Getopt("testprog", args, "v");
+ int c = -1;
+ while ((c = g.getopt()) != -1)
+ {
+ switch (c)
+ {
+ case 'v':
+ verbose = true;
+ }
+ }
- String propFile = args[0];
- String output = args[1];
- List<String> names = new ArrayList<String>();
- for (int i = 2; i < args.length; i++)
- names.add(args[i]);
+ if (args.length < 3)
+ {
+ System.err.println
+ ("usage: [<options>] <properties> <output> <data>*");
+ System.exit(2);
+ }
- String title = null;
- String xlabel = null;
- String ylabel1 = null;
- String ylabel2 = null;
- List<double[][]> data = new ArrayList<double[][]>();
- List<String> labels = new ArrayList<String>();
+ Bits.init();
+ Util.verbose(verbose);
- properties = new Properties();
- load(propFile);
- title = properties.getProperty("title");
- xlabel = properties.getProperty("xlabel");
- ylabel1 = properties.getProperty("ylabel1");
- ylabel2 = properties.getProperty("ylabel2");
+ String propFile = args[0];
+ String output = args[1];
+ List<String> names = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++)
+ names.add(args[i]);
- scanProperties();
+ String title = null;
+ String xlabel = null;
+ String ylabel1 = null;
+ String ylabel2 = null;
+ List<double[][]> data = new ArrayList<double[][]>();
+ List<String> labels = new ArrayList<String>();
- for (String name : names)
- {
- File file = new File(name);
- Util.verbose("open: " + file);
- List<String> lines = null;
- try
- {
- lines = LineReader.read(file);
- }
- catch (FileNotFoundException e)
- {
- System.out.println("not found: " + file);
- System.exit(1);
- }
- double[][] array = LineReader.array(lines);
- data.add(array);
- addLabel(name, labels);
- Util.verbose("array:\n" + toString(array));
- }
+ properties = new Properties();
+ load(propFile);
+ title = properties.getProperty("title");
+ xlabel = properties.getProperty("xlabel");
+ ylabel1 = properties.getProperty("ylabel1");
+ ylabel2 = properties.getProperty("ylabel2");
- XYSeriesCollection[] collections =
- collections(data, labels, names);
+ scanProperties();
- plot(collections, title, xlabel, ylabel1, ylabel2, output);
- }
+ for (String name : names)
+ {
+ File file = new File(name);
+ Util.verbose("open: " + file);
+ List<String> lines = null;
+ try
+ {
+ lines = LineReader.read(file);
+ }
+ catch (FileNotFoundException e)
+ {
+ System.err.println("not found: " + file);
+ System.exit(1);
+ }
+ double[][] array = LineReader.array(lines);
+ data.add(array);
+ addLabel(name, labels);
+ Util.verbose("array:\n" + toString(array));
+ }
- static XYSeriesCollection[] collections(List<double[][]> data,
- List<String> labels,
- List<String> names)
- {
- final XYSeriesCollection[] result = new XYSeriesCollection[2];
- result[0] = new XYSeriesCollection();
- result[1] = new XYSeriesCollection();
+ XYSeriesCollection[] collections =
+ collections(data, labels, names);
- int count = 0;
- for (int i = 0; i < 2; i++)
+ plot(collections, title, xlabel, ylabel1, ylabel2, output);
+ }
+
+ static XYSeriesCollection[] collections(List<double[][]> data,
+ List<String> labels,
+ List<String> names)
{
- double[][] d = data.get(i);
- String label = "data: " + count;
- try
- {
- label = labels.get(count);
- }
- catch (IndexOutOfBoundsException e)
- {}
+ final XYSeriesCollection[] result = new XYSeriesCollection[2];
+ result[0] = new XYSeriesCollection();
+ result[1] = new XYSeriesCollection();
- XYSeries series = new XYSeries(label);
- for (int j = 0; j < d.length; j++)
- {
- series.add(d[j][0], d[j][1]);
- }
+ int count = 0;
+ for (int i = 0; i < 2; i++)
+ {
+ double[][] d = data.get(i);
+ String label = "data: " + count;
+ try
+ {
+ label = labels.get(count);
+ }
+ catch (IndexOutOfBoundsException e)
+ {}
- series.setDescription(names.get(count));
- result[i].addSeries(series);
- count++;
+ XYSeries series = new XYSeries(label);
+ for (int j = 0; j < d.length; j++)
+ {
+ series.add(d[j][0], d[j][1]);
+ }
+
+ series.setDescription(names.get(count));
+ result[i].addSeries(series);
+ count++;
+ }
+ return result;
}
- return result;
- }
- static void load(String propFile)
- {
- try
+ static void load(String propFile)
{
- if (propFile.equals("-"))
- properties.load(System.in);
- else
- properties.load(new FileInputStream(propFile));
+ try
+ {
+ if (propFile.equals("-"))
+ properties.load(System.in);
+ else
+ properties.load(new FileInputStream(propFile));
+ }
+ catch (FileNotFoundException e)
+ {
+ System.err.println(e);
+ System.exit(1);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ System.exit(1);
+ }
}
- catch (FileNotFoundException e)
- {
- System.out.println(e);
- System.exit(1);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- System.exit(1);
- }
- }
- /**
- Various plot properties. All are currently optional
+ /**
+ Various plot properties. All are currently optional
- Example.
- Assume you want to plot a two-column table in file.data.
- The first column is the x values and the second column
- is the y values. See LineReader for details.
+ Example.
+ Assume you want to plot a two-column table in file.data.
+ The first column is the x values and the second column
+ is the y values. See LineReader for details.
- Your properties may include:
- title = Plot
- xlabel = size
- ylabel = speed
- label.file.data = legend text
- width (output image width)
- height (output image height)
- xmin, xmax, ymin1, ymax1, ymin2, ymax2
- (auto-selected if not given)
- bw (Black and white, true/false, default false)
- */
- static void scanProperties()
- {
- String tmp;
- tmp = properties.getProperty("width");
- if (tmp != null)
- width = Integer.parseInt(tmp.trim());
- tmp = properties.getProperty("height");
- if (tmp != null)
- height = Integer.parseInt(tmp.trim());
- tmp = properties.getProperty("xmin");
- if (tmp != null)
- xmin = Double.parseDouble(tmp);
- tmp = properties.getProperty("xmax");
- if (tmp != null)
- xmax = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymin1");
- if (tmp != null)
- ymin1 = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymax1");
- if (tmp != null)
- ymax1 = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymin2");
- if (tmp != null)
- ymin2 = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymax2");
- if (tmp != null)
- ymax2 = Double.parseDouble(tmp);
+ Your properties may include:
+ title = Plot
+ xlabel = size
+ ylabel = speed
+ label.file.data = legend text
+ width (output image width)
+ height (output image height)
+ xmin, xmax, ymin1, ymax1, ymin2, ymax2
+ (auto-selected if not given)
+ bw (Black and white, true/false, default false)
+ */
+ static void scanProperties()
+ {
+ String tmp;
+ tmp = properties.getProperty("width");
+ if (tmp != null)
+ width = Integer.parseInt(tmp.trim());
+ tmp = properties.getProperty("height");
+ if (tmp != null)
+ height = Integer.parseInt(tmp.trim());
+ tmp = properties.getProperty("xmin");
+ if (tmp != null)
+ xmin = Double.parseDouble(tmp);
+ tmp = properties.getProperty("xmax");
+ if (tmp != null)
+ xmax = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymin1");
+ if (tmp != null)
+ ymin1 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymax1");
+ if (tmp != null)
+ ymax1 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymin2");
+ if (tmp != null)
+ ymin2 = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymax2");
+ if (tmp != null)
+ ymax2 = Double.parseDouble(tmp);
- tmp = properties.getProperty("bw");
- if (tmp != null)
- bw = Boolean.parseBoolean(tmp);
- }
+ tmp = properties.getProperty("bw");
+ if (tmp != null)
+ bw = Boolean.parseBoolean(tmp);
+ }
- /**
- Arrays.copyOfRange is a Java 1.6 feature.
- This has the same signature.
- */
- /*
- static String[] select(String[] s, int p, int q)
- {
- String[] result = new String[q-p];
- int j = 0;
- for (int i = p; i < q; i++)
+ /**
+ Arrays.copyOfRange is a Java 1.6 feature.
+ This has the same signature.
+ */
+ /*
+ static String[] select(String[] s, int p, int q)
+ {
+ String[] result = new String[q-p];
+ int j = 0;
+ for (int i = p; i < q; i++)
result[j++] = s[i];
- return result;
- }
- */
+ return result;
+ }
+ */
- static void addLabel(String name,
- List<String> labels)
- {
- String label = properties.getProperty("label."+name);
- if (label == null)
- label = "";
- labels.add(label);
- }
+ static void addLabel(String name,
+ List<String> labels)
+ {
+ String label = properties.getProperty("label."+name);
+ if (label == null)
+ label = "";
+ labels.add(label);
+ }
- static boolean showShape(String name)
- {
- // System.out.println(name);
- String mode = properties.getProperty("shape."+name);
- // System.out.println(mode);
- if ("none".equals(mode))
- return false;
- return true;
- }
+ static boolean showShape(String name)
+ {
+ // System.out.println(name);
+ String mode = properties.getProperty("shape."+name);
+ // System.out.println(mode);
+ if ("none".equals(mode))
+ return false;
+ return true;
+ }
- static String toString(double[][] array)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < array.length; i++)
+ static String toString(double[][] array)
{
- double[] row = array[i];
- for (int j = 0; j < row.length; j++)
- {
- sb.append(array[i][j]);
- if (j < row.length-1)
- sb.append(" ");
- }
- sb.append("\n");
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length; i++)
+ {
+ double[] row = array[i];
+ for (int j = 0; j < row.length; j++)
+ {
+ sb.append(array[i][j]);
+ if (j < row.length-1)
+ sb.append(" ");
+ }
+ sb.append("\n");
+ }
+ return sb.toString();
}
- return sb.toString();
- }
}
Modified: usertools/plotter/src/plotter/LineReader.java
===================================================================
--- usertools/plotter/src/plotter/LineReader.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/LineReader.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -1,6 +1,7 @@
package plotter;
import java.util.*;
+import java.io.*;
/**
* Utility to read a file into a List of String lines.
@@ -11,148 +12,148 @@
* */
public class LineReader
{
- LineReader()
- {}
+ LineReader()
+ {}
- public static List<String> read(java.io.File file)
- throws java.io.FileNotFoundException
- {
- java.io.BufferedReader reader =
- new java.io.BufferedReader(new java.io.FileReader(file));
- return read(reader);
- }
+ public static List<String> read(File file)
+ throws FileNotFoundException
+ {
+ BufferedReader reader =
+ new BufferedReader(new FileReader(file));
+ return read(reader);
+ }
- public static List<String> read(String s)
- {
- java.io.BufferedReader reader =
- new java.io.BufferedReader(new java.io.StringReader(s));
- return read(reader);
- }
+ public static List<String> read(String s)
+ {
+ BufferedReader reader =
+ new BufferedReader(new StringReader(s));
+ return read(reader);
+ }
- public static List<String> read(java.io.BufferedReader reader)
- {
- List<String> result = new ArrayList<String>();
- try
+ public static List<String> read(BufferedReader reader)
{
- String prevline = "";
- String line = "";
- while ((line = reader.readLine()) != null)
- {
- int hash = line.indexOf("#");
- if (hash >= 0)
- line = line.substring(0,hash);
- line = spaces(line);
- line = (prevline + " " + line).trim();
- if (line.endsWith("\\"))
+ List<String> result = new ArrayList<String>();
+ try
{
- line = line.substring(0, line.length()-2);
- prevline = line;
- continue;
+ String prevline = "";
+ String line = "";
+ while ((line = reader.readLine()) != null)
+ {
+ int hash = line.indexOf("#");
+ if (hash >= 0)
+ line = line.substring(0,hash);
+ line = spaces(line);
+ line = (prevline + " " + line).trim();
+ if (line.endsWith("\\"))
+ {
+ line = line.substring(0, line.length()-2);
+ prevline = line;
+ continue;
+ }
+ else
+ {
+ prevline = "";
+ line = line.trim();
+ if (line.length() > 0)
+ result.add(line);
+ }
+ }
+ reader.close();
}
- else
+ catch (IOException e)
{
- prevline = "";
- line = line.trim();
- if (line.length() > 0)
- result.add(line);
+ System.err.println("LineReader: I/O problem.");
+ return null;
}
- }
- reader.close();
+ return result;
}
- catch (java.io.IOException e)
+
+ public static List<String[]> tokens(List<String> lines)
{
- System.out.println("LineReader: I/O problem.");
- return null;
+ List<String[]> result = new ArrayList<String[]>(lines.size());
+ for (String line : lines)
+ {
+ String[] tokens = tokenize(line);
+ result.add(tokens);
+ }
+ return result;
}
- return result;
- }
- public static List<String[]> tokens(List<String> lines)
- {
- List<String[]> result = new ArrayList<String[]>(lines.size());
- for (String line : lines)
+ public static int maxTokens(List<String[]> tokens)
{
- String[] tokens = tokenize(line);
- result.add(tokens);
+ int result = 0;
+ for (String[] t : tokens)
+ if (t.length > result)
+ result = t.length;
+ return result;
}
- return result;
- }
- public static int maxTokens(List<String[]> tokens)
- {
- int result = 0;
- for (String[] t : tokens)
- if (t.length > result)
- result = t.length;
- return result;
- }
+ /**
+ Take line-oriented data and produce an array of doubles.
+ */
+ public static double[][] array(List<String> lines)
+ {
+ List<String[]> tokens = tokens(lines);
+ int columns = maxTokens(tokens);
+ int rows = lines.size();
+ double[][] result = new double[rows][columns];
+ for (int i = 0; i < rows; i++)
+ for (int j = 0; j < columns; j++)
+ {
+ try
+ {
+ String v = tokens.get(i)[j];
+ double d = Double.parseDouble(v);
+ result[i][j] = d;
+ }
+ catch (NumberFormatException e)
+ {
+ throw new RuntimeException("Problem in row: " + i);
+ }
+ }
+ return result;
+ }
- /**
- Take line-oriented data and produce an array of doubles.
- */
- public static double[][] array(List<String> lines)
- {
- List<String[]> tokens = tokens(lines);
- int columns = maxTokens(tokens);
- int rows = lines.size();
- double[][] result = new double[rows][columns];
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < columns; j++)
- {
- try
+ public static String spaces(String line)
+ {
+ String result = "";
+ for (int i = 0; i < line.length(); i++)
{
- String v = tokens.get(i)[j];
- double d = Double.parseDouble(v);
- result[i][j] = d;
+ if (line.charAt(i) == '=' &&
+ line.charAt(i+1) != '=' &&
+ line.charAt(i-1) != '=')
+ {
+ result += " = ";
+ }
+ else
+ result += line.substring(i,i+1);
}
- catch (NumberFormatException e)
- {
- throw new RuntimeException("Problem in row: " + i);
- }
- }
- return result;
- }
+ return result;
+ }
- public static String spaces(String line)
- {
- String result = "";
- for (int i = 0; i < line.length(); i++)
+ public static String[] tokenize(String line)
{
- if (line.charAt(i) == '=' &&
- line.charAt(i+1) != '=' &&
- line.charAt(i-1) != '=')
- {
- result += " = ";
- }
- else
- result += line.substring(i,i+1);
+ if (line == null)
+ return null;
+ List<String> words = new ArrayList<String>();
+ String[] ws = line.split("\\s");
+ for (int i = 0; i < ws.length; i++)
+ if (ws[i].length() > 0)
+ words.add(ws[i]);
+ String[] result = new String[words.size()];
+ for (int i = 0; i < words.size(); i++)
+ result[i] = words.get(i);
+ return result;
}
- return result;
- }
- public static String[] tokenize(String line)
- {
- if (line == null)
- return null;
- List<String> words = new ArrayList<String>();
- String[] ws = line.split("\\s");
- for (int i = 0; i < ws.length; i++)
- if (ws[i].length() > 0)
- words.add(ws[i]);
- String[] result = new String[words.size()];
- for (int i = 0; i < words.size(); i++)
- result[i] = words.get(i);
- return result;
- }
-
- /*
- public static List<String> list(String line)
- {
- List<String> result = new ArrayList<String>();
- String[] tokens = tokenize(line);
- for (int i = 0; i < tokens.length; i++)
+ /*
+ public static List<String> list(String line)
+ {
+ List<String> result = new ArrayList<String>();
+ String[] tokens = tokenize(line);
+ for (int i = 0; i < tokens.length; i++)
result.add(tokens[i]);
- return result;
- }
- */
+ return result;
+ }
+ */
}
Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/Lines.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -24,326 +24,327 @@
* */
public class Lines
{
- static Properties properties;
+ static Properties properties;
- public static boolean bw = false;
+ public static boolean bw = false;
- static int width = 400;
- static int height = 400;
+ static int width = 400;
+ static int height = 400;
- // null indicates the value was not set by the user
- static Double xmin = null;
- static Double xmax = null;
- static Double ymin = null;
- static Double ymax = null;
+ // null indicates the value was not set by the user
+ static Double xmin = null;
+ static Double xmax = null;
+ static Double ymin = null;
+ static Double ymax = null;
- static boolean withLegend = true;
+ static boolean withLegend = true;
- /**
- Generate simple plot.
- @param collection The x,y data.
- @param title Plot title.
- @param xlabel X label text.
- @param ylabel Y label text.
- @param output EPS filename.
- */
- public static boolean plot(XYSeriesCollection collection,
- String title, String xlabel,
- String ylabel, String output)
- {
- EPSDocumentGraphics2D g2d = null;
- Rectangle2D.Double rectangle = null;
- OutputStream out = null;
-
- try
+ /**
+ Generate simple plot.
+ @param collection The x,y data.
+ @param title Plot title.
+ @param xlabel X label text.
+ @param ylabel Y label text.
+ @param output EPS filename.
+ @return true/false depending if the method completed without error or not
+ */
+ public static boolean plot(XYSeriesCollection collection,
+ String title, String xlabel,
+ String ylabel, String output)
{
- out = new FileOutputStream(output);
- out = new BufferedOutputStream(out);
+ EPSDocumentGraphics2D g2d = null;
+ Rectangle2D.Double rectangle = null;
+ OutputStream out = null;
- g2d = new EPSDocumentGraphics2D(false);
- g2d.setGraphicContext
- (new org.apache.xmlgraphics.java2d.GraphicContext());
+ try
+ {
+ out = new FileOutputStream(output);
+ out = new BufferedOutputStream(out);
- rectangle = new Rectangle2D.Double(0, 0, width, height);
+ g2d = new EPSDocumentGraphics2D(false);
+ g2d.setGraphicContext
+ (new org.apache.xmlgraphics.java2d.GraphicContext());
- g2d.setGraphicContext
- (new org.apache.xmlgraphics.java2d.GraphicContext());
- g2d.setupDocument(out, width, height);
- }
- catch (IOException e)
- {
- System.out.println("Problem with file: " + output);
- return false;
- }
+ rectangle = new Rectangle2D.Double(0, 0, width, height);
- JFreeChart chart =
- ChartFactory.createXYLineChart
- (title, xlabel, ylabel, collection,
- PlotOrientation.VERTICAL, withLegend, false, false);
+ g2d.setGraphicContext
+ (new org.apache.xmlgraphics.java2d.GraphicContext());
+ g2d.setupDocument(out, width, height);
+ }
+ catch (IOException e)
+ {
+ System.err.println("Problem with file: " + output);
+ return false;
+ }
- setupPlot(chart, collection);
- chart.draw(g2d, rectangle);
+ JFreeChart chart =
+ ChartFactory.createXYLineChart
+ (title, xlabel, ylabel, collection,
+ PlotOrientation.VERTICAL, withLegend, false, false);
- try
- {
- g2d.finish();
- }
- catch (Exception e)
- {
- System.out.println("Err!");
- }
+ setupPlot(chart, collection);
+ chart.draw(g2d, rectangle);
- IOUtils.closeQuietly(out);
- System.out.println("PLOTTED: " + output);
+ try
+ {
+ g2d.finish();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Err!" + e);
+ }
- return true;
- }
+ IOUtils.closeQuietly(out);
+ System.out.println("PLOTTED: " + output);
- private static void setupPlot(JFreeChart chart,
- XYSeriesCollection collection)
- {
- XYPlot plot = chart.getXYPlot();
- XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
- if (bw)
- for (int i = 0; i < plot.getSeriesCount(); i++)
- renderer.setSeriesPaint(i, Color.BLACK);
- for (int i = 0; i < plot.getSeriesCount(); i++)
- {
- Series series = collection.getSeries(i);
- if (! showShape(series.getDescription()))
- renderer.setSeriesShapesVisible(i, false);
+ return true;
}
- Plots.setupLegend(chart, properties);
- setAxes(plot);
- plot.setRenderer(renderer);
- plot.setBackgroundPaint(Color.WHITE);
- }
+ private static void setupPlot(JFreeChart chart,
+ XYSeriesCollection collection)
+ {
+ XYPlot plot = chart.getXYPlot();
+ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
+ if (bw)
+ for (int i = 0; i < plot.getSeriesCount(); i++)
+ renderer.setSeriesPaint(i, Color.BLACK);
+ for (int i = 0; i < plot.getSeriesCount(); i++)
+ {
+ Series series = collection.getSeries(i);
+ if (! showShape(series.getDescription()))
+ renderer.setSeriesShapesVisible(i, false);
+ }
- static void setAxes(XYPlot plot)
- {
- // Actual values: modify if necessary
- double axmin, axmax, aymin, aymax;
-
- if (xmin != null || xmax != null)
- {
- NumberAxis axis = (NumberAxis) plot.getDomainAxis();
- Range range = axis.getRange();
- axmin = range.getLowerBound();
- axmax = range.getUpperBound();
- if (xmin != null) axmin = xmin;
- if (xmax != null) axmax = xmax;
- axis.setRange(axmin, axmax);
+ Plots.setupLegend(chart, properties);
+ setAxes(plot);
+ plot.setRenderer(renderer);
+ plot.setBackgroundPaint(Color.WHITE);
}
- if (ymin != null || ymax != null)
+ static void setAxes(XYPlot plot)
{
- NumberAxis axis = (NumberAxis) plot.getRangeAxis();
- Range range = axis.getRange();
- aymin = range.getLowerBound();
- aymax = range.getUpperBound();
- if (ymin != null) aymin = ymin;
- if (ymax != null) aymax = ymax;
- axis.setRange(aymin, aymax);
- }
- }
+ // Actual values: modify if necessary
+ double axmin, axmax, aymin, aymax;
- /**
- Args: Lines <properties> <output file> <data file>*
- Reads settings from properties: see scanProperties()
- Produces EPS output file
- Data files are two-columns of numbers each -
- see LineReader.read() and LineReader.array()
- */
- public static void main(String[] args)
- {
- // Settings:
- boolean verbose = false;
+ if (xmin != null || xmax != null)
+ {
+ NumberAxis axis = (NumberAxis) plot.getDomainAxis();
+ Range range = axis.getRange();
+ axmin = range.getLowerBound();
+ axmax = range.getUpperBound();
+ if (xmin != null) axmin = xmin;
+ if (xmax != null) axmax = xmax;
+ axis.setRange(axmin, axmax);
+ }
- Getopt g = new Getopt("testprog", args, "v");
- int c = -1;
- while ((c = g.getopt()) != -1)
- {
- switch (c)
- {
- case 'v':
- verbose = true;
- }
+ if (ymin != null || ymax != null)
+ {
+ NumberAxis axis = (NumberAxis) plot.getRangeAxis();
+ Range range = axis.getRange();
+ aymin = range.getLowerBound();
+ aymax = range.getUpperBound();
+ if (ymin != null) aymin = ymin;
+ if (ymax != null) aymax = ymax;
+ axis.setRange(aymin, aymax);
+ }
}
- if (args.length < 3)
+ /**
+ Args: Lines <properties> <output file> <data file>*
+ Reads settings from properties: see scanProperties()
+ Produces EPS output file
+ Data files are two-columns of numbers each -
+ see LineReader.read() and LineReader.array()
+ */
+ public void plotter(String[] args)
{
- System.out.println
- ("usage: [<options>] <properties> <output> <data>*");
- System.exit(2);
- }
+ // Settings:
+ boolean verbose = false;
- Bits.init();
- Util.verbose(verbose);
+ Getopt g = new Getopt("testprog", args, "v");
+ int c = -1;
+ while ((c = g.getopt()) != -1)
+ {
+ switch (c)
+ {
+ case 'v':
+ verbose = true;
+ }
+ }
- String propFile = args[0];
- String output = args[1];
- List<String> names = new ArrayList<String>();
- for (int i = 2; i < args.length; i++)
- names.add(args[i]);
+ if (args.length < 3)
+ {
+ System.err.println
+ ("usage: [<options>] <properties> <output> <data>*");
+ System.exit(2);
+ }
- String title = null;
- String xlabel = null;
- String ylabel = null;
- List<double[][]> data = new ArrayList<double[][]>();
- List<String> labels = new ArrayList<String>();
+ Bits.init();
+ Util.verbose(verbose);
- properties = new Properties();
- load(propFile);
- title = properties.getProperty("title");
- xlabel = properties.getProperty("xlabel");
- ylabel = properties.getProperty("ylabel");
+ String propFile = args[0];
+ String output = args[1];
+ List<String> names = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++)
+ names.add(args[i]);
- scanProperties();
+ String title = null;
+ String xlabel = null;
+ String ylabel = null;
+ List<double[][]> data = new ArrayList<double[][]>();
+ List<String> labels = new ArrayList<String>();
- for (String name : names)
- {
- File file = new File(name);
- Util.verbose("open: " + file);
- List<String> lines = null;
- try
- {
- lines = LineReader.read(file);
- }
- catch (FileNotFoundException e)
- {
- System.out.println("not found: " + file);
- System.exit(1);
- }
- double[][] array = LineReader.array(lines);
- data.add(array);
- addLabel(name, labels);
- Util.verbose("array:\n" + toString(array));
- }
+ properties = new Properties();
+ load(propFile);
+ title = properties.getProperty("title");
+ xlabel = properties.getProperty("xlabel");
+ ylabel = properties.getProperty("ylabel");
- XYSeriesCollection collection = Util.collection(data, labels,
- names);
+ scanProperties();
- plot(collection, title, xlabel, ylabel, output);
- }
+ for (String name : names)
+ {
+ File file = new File(name);
+ Util.verbose("open: " + file);
+ List<String> lines = null;
+ try
+ {
+ lines = LineReader.read(file);
+ }
+ catch (FileNotFoundException e)
+ {
+ System.err.println("not found: " + file);
+ System.exit(1);
+ }
+ double[][] array = LineReader.array(lines);
+ data.add(array);
+ addLabel(name, labels);
+ Util.verbose("array:\n" + toString(array));
+ }
- static void load(String propFile)
- {
- try
- {
- if (propFile.equals("-"))
- properties.load(System.in);
- else
- properties.load(new FileInputStream(propFile));
+ XYSeriesCollection collection = Util.collection(data, labels,
+ names);
+
+ plot(collection, title, xlabel, ylabel, output);
}
- catch (FileNotFoundException e)
+
+ static void load(String propFile)
{
- System.out.println(e);
- System.exit(1);
+ try
+ {
+ if (propFile.equals("-"))
+ properties.load(System.in);
+ else
+ properties.load(new FileInputStream(propFile));
+ }
+ catch (FileNotFoundException e)
+ {
+ System.err.println(e);
+ System.exit(1);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ System.exit(1);
+ }
}
- catch (IOException e)
- {
- e.printStackTrace();
- System.exit(1);
- }
- }
- /**
- Various plot properties. All are currently optional
+ /**
+ Various plot properties. All are currently optional
- Example.
- Assume you want to plot a two-column table in file.data.
- The first column is the x values and the second column
- is the y values. See LineReader for details.
+ Example.
+ Assume you want to plot a two-column table in file.data.
+ The first column is the x values and the second column
+ is the y values. See LineReader for details.
- Your properties may include:
- title = Plot
- xlabel = size
- ylabel = speed
- label.file.data = legend text
- width (output image width)
- height (output image height)
- xmin, xmax, ymin, ymax (auto-selected if not given)
- bw (Black and white, true/false, default false)
- legend.enabled (true/false, default true)
- */
- static void scanProperties()
- {
- String tmp;
- tmp = properties.getProperty("width");
- if (tmp != null)
- width = Integer.parseInt(tmp.trim());
- tmp = properties.getProperty("height");
- if (tmp != null)
- height = Integer.parseInt(tmp.trim());
- tmp = properties.getProperty("xmin");
- if (tmp != null)
- xmin = Double.parseDouble(tmp);
- tmp = properties.getProperty("xmax");
- if (tmp != null)
- xmax = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymin");
- if (tmp != null)
- ymin = Double.parseDouble(tmp);
- tmp = properties.getProperty("ymax");
- if (tmp != null)
- ymax = Double.parseDouble(tmp);
- tmp = properties.getProperty("bw");
- if (tmp != null)
- bw = Boolean.parseBoolean(tmp);
- tmp = properties.getProperty("legend.enabled");
- if (tmp != null)
- withLegend = Boolean.parseBoolean(tmp);
- }
+ Your properties may include:
+ title = Plot
+ xlabel = size
+ ylabel = speed
+ label.file.data = legend text
+ width (output image width)
+ height (output image height)
+ xmin, xmax, ymin, ymax (auto-selected if not given)
+ bw (Black and white, true/false, default false)
+ legend.enabled (true/false, default true)
+ */
+ static void scanProperties()
+ {
+ String tmp;
+ tmp = properties.getProperty("width");
+ if (tmp != null)
+ width = Integer.parseInt(tmp.trim());
+ tmp = properties.getProperty("height");
+ if (tmp != null)
+ height = Integer.parseInt(tmp.trim());
+ tmp = properties.getProperty("xmin");
+ if (tmp != null)
+ xmin = Double.parseDouble(tmp);
+ tmp = properties.getProperty("xmax");
+ if (tmp != null)
+ xmax = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymin");
+ if (tmp != null)
+ ymin = Double.parseDouble(tmp);
+ tmp = properties.getProperty("ymax");
+ if (tmp != null)
+ ymax = Double.parseDouble(tmp);
+ tmp = properties.getProperty("bw");
+ if (tmp != null)
+ bw = Boolean.parseBoolean(tmp);
+ tmp = properties.getProperty("legend.enabled");
+ if (tmp != null)
+ withLegend = Boolean.parseBoolean(tmp);
+ }
- /**
- Arrays.copyOfRange is a Java 1.6 feature.
- This has the same signature.
- */
- /*
- static String[] select(String[] s, int p, int q)
- {
- String[] result = new String[q-p];
- int j = 0;
- for (int i = p; i < q; i++)
+ /**
+ Arrays.copyOfRange is a Java 1.6 feature.
+ This has the same signature.
+ */
+ /*
+ static String[] select(String[] s, int p, int q)
+ {
+ String[] result = new String[q-p];
+ int j = 0;
+ for (int i = p; i < q; i++)
result[j++] = s[i];
- return result;
- }
- */
+ return result;
+ }
+ */
- static void addLabel(String name,
- List<String> labels)
- {
- String label = properties.getProperty("label."+name);
- if (label == null)
- label = "";
- labels.add(label);
- }
+ static void addLabel(String name,
+ List<String> labels)
+ {
+ String label = properties.getProperty("label."+name);
+ if (label == null)
+ label = "";
+ labels.add(label);
+ }
- static boolean showShape(String name)
- {
- // System.out.println(name);
- String mode = properties.getProperty("shape."+name);
- // System.out.println(mode);
- if ("none".equals(mode))
- return false;
- return true;
- }
+ static boolean showShape(String name)
+ {
+ // System.out.println(name);
+ String mode = properties.getProperty("shape."+name);
+ // System.out.println(mode);
+ if ("none".equals(mode))
+ return false;
+ return true;
+ }
- static String toString(double[][] array)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < array.length; i++)
+ static String toString(double[][] array)
{
- double[] row = array[i];
- for (int j = 0; j < row.length; j++)
- {
- sb.append(array[i][j]);
- if (j < row.length-1)
- sb.append(" ");
- }
- sb.append("\n");
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length; i++)
+ {
+ double[] row = array[i];
+ for (int j = 0; j < row.length; j++)
+ {
+ sb.append(array[i][j]);
+ if (j < row.length-1)
+ sb.append(" ");
+ }
+ sb.append("\n");
+ }
+ return sb.toString();
}
- return sb.toString();
- }
}
Modified: usertools/plotter/src/plotter/Plots.java
===================================================================
--- usertools/plotter/src/plotter/Plots.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/Plots.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -13,22 +13,22 @@
*/
public class Plots
{
- static void setupLegend(JFreeChart chart,
- Properties properties)
- {
- LegendTitle legend = chart.getLegend();
- Font font = getLegendFont(properties);
- if (font != null)
- legend.setItemFont(font);
- }
+ static void setupLegend(JFreeChart chart,
+ Properties properties)
+ {
+ LegendTitle legend = chart.getLegend();
+ Font font = getLegendFont(properties);
+ if (font != null)
+ legend.setItemFont(font);
+ }
- static Font getLegendFont(Properties properties)
- {
- Font result = null;
- String name = properties.getProperty("legend.font");
- if (name == null)
- return null;
- result = new Font(name, Font.PLAIN, 12);
- return result;
- }
+ static Font getLegendFont(Properties properties)
+ {
+ Font result = null;
+ String name = properties.getProperty("legend.font");
+ if (name == null)
+ return null;
+ result = new Font(name, Font.PLAIN, 12);
+ return result;
+ }
}
Added: usertools/plotter/src/plotter/Plotter.java
===================================================================
--- usertools/plotter/src/plotter/Plotter.java (rev 0)
+++ usertools/plotter/src/plotter/Plotter.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -0,0 +1,46 @@
+package plotter;
+
+import plotter.Lines;
+import plotter.Dual;
+
+public class Plotter
+{
+ public static void main(String[] args)
+ {
+ if (args.length < 4 )
+ {
+ usage();
+ }
+
+ /* Gather the arguments except the first one */
+ String[] tmp = new String[args.length - 1];
+ for( int i = 0; i < tmp.length; ++i )
+ {
+ tmp[i] = args[i+1];
+ }
+
+ /* If asking for a single labeled Y-axis */
+ if (args[0].equalsIgnoreCase( "-s" ))
+ {
+ Lines l = new Lines();
+ l.plotter(tmp);
+ }
+ /* If asking for a dual labeled Y-axis */
+ else if (args[0].equalsIgnoreCase( "-d" ))
+ {
+ Dual d = new Dual();
+ d.plotter(tmp);
+ }
+ /* Do not understand option for what graph */
+ else
+ {
+ usage();
+ }
+ }
+
+ public static void usage()
+ {
+ System.err.println( "usage: [-s,-d] [<options>] <properties> <output> <data>*" );
+ System.exit(2);
+ }
+}
Modified: usertools/plotter/src/plotter/Util.java
===================================================================
--- usertools/plotter/src/plotter/Util.java 2011-06-17 02:19:13 UTC (rev 4627)
+++ usertools/plotter/src/plotter/Util.java 2011-06-17 19:28:46 UTC (rev 4628)
@@ -11,54 +11,54 @@
public class Util
{
- static boolean v = false;
+ static boolean v = false;
- /**
- Stores the label as the Series key.
- Stores the filename as the Series description.
- */
- static XYSeriesCollection collection(List<double[][]> data,
- List<String> labels,
- List<String> names)
- {
- final XYSeriesCollection collection = new XYSeriesCollection();
-
- int count = 0;
- for (double[][] d : data)
+ /**
+ Stores the label as the Series key.
+ Stores the filename as the Series description.
+ */
+ static XYSeriesCollection collection(List<double[][]> data,
+ List<String> labels,
+ List<String> names)
{
- String label = "data: " + count;
- try
- {
- label = labels.get(count);
- }
- catch (IndexOutOfBoundsException e)
- {}
+ final XYSeriesCollection collection = new XYSeriesCollection();
- XYSeries series = new XYSeries(label);
- for (int i = 0; i < d.length; i++)
- series.add(d[i][0], d[i][1]);
+ int count = 0;
+ for (double[][] d : data)
+ {
+ String label = "data: " + count;
+ try
+ {
+ label = labels.get(count);
+ }
+ catch (IndexOutOfBoundsException e)
+ {}
- series.setDescription(names.get(count));
- collection.addSeries(series);
- count++;
+ XYSeries series = new XYSeries(label);
+ for (int i = 0; i < d.length; i++)
+ series.add(d[i][0], d[i][1]);
+
+ series.setDescription(names.get(count));
+ collection.addSeries(series);
+ count++;
+ }
+ return collection;
}
- return collection;
- }
- public static void fatal(String s)
- {
- System.out.println(s);
- System.exit(2);
- }
+ public static void fatal(String s)
+ {
+ System.err.println(s);
+ System.exit(2);
+ }
- public static void verbose(String s)
- {
- if (v)
- System.out.println(s);
- }
+ public static void verbose(String s)
+ {
+ if (v)
+ System.out.println(s);
+ }
- public static void verbose(boolean status)
- {
- v = status;
- }
+ public static void verbose(boolean status)
+ {
+ v = status;
+ }
}
Added: usertools/plotter/swift_plotter.zsh
===================================================================
--- usertools/plotter/swift_plotter.zsh (rev 0)
+++ usertools/plotter/swift_plotter.zsh 2011-06-17 19:28:46 UTC (rev 4628)
@@ -0,0 +1,10 @@
+#!/bin/zsh
+
+PLOTTERS=$( cd $( dirname $0 ) ; /bin/pwd )
+
+# declare -p PLOTTERS
+
+source ${PLOTTERS}/classpath.zsh
+[[ $? != 0 ]] && print "Could not build CLASSPATH!" && return 1
+
+java -ea -cp ${CP} plotter.Plotter ${*}
Property changes on: usertools/plotter/swift_plotter.zsh
___________________________________________________________________
Added: svn:executable
+ *
More information about the Swift-commit
mailing list