[Swift-commit] r7588 - usertools/plotter/src/plotter
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Tue Feb 11 16:16:07 CST 2014
Author: wozniak
Date: 2014-02-11 16:16:06 -0600 (Tue, 11 Feb 2014)
New Revision: 7588
Added:
usertools/plotter/src/plotter/LineReaderException.java
Modified:
usertools/plotter/src/plotter/LineReader.java
usertools/plotter/src/plotter/Lines.java
Log:
Better error handling
Modified: usertools/plotter/src/plotter/LineReader.java
===================================================================
--- usertools/plotter/src/plotter/LineReader.java 2014-02-11 22:02:39 UTC (rev 7587)
+++ usertools/plotter/src/plotter/LineReader.java 2014-02-11 22:16:06 UTC (rev 7588)
@@ -88,14 +88,21 @@
/**
Take line-oriented data and produce an array of doubles.
+ * @throws LineReaderException
+
*/
public static double[][] array(List<String> lines)
+ throws LineReaderException
{
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++)
+ {
+ String[] row = tokens.get(i);
+ if (row.length < columns)
+ throw new LineReaderException("Short row: " + i);
for (int j = 0; j < columns; j++)
{
try
@@ -108,9 +115,10 @@
}
catch (NumberFormatException e)
{
- throw new RuntimeException("Problem in row: " + i);
+ throw new LineReaderException("Bad number in row: " + i);
}
}
+ }
return result;
}
Added: usertools/plotter/src/plotter/LineReaderException.java
===================================================================
--- usertools/plotter/src/plotter/LineReaderException.java (rev 0)
+++ usertools/plotter/src/plotter/LineReaderException.java 2014-02-11 22:16:06 UTC (rev 7588)
@@ -0,0 +1,10 @@
+
+package plotter;
+
+public class LineReaderException extends Exception
+{
+ public LineReaderException(String msg)
+ {
+ super(msg);
+ }
+}
Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java 2014-02-11 22:02:39 UTC (rev 7587)
+++ usertools/plotter/src/plotter/Lines.java 2014-02-11 22:16:06 UTC (rev 7588)
@@ -103,11 +103,25 @@
scanProperties();
+ readDataFiles(names, data, labels);
+
+ XYSeriesCollection collection =
+ collection(data, labels, names);
+
+ plot(collection, title, xlabel, ylabel, output);
+ }
+
+ static void readDataFiles(List<String> names,
+ List<double[][]> data,
+ List<String> labels)
+ throws UserInputException
+ {
for (String name : names)
{
File file = new File(name);
Util.verbose("open: " + file);
List<String> lines = null;
+ double[][] array;
try
{
lines = LineReader.read(file);
@@ -116,26 +130,28 @@
{
System.err.println("Problem when reading: "+file);
}
+ array = LineReader.array(lines);
}
catch (FileNotFoundException e)
{
- System.err.println("not found: " + file);
- System.exit(1);
+ throw new UserInputException("not found: " + file);
}
- double[][] array = LineReader.array(lines);
+ catch (LineReaderException e)
+ {
+ throw new UserInputException
+ (e.getMessage() + "\n" + "In file: " + file);
+ }
+
if (array.length == 0)
- throw new UserInputException("file has no data: " + name);
+ throw new UserInputException
+ ("file has no data: " + name);
if (array[0].length != 2)
- throw new UserInputException("file is not two-column: " + name);
+ throw new UserInputException
+ ("file is not two-column: " + name);
data.add(array);
addLabel(name, labels);
Util.verbose("array:\n" + toString(array));
}
-
- XYSeriesCollection collection = collection(data, labels,
- names);
-
- plot(collection, title, xlabel, ylabel, output);
}
/**
More information about the Swift-commit
mailing list