⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnuplotoperator.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  YALE - Yet Another Learning Environment *  Copyright (C) 2002, 2003 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,  *          Katharina Morik, Oliver Ritthoff *      Artificial Intelligence Unit *      Computer Science Department *      University of Dortmund *      44221 Dortmund,  Germany *  email: yale@ls8.cs.uni-dortmund.de *  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;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 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 2.2 2003/08/21 15:18:17 fischer 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("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, 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));	types.add(new ParameterTypeString("y_axis", "The values of the y-axis (for 3d plots).", true));	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 + -