Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

JetWebPlotMLReader Class Reference

Inheritance diagram for JetWebPlotMLReader:

Inheritance graph
[legend]
Collaboration diagram for JetWebPlotMLReader:

Collaboration graph
[legend]
List of all members.

Detailed Description

Uses JDOM API to read a JetWeb XML data plot. Reads XML using a SAX parser. Outputs plot attributes and data.

Author:
S Butterworth, UCL.
Version:
Date
2005-11-23 21:44:23 +0000 (Wed, 23 Nov 2005)
Revision
979

Definition at line 30 of file JetWebPlotMLReader.java.


Public Member Functions

 JetWebPlotMLReader (String filename) throws JetWebXMLException
String getTitle ()
String getXLabel ()
String getYLabel ()
void fillPlot (DataPlot plot) throws JetWebException
void setDirectory (String dir) throws JetWebException

Static Public Member Functions

void main (String args[])

Protected Member Functions

Document getDocument ()
String getFileName ()

Static Protected Attributes

final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces"
final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation"
final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema"
final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking"
final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic"
final String LOAD_EXTERNAL_DTD_FEATURE_ID = "http://apache.org/xml/features/nonvalidating/load-external-dtd"
final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser"
final boolean DEFAULT_NAMESPACES = true
final boolean DEFAULT_VALIDATION = false
final boolean DEFAULT_LOAD_EXTERNAL_DTD = true
final boolean DEFAULT_SCHEMA_VALIDATION = false
final boolean DEFAULT_SCHEMA_FULL_CHECKING = false
final boolean DEFAULT_DYNAMIC_VALIDATION = false
final boolean DEFAULT_CANONICAL = false

Private Member Functions

void populateSoloPlot ()
void populateDataPoints ()
String[][] decodeData (String data)
Collection< DataPointgetDataPoints ()

Private Attributes

String filename
Element soloPlot
String title
String xlabel
String ylabel
boolean isLogarithmic = false
Vector< DataPointdataPoints = new Vector<DataPoint>()

Constructor & Destructor Documentation

JetWebPlotMLReader String  filename  )  throws JetWebXMLException
 

constructor requires xml filename and, optionally, sax driver class

Definition at line 63 of file JetWebPlotMLReader.java.

References JetWebPlotMLReader.filename, and JetWebPlotMLReader.populateSoloPlot().

Referenced by JetWebPlotMLReader.main().

00063                                                                          {
00064     super(filename);
00065     populateSoloPlot();
00066     }


Member Function Documentation

String [][] decodeData String  data  )  [private]
 

a bins1d plotML element text consists of a set of comma delimited strings separated by carriage returns. this method decodes this text into a an array of points, where each point is an array of strings: point[0] value point[1] error point[2] anuvver error

Definition at line 164 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.populateDataPoints().

00164                                                {
00165     
00166     StringTokenizer tokLines = new StringTokenizer(data,"\n");
00167     String[][] pointsA = new String[3][tokLines.countTokens()];
00168     int i = 0;
00169     while (tokLines.hasMoreTokens()){
00170         StringTokenizer tokCommas = new StringTokenizer(tokLines.nextToken(),",");
00171             pointsA[0][i]=tokCommas.nextToken();
00172         pointsA[1][i]=tokCommas.nextToken();
00173         if (tokCommas.countTokens()==3){
00174         pointsA[2][i]=tokCommas.nextToken();
00175         }
00176         i++;
00177     }
00178     return pointsA;
00179     }

void fillPlot DataPlot  plot  )  throws JetWebException
 

Implements JetWebPlotReader.

Definition at line 204 of file JetWebPlotMLReader.java.

References JetWebPlotMLReader.dataPoints, JetWebPlotMLReader.isLogarithmic, JetWebPlotMLReader.title, JetWebPlotMLReader.xlabel, and JetWebPlotMLReader.ylabel.

00204                                                                { 
00205     //System.out.println("fillplot called. title= " + title);
00206     plot.setTitle(title);
00207     plot.setXLabel(xlabel);
00208     plot.setYLabel(ylabel);
00209         plot.setLogarithmic(isLogarithmic);
00210     plot.setDataPoints(dataPoints);
00211     if (plot instanceof PredictedPlot){
00212         PredictedPlot.adjustErrors((PredictedPlot)plot);
00213     }
00214     plot.setHasData(true);
00215     }

Collection<DataPoint> getDataPoints  )  [private]
 

get enumeration of data point objects: point[X] = x value. point[Y] = y value. point[YUP] = y error (up). point[YDOWN] = y error (down). point[BINWIDTH] = bin width point[CHI2] = pull (chi2) [not populated]

Definition at line 201 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.main().

00201                                                  {
00202     return dataPoints;
00203     }

Document getDocument  )  [protected, inherited]
 

Definition at line 365 of file JetWebXMLReader.java.

Referenced by JetWebLogReader.fillLog(), and JetWebPlotMLReader.populateSoloPlot().

00365                                      {
00366     //if (doc==null) throw new JetWebXMLException("XML Reader not initialised: Document is null",null);
00367     return doc;
00368     }

String getFileName  )  [protected, inherited]
 

Definition at line 369 of file JetWebXMLReader.java.

Referenced by JetWebLogReader.fillLog().

00369                                     {
00370     //if (filename==null) throw new JetWebXMLException("XML Reader not initialised: No Filename provided",null);
00371     return filename;
00372     }

String getTitle  ) 
 

get plot title

Definition at line 181 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.main().

00181                             {
00182         return title;
00183     }

String getXLabel  ) 
 

get x axis label

Definition at line 185 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.main().

00185                              {
00186     return xlabel;
00187     }

String getYLabel  ) 
 

get y axis label

Definition at line 189 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.main().

00189                              {
00190     return ylabel;
00191     }

void main String  args[]  )  [static]
 

test main method args[0] : xml filename

Definition at line 44 of file JetWebPlotMLReader.java.

References JetWebPlotMLReader.getDataPoints(), JetWebPlotMLReader.getTitle(), JetWebPlotMLReader.getXLabel(), JetWebPlotMLReader.getYLabel(), and JetWebPlotMLReader.JetWebPlotMLReader().

00044                                           {
00045     try {
00046         JetWebPlotMLReader tester = new JetWebPlotMLReader(args[0]);
00047         System.out.println("test title " + tester.getTitle());
00048         System.out.println("x label " + tester.getXLabel());
00049         System.out.println("y label " + tester.getYLabel());
00050         Collection<DataPoint> points=tester.getDataPoints();
00051         int i=0;
00052         for (DataPoint point : points) {
00053         i++;
00054         System.out.println("point"+i+ point.toString());
00055         }
00056     } catch (Throwable t) {
00057         System.out.println("Error reading XML");
00058     }
00059     }

void populateDataPoints  )  [private]
 

extract a set of data points from a data1d plotML element populate a vector of DataPoint objects each datapoint contains an array of doubles: point[X] = x value. point[Y] = y value. point[YUP] = y error (up). point[YDOWN] = y error (down). point[BINWIDTH] = bin width point[CHI2] = pull (chi2)

Definition at line 115 of file JetWebPlotMLReader.java.

References DataPoint.add(), JetWebPlotMLReader.dataPoints, JetWebPlotMLReader.decodeData(), DataPoint.getYDown(), DataPoint.setBinWidth(), DataPoint.setX(), DataPoint.setY(), DataPoint.setYDown(), DataPoint.setYUp(), and JetWebPlotMLReader.soloPlot.

Referenced by JetWebPlotMLReader.populateSoloPlot().

00115                                      {
00116     List<Element> pointsList = soloPlot.getChild("dataArea").getChildren("data1d");
00117     Iterator<Element> points = pointsList.iterator();
00118     try {
00119     while (points.hasNext()){
00120         Element point = points.next();
00121         Element axisAttr = point.getChild("binnedDataAxisAttributes");
00122         double numberOfBins = Double.parseDouble(axisAttr.getAttributeValue("numberOfBins"));
00123         double min = Double.parseDouble(axisAttr.getAttributeValue("min"));
00124         double max = Double.parseDouble(axisAttr.getAttributeValue("max"));
00125         double binwidth = (max - min) / numberOfBins;
00126 
00127         //have to decode this string into points and errors
00128         String[][] hdata = decodeData(point.getChildTextTrim
00129 ("bins1d"));
00130         for (int i=0;i<hdata[0].length;i++){
00131 
00132         DataPoint pointA = new DataPoint();
00133         pointA.setX(binwidth*i + 0.5*binwidth + min);
00134         pointA.setY(Double.parseDouble(hdata[0][i]));
00135         pointA.setYUp(Double.parseDouble(hdata[1][i]));
00136         pointA.setYDown(pointA.getYDown());
00137         pointA.setBinWidth(binwidth);
00138         /*
00139         double[] pointA = new double[6];
00140             pointA[DataPoint.X]=binwidth*i +  binwidth/2.0 +min;
00141         pointA[DataPoint.Y]=Double.parseDouble(hdata[0][i]);
00142         pointA[DataPoint.YUP]=Double.parseDouble(hdata[1][i]);      
00143         pointA[DataPoint.YDOWN]=pointA[2];
00144         pointA[DataPoint.BINWIDTH]=binwidth;
00145         
00146         dataPoints.add(new DataPoint(pointA));
00147         */
00148         dataPoints.add(pointA);
00149         }
00150     }
00151         } catch (Exception e){
00152         System.out.println("Exception in populate data points " + e);
00153         e.printStackTrace(System.out);
00154     }
00155     }

void populateSoloPlot  )  [private]
 

extract first plot from plotfile, ignore any others

Definition at line 70 of file JetWebPlotMLReader.java.

References JetWebXMLReader.getDocument(), JetWebPlotMLReader.isLogarithmic, JetWebPlotMLReader.populateDataPoints(), JetWebPlotMLReader.soloPlot, JetWebPlotMLReader.title, JetWebPlotMLReader.xlabel, and JetWebPlotMLReader.ylabel.

Referenced by JetWebPlotMLReader.JetWebPlotMLReader().

00070                                    {
00071     Document doc = getDocument();
00072     if (soloPlot==null){
00073         soloPlot = doc.getRootElement().getChild("plot");
00074     }
00075     if (soloPlot==null){
00076         System.out.println("Error reading plotfile - no plot");
00077     } else {
00078         //extract plot title
00079         title=soloPlot.getChild("title").getChild("label").getAttributeValue("text");
00080         //extract axes titles
00081         List<Element> axesList=soloPlot.getChild("dataArea").getChildren("axis");
00082         Iterator<Element> axes = axesList.iterator();
00083         while (axes.hasNext()){
00084         Element axis = axes.next();
00085         String axisLabel=axis.getChild("label").getAttributeValue("text");
00086         String axisType=axis.getAttributeValue("location");
00087         if (axisType.equals("x0")){
00088             xlabel=axisLabel;
00089         } else {
00090             ylabel=axisLabel;
00091                     String isLog = axis.getAttributeValue("logarithmic");
00092                     if(isLog.compareTo("true")==0) {
00093                         isLogarithmic = true;
00094                     }else {
00095                         isLogarithmic = false;
00096                     }
00097         }
00098         }
00099         //populate a vector of data points for the plot
00100         populateDataPoints();
00101 
00102     }
00103     }

void setDirectory String  dir  )  throws JetWebException
 

Implements JetWebPlotReader.

Definition at line 217 of file JetWebPlotMLReader.java.

00217                                                                 {
00218     throw new JetWebException("JetWebPlotMLReader","setDirectory not implemented");
00219     }


Member Data Documentation

Vector<DataPoint> dataPoints = new Vector<DataPoint>() [private]
 

Definition at line 38 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.fillPlot(), and JetWebPlotMLReader.populateDataPoints().

final boolean DEFAULT_CANONICAL = false [static, protected, inherited]
 

Default canonical output (false).

Definition at line 65 of file JetWebXMLReader.java.

final boolean DEFAULT_DYNAMIC_VALIDATION = false [static, protected, inherited]
 

Default dynamic validation support (false).

Definition at line 62 of file JetWebXMLReader.java.

final boolean DEFAULT_LOAD_EXTERNAL_DTD = true [static, protected, inherited]
 

Default load external DTD (true).

Definition at line 53 of file JetWebXMLReader.java.

final boolean DEFAULT_NAMESPACES = true [static, protected, inherited]
 

Default namespaces support (true).

Definition at line 47 of file JetWebXMLReader.java.

final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser" [static, protected, inherited]
 

Default parser name.

Definition at line 44 of file JetWebXMLReader.java.

final boolean DEFAULT_SCHEMA_FULL_CHECKING = false [static, protected, inherited]
 

Default Schema full checking support (false).

Definition at line 59 of file JetWebXMLReader.java.

final boolean DEFAULT_SCHEMA_VALIDATION = false [static, protected, inherited]
 

Default Schema validation support (false).

Definition at line 56 of file JetWebXMLReader.java.

final boolean DEFAULT_VALIDATION = false [static, protected, inherited]
 

Default validation support (false).

Definition at line 50 of file JetWebXMLReader.java.

final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic" [static, protected, inherited]
 

Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic).

Definition at line 36 of file JetWebXMLReader.java.

String filename [private]
 

Reimplemented from JetWebXMLReader.

Definition at line 32 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.JetWebPlotMLReader().

boolean isLogarithmic = false [private]
 

Definition at line 37 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.fillPlot(), and JetWebPlotMLReader.populateSoloPlot().

final String LOAD_EXTERNAL_DTD_FEATURE_ID = "http://apache.org/xml/features/nonvalidating/load-external-dtd" [static, protected, inherited]
 

Load external DTD feature id (http://apache.org/xml/features/nonvalidating/load-external-dtd).

Definition at line 39 of file JetWebXMLReader.java.

final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces" [static, protected, inherited]
 

Namespaces feature id (http://xml.org/sax/features/namespaces).

Definition at line 24 of file JetWebXMLReader.java.

final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking" [static, protected, inherited]
 

Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).

Definition at line 33 of file JetWebXMLReader.java.

final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema" [static, protected, inherited]
 

Schema validation feature id (http://apache.org/xml/features/validation/schema).

Definition at line 30 of file JetWebXMLReader.java.

Element soloPlot [private]
 

Definition at line 33 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.populateDataPoints(), and JetWebPlotMLReader.populateSoloPlot().

String title [private]
 

Definition at line 34 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.fillPlot(), and JetWebPlotMLReader.populateSoloPlot().

final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation" [static, protected, inherited]
 

Validation feature id (http://xml.org/sax/features/validation).

Definition at line 27 of file JetWebXMLReader.java.

String xlabel [private]
 

Definition at line 35 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.fillPlot(), and JetWebPlotMLReader.populateSoloPlot().

String ylabel [private]
 

Definition at line 36 of file JetWebPlotMLReader.java.

Referenced by JetWebPlotMLReader.fillPlot(), and JetWebPlotMLReader.populateSoloPlot().


The documentation for this class was generated from the following file:

Generated Wed Jan 17 09:14:27 GMT 2007