com.github.javacliparser.StringOption Java Examples

The following examples show how to use com.github.javacliparser.StringOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Plot.java    From moa with GNU General Public License v3.0 4 votes vote down vote up
@Override
   protected Object doMainTask(TaskMonitor monitor, ObjectRepository repository) {
File resultFile = this.plotOutputOption.getFile();
if (this.plotOutputOption.getFile() == null) {
    throw new RuntimeException("Plot output file option not set!");
}

String resultDirectory = (new File(resultFile.getAbsolutePath()))
	.getParent();
String gnuPlotPath = gnuplotPathOption.getValue();
File gnuplotDir = new File(gnuPlotPath);
if(!gnuplotDir.exists()){
    throw new RuntimeException("Gnuplot directory not found: " + gnuPlotPath);
}

monitor.setCurrentActivity("Verifying input files...", 0.0);

if (inputFilesOption.getList().length > fileAliasesOption.getList().length) {
    throw new RuntimeException("Too little aliases for input files!");
} else if (inputFilesOption.getList().length < fileAliasesOption
	.getList().length) {
    throw new RuntimeException("Too many aliases for input files!");
} else {
    for (int i = 0; i < inputFilesOption.getList().length; i++) {
	File inputFile = new File(((StringOption) inputFilesOption
		.getList()[i]).getValue());

	if (!inputFile.exists()) {
	    throw new RuntimeException("File not found: "
		    + inputFile.getAbsolutePath());
	}
    }
}

if (monitor.taskShouldAbort()) {
    return null;
}
monitor.setCurrentActivity("Creating script file...", 1.0 / 4.0);

String gnuplotScriptPath = resultDirectory + File.separator
	+ resultFile.getName() + ".plt";
String script = createScript(resultFile);
File scriptFile = writeScriptToFile(gnuplotScriptPath, script);

if (monitor.taskShouldAbort()) {
    return null;
}
monitor.setCurrentActivity("Plotting data...", 2.0 / 4.0);

String gnuplotCommand = gnuPlotPath + File.separator + "gnuplot \""
	+ gnuplotScriptPath + "\"";

String line, gnuplotOutput = "";
try {
    Process p = Runtime.getRuntime().exec(gnuplotCommand);

    BufferedReader err = new BufferedReader(new InputStreamReader(p
	    .getErrorStream()));
    while ((line = err.readLine()) != null) {
	gnuplotOutput += line + System.getProperty("line.separator");
    }
    err.close();
} catch (IOException ex) {
    throw new RuntimeException("Error while executing gnuplot script:"
	    + scriptFile, ex);
}

if (monitor.taskShouldAbort()) {
    return null;
}
if (deleteScriptsOption.isSet()) {
    monitor.setCurrentActivity("Deleting script...", 3.0 / 4.0);
    scriptFile.delete();
}
if (monitor.taskShouldAbort()) {
    return null;
}
monitor.setCurrentActivity("Done", 1.0);

return resultFile.getAbsolutePath()
	+ System.getProperty("line.separator") + gnuplotOutput;
   }
 
Example #2
Source File: Plot.java    From moa with GNU General Public License v3.0 4 votes vote down vote up
/**
    * Creates the content of the gnuplot script.
    * @param resultFile path of the plot output file
    * @return gnuplot script
    */
   private String createScript(File resultFile) {
String newLine = System.getProperty("line.separator");
int sourceFileIdx = 0;

// terminal options;
String script = "set term "
	+ terminalOptions(Terminal.valueOf(outputTypeOption
		.getChosenLabel())) + newLine;
script += "set output '" + resultFile.getAbsolutePath() + "'" + newLine;
script += "set datafile separator ','" + newLine;
script += "set grid" + newLine;
script += "set style line 1 pt 8" + newLine;
script += "set style line 2 lt rgb '#00C000'" + newLine;
script += "set style line 5 lt rgb '#FFD800'" + newLine;
script += "set style line 6 lt rgb '#4E0000'" + newLine;
script += "set format x '%.0s %c" + getAxisUnit(xUnitOption.getValue())
	+ "'" + newLine;
script += "set format y '%.0s %c" + getAxisUnit(yUnitOption.getValue())
	+ "'" + newLine;
script += "set ylabel '" + yTitleOption.getValue() + "'" + newLine;
script += "set xlabel '" + xTitleOption.getValue() + "'" + newLine;
if (!legendTypeOption.getChosenLabel().equals(LegendType.NONE)) {
    script += "set key "
	    + legendTypeOption.getChosenLabel().toLowerCase().replace(
		    '_', ' ')
	    + " "
	    + legendLocationOption.getChosenLabel().toLowerCase()
		    .replace('_', ' ') + newLine;
}

// additional commands
script += additionalSetOption.getValue();

// plot command
script += "plot " + additionalPlotOption.getValue() + " ";

// plot for each input file
for (int i = 0; i < inputFilesOption.getList().length; i++) {
	
    if (sourceFileIdx > 0) {
	script += ", ";
    }
    sourceFileIdx++;
    script += "'" + ((StringOption) inputFilesOption
		.getList()[i]).getValue() + "' using "
	    + xColumnOption.getValue() + ":" + yColumnOption.getValue();

    if (smoothOption.isSet()) {
	script += ":(1.0) smooth bezier";
    }

    script += " with " + plotStyleOption.getChosenLabel().toLowerCase()
	    + " ls " + sourceFileIdx + " lw "
	    + lineWidthOption.getValue();
    if (plotStyleOption.getChosenLabel().equals(
	    PlotStyle.LINESPOINTS.toString())
	    && pointIntervalOption.getValue() > 0) {
	script += " pointinterval " + pointIntervalOption.getValue();
    }
    script += " title '" + ((StringOption) fileAliasesOption
		.getList()[i]).getValue() + "'";
}
script += newLine;
return script;
   }