📄 gnuplotoperator.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* web: http://yale.cs.uni-dortmund.de/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package edu.udo.cs.yale.operator.io;
import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.IOObject;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.UserError;
import edu.udo.cs.yale.Statistics;
import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.tools.LogService;
import java.util.List;
import java.io.*;
/** Writes the data generated by a {@link edu.udo.cs.yale.operator.ExperimentLogOperator} to a file in gnuplot
* format to a file.
* The property <code>yale.tools.gnuplot.command</code> should be set to the complete
* path of the gnuplot executable, though this is not necessary, since gnuplot is not
* invoked.
*
* @version $Id: GNUPlotOperator.java,v 1.3 2004/08/27 11:57:37 ingomierswa Exp $
*/
public class GNUPlotOperator extends Operator {
public Class[] getInputClasses() { return new Class[0]; }
public Class[] getOutputClasses() { return new Class[0]; }
public IOObject[] apply() throws OperatorException {
String statisticsName = getParameterAsString("name");
if (!getExperiment().statisticsExist(statisticsName)) {
LogService.logMessage("Statistics with name '" + statisticsName + "' does not exist.",
LogService.ERROR);
return new IOObject[0];
}
Statistics statistics = getExperiment().getStatistics(statisticsName);
String[] valueNames = getParameterAsString("values").split(" ");
int[] values = new int[valueNames.length];
for (int i = 0; i < values.length; i++) {
values[i] = statistics.getColumnIndex(valueNames[i]);
if (values[i] == -1) {
LogService.logMessage(getName()+": No data column with name '" + valueNames[i] + "' exists.",
LogService.ERROR);
return new IOObject[0];
}
}
String xAxisName = getParameterAsString("x_axis");
int xAxis = statistics.getColumnIndex(xAxisName);
if (xAxis == -1) {
LogService.logMessage("No data column with name '" + xAxisName + "' exists.", LogService.ERROR);
return new IOObject[0];
}
String yAxisName = getParameterAsString("y_axis");
int yAxis = -1;
if (yAxisName != null) {
yAxis = statistics.getColumnIndex(yAxisName);
if (yAxis == -1) {
LogService.logMessage("No data column with name '" + yAxisName + "' exists.", LogService.ERROR);
return new IOObject[0];
}
}
String additional = "";
if (isParameterSet("title")) additional += "set title \""+getParameterAsString("title")+"\"\n";
if (isParameterSet("additional_parameters"))
additional += getParameterAsString("additional_parameters");
try {
File file = getExperiment().createFile(getParameterAsString("output_file"));
LogService.logMessage("Creating gnuplot file '"+file+"'", LogService.MINIMUM);
PrintStream out = new PrintStream(new FileOutputStream(file));
statistics.writeGNUPlot(out, xAxis, yAxis, values, "linespoints", additional, null);
out.close();
} catch (IOException e) {
LogService.logMessage("Cannot create output file: " + e.getMessage(), LogService.ERROR);
return new IOObject[0];
}
return new IOObject[0];
}
public List getParameterTypes() {
List types = super.getParameterTypes();
types.add(new ParameterTypeFile("output_file", "The gnuplot file.", false));
types.add(new ParameterTypeString("name", "The name of the experiment log operator which produced the statistics.", false));
types.add(new ParameterTypeString("title", "The title of the plot.", "Created by Yale"));
types.add(new ParameterTypeString("x_axis", "The values of the x-axis.", false));
ParameterType type = new ParameterTypeString("y_axis", "The values of the y-axis (for 3d plots).", true);
type.setExpert(false);
types.add(type);
types.add(new ParameterTypeString("values", "A whitespace separated list of values which should be plotted.", false));
types.add(new ParameterTypeString("additional_parameters", "Additional parameters for the gnuplot header.", true));
return types;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -