edu.ull.cgunay.plots
Class Grapher

java.lang.Object
  |
  +--edu.ull.cgunay.plots.Grapher
Direct Known Subclasses:
GNUPlot, MatLab

public abstract class Grapher
extends Object

Represents the active Grapher process and its capabilities. The methods defined in this class are generic or abstract if it is not possible to generalize them.

Returns string representations for various operations according to the grapher platform. Each of the classes extending this class specifies such a platform.

In order to create a plot the usage is as follows:

Grapher g = new ...();
Plot p = new ...();
g.display(p);

Created: Mon Apr 8 17:12:23 2002

Modified: $Date: 2003/03/21 05:10:57 $

Version:
v2.0, and $Revision: 1.19 $ for this file.
Author:
Cengiz Gunay
See Also:
Plot

Nested Class Summary
protected  class Grapher.Axis
          An object that represent a data axis for the grapher.
(package private)  class Grapher.Data
          Each dataset that can be added to an Axis.
protected  class Grapher.DataType
          Type of representation for the data.
 class Grapher.ErrorData
          For errorbar plots.
protected  class Grapher.MultiAxes
          An object that combines multiple axes.
 class Grapher.PreciseProfileData
          Data structure for generating profile plots.
 class Grapher.ProfileData
          Data structure for generating profile plots, where the precision can be defined as the total number of points on the plot.
 class Grapher.VerticalBar
          For drawing a vertical bar on the x-axis.
 
Field Summary
protected  Hashtable dataTypes
          Hash to hold name->datatype values for a grapher.
(package private)  BufferedReader err
          Reader of the error stream of the grapher process.
(package private)  BufferedReader msg
          Reader of the output stream of the grapher process.
 PrintWriter out
          The output stream that is connected to the grapher process.
(package private)  int points
          Number of points on the graph, default is 100.
(package private)  Process process
          The runtime process of the spawned grapher program.
protected  int windowNumber
          The number of the window in which the plot will appear.
 
Constructor Summary
(package private) Grapher(String processName)
          Spawns a grapher process (used from subclasses).
 
Method Summary
 String add(String a, String b)
          Returns a String that adds two parameters for the Grapher.
 String assign(String var, String value)
          Returns a String that assigns a value to a variable for the Grapher.
 void close()
          Kills the grapher process.
 String command(String line)
          Properly terminate a grapher command with end-of-line separator.
abstract  Grapher.Axis createAxis()
          Factory method fro creating Axis instances.
abstract  Grapher.MultiAxes createMultiAxes(Grapher.Axis[] axes)
          Factory method fro creating MultiAxes instances.
abstract  Grapher.MultiAxes createMultiAxes(List axes)
          Factory method fro creating MultiAxes instances.
abstract  String def_func(String name, String[] params, String body)
          Returns a String that defines a function for the Grapher.
 PlotHandle display(Plot plot, PrintStream out)
          Displays the plot generated from the given plot description.
 String div(String a, String b)
          Returns a String that divides two parameters for the Grapher.
 String exp(String a)
          Returns a String that takes the exponential of the parameter for the Grapher.
 String func(String name, String[] params)
          Returns a String that calls a predefined function with given arguments for the Grapher.
 String geq(String a, String b)
          Returns a String that is a greater or equal conditional expression for the Grapher.
 int getPoints()
          Get the value of points.
 String mul(String a, String b)
          Returns a String that multiplies two parameters for the Grapher.
abstract  PlotHandle multiPlot(Collection plots, PrintStream out)
          Multiple plots in the same window, arranged one on top of the other with same range.
 PlotHandle multiPlot(Plot[] plots, PrintStream out)
           
 String neg(String a)
          Returns a String that negates the parameter for the Grapher.
 String paren(String a)
          Returns a String that parenthesizes the parameter for the Grapher.
abstract  String plotToString(SimplePlot plot)
          Deprecated.  
abstract  String plotToString(SpikePlot plot)
          Deprecated.  
abstract  String plotToStringAlt(Plot plot)
          When defined, should call plot.recipe.
 String profile(Profile profile, Range range)
          Returns a string representation of a Profile for a given Range.
 String quote(String value)
          Quotes the given string.
 String range(Range range)
          Returns a String that gives a range for the Grapher.
 String response()
          Returns the standard and error outputs of the process if available.
 void setPoints(int v)
          Set the value of points.
abstract  void setWindow(int windowNumber)
          Sets the current plot window according to grapher platform.
 String sub(String a, String b)
          Returns a String that subtracts two parameters for the Grapher.
abstract  PlotHandle superposedPlot(String title, Collection plots, PrintStream out)
          Multiple datasets on the same axis.
 PlotHandle superposedPlot(String title, Plot[] plots, PrintStream out)
           
(package private)  String variable(String name)
          Returns a String that represents the given variable for the Grapher.
 void waitForResponse()
          Wait until a response comes from either the output or error streams of the process.
abstract  void writeEPS(PlotHandle handle, String filename)
          Exports an EPS file of the previously visualized (required) plot.
abstract  void writeEPSbw(PlotHandle handle, String filename)
          Exports a black-n-white EPS file of the previously visualized (required) plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

process

Process process
The runtime process of the spawned grapher program.

See Also:
GNUPlot, MatLab

out

public PrintWriter out
The output stream that is connected to the grapher process.


msg

BufferedReader msg
Reader of the output stream of the grapher process.


err

BufferedReader err
Reader of the error stream of the grapher process.


points

int points
Number of points on the graph, default is 100.


windowNumber

protected int windowNumber
The number of the window in which the plot will appear.


dataTypes

protected Hashtable dataTypes
Hash to hold name->datatype values for a grapher.

Constructor Detail

Grapher

Grapher(String processName)
  throws GrapherNotAvailableException
Spawns a grapher process (used from subclasses).

Parameters:
processName - the string to be executed
Throws:
GrapherNotAvailableException - cannot connect process or streams
Method Detail

getPoints

public int getPoints()
Get the value of points.

Returns:
value of points.

setPoints

public void setPoints(int v)
Set the value of points.

Parameters:
v - Value to assign to points.

profile

public String profile(Profile profile,
                      Range range)
Returns a string representation of a Profile for a given Range. Most of the time it should be in the form of ((t>t1)*v1 + (t>t2)*(v2-v1) + ... ) where t is the variable denoting time, and (t1,v1) is a pair found in the profile. See specific implementations for more information. It is an error if the Profilable entity does not meaningfully define its doubleValue() method, that is converted to a simple double value.

Parameters:
profile - a Profile value
range - a Range value
Returns:
a String value
See Also:
Profilable.doubleValue()

plotToString

public abstract String plotToString(SimplePlot plot)
Deprecated.  

Generic plot that calls Plot.body() as the body.

Parameters:
plot - a Plot value
Returns:
a String value
See Also:
SimplePlot.body()

plotToString

public abstract String plotToString(SpikePlot plot)
Deprecated.  

Returns a String representation of a spike plot for the Grapher.

Parameters:
plot - a SpikePlot value
Returns:
a String value

plotToStringAlt

public abstract String plotToStringAlt(Plot plot)
When defined, should call plot.recipe.

Parameters:
plot - a Plot value
Returns:
a String value

multiPlot

public PlotHandle multiPlot(Plot[] plots,
                            PrintStream out)
Parameters:
plots - a Plot[] value
out - a PrintStream value
Returns:
a String value
See Also:
multiPlot(Collection,PrintStream)

multiPlot

public abstract PlotHandle multiPlot(Collection plots,
                                     PrintStream out)
Multiple plots in the same window, arranged one on top of the other with same range. Implemented separately for each grapher.

Parameters:
plots - a Collection value
out - a PrintStream value
Returns:
a String value
See Also:
GNUPlot.multiPlot(java.util.Collection, java.io.PrintStream), MatLab.multiPlot(java.util.Collection, java.io.PrintStream)

superposedPlot

public PlotHandle superposedPlot(String title,
                                 Plot[] plots,
                                 PrintStream out)
Parameters:
title - a String value
plots - a Plot[] value
out - a PrintStream value
Returns:
a PlotHandle value
See Also:
superposedPlot(String,Collection,PrintStream)

superposedPlot

public abstract PlotHandle superposedPlot(String title,
                                          Collection plots,
                                          PrintStream out)
Multiple datasets on the same axis.

Parameters:
title - a String value
plots - a Collection value
out - a PrintStream value
Returns:
a PlotHandle value

createAxis

public abstract Grapher.Axis createAxis()
Factory method fro creating Axis instances.

Returns:
an Axis subclass instance for the given grapher.

createMultiAxes

public abstract Grapher.MultiAxes createMultiAxes(Grapher.Axis[] axes)
Factory method fro creating MultiAxes instances.

Parameters:
axes - a Grapher.Axis[] value
Returns:
a Grapher.MultiAxes value

createMultiAxes

public abstract Grapher.MultiAxes createMultiAxes(List axes)
Factory method fro creating MultiAxes instances.

Parameters:
axes - a List of Grapher.Axis[] values
Returns:
a Grapher.MultiAxes value

variable

String variable(String name)
Returns a String that represents the given variable for the Grapher. By default it is "name".

Parameters:
name - a String value
Returns:
a String value

add

public String add(String a,
                  String b)
Returns a String that adds two parameters for the Grapher. By default it is "(a) + (b)".

Parameters:
a - a String value
b - a String value
Returns:
a String value

sub

public String sub(String a,
                  String b)
Returns a String that subtracts two parameters for the Grapher. by default it is add((a), neg(b)).

Parameters:
a - a String value
b - a String value
Returns:
a String value

mul

public String mul(String a,
                  String b)
Returns a String that multiplies two parameters for the Grapher. By default it is "(a) * (b)".

Parameters:
a - a String value
b - a String value
Returns:
a String value

geq

public String geq(String a,
                  String b)
Returns a String that is a greater or equal conditional expression for the Grapher. By default it is "(a) >= (b)".

Parameters:
a - a String value
b - a String value
Returns:
a String value

div

public String div(String a,
                  String b)
Returns a String that divides two parameters for the Grapher. By default it is "(a) / (b)".

Parameters:
a - a String value
b - a String value
Returns:
a String value

neg

public String neg(String a)
Returns a String that negates the parameter for the Grapher. By default it is "-(a)".

Parameters:
a - a String value
Returns:
a String value

exp

public String exp(String a)
Returns a String that takes the exponential of the parameter for the Grapher. By default it is "exp(a)".

Parameters:
a - a String value
Returns:
a String value

paren

public String paren(String a)
Returns a String that parenthesizes the parameter for the Grapher. By default it is "(a)".

Parameters:
a - a String value
Returns:
a String value

quote

public String quote(String value)
Quotes the given string.

Parameters:
value - a String value

command

public String command(String line)
Properly terminate a grapher command with end-of-line separator.

Parameters:
line - a String value

assign

public String assign(String var,
                     String value)
Returns a String that assigns a value to a variable for the Grapher.

Parameters:
var - a String value
value - a String value
Returns:
a String value

def_func

public abstract String def_func(String name,
                                String[] params,
                                String body)
Returns a String that defines a function for the Grapher.

Parameters:
name - a String value, name of the function
params - a String[] value, parameter names of the function
body - a String value, the body of the function
Returns:
a String value

range

public String range(Range range)
Returns a String that gives a range for the Grapher. By default it is "start:end".

Parameters:
range - a Range value
Returns:
a String value

func

public String func(String name,
                   String[] params)
Returns a String that calls a predefined function with given arguments for the Grapher. By default it is "func(par1,par2,...)".

Parameters:
name - a String value, name of the function
params - a String[] value, array of parameter values
Returns:
a String value

display

public PlotHandle display(Plot plot,
                          PrintStream out)
Displays the plot generated from the given plot description.

TODO: Should return the PlotHandle and call directly Grapher.plot(Plot)

Parameters:
plot - a Plot value
out - a PrintStream for displaying grapher response. If null, System.out is used.
Returns:
The response from the grapher
See Also:
Plot.plot(Grapher)

setWindow

public abstract void setWindow(int windowNumber)
Sets the current plot window according to grapher platform.

Parameters:
windowNumber - an int value

response

public String response()
Returns the standard and error outputs of the process if available.

Returns:
a String value

waitForResponse

public void waitForResponse()
Wait until a response comes from either the output or error streams of the process.


close

public void close()
Kills the grapher process.


writeEPS

public abstract void writeEPS(PlotHandle handle,
                              String filename)
Exports an EPS file of the previously visualized (required) plot.

Parameters:
handle - a PlotHandle value
filename - a String value

writeEPSbw

public abstract void writeEPSbw(PlotHandle handle,
                                String filename)
Exports a black-n-white EPS file of the previously visualized (required) plot.

TODO: make some export properties to handle these.

Parameters:
handle - a PlotHandle value
filename - a String value