private static void writeAsXML(IHistogram2D h, String filename) { try { StreamWriter writer = new StreamWriter(filename); writer.WriteLine("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"); writer.WriteLine("<!DOCTYPE plotML SYSTEM \"plotML.dtd\">"); writer.WriteLine("<plotML>"); writer.WriteLine("<plot>"); writer.WriteLine("<dataArea>"); writer.WriteLine("<data2d type=\"xxx\">"); writer.WriteLine("<bins2d title=\"" + h.Title + "\" xSize=\"" + h.XAxis.Bins + "\" ySize=\"" + h.YAxis.Bins + "\">"); for (int i = 0; i < h.XAxis.Bins; i++) { for (int j = 0; j < h.YAxis.Bins; j++) { writer.WriteLine(h.BinEntries(i, j) + "," + h.BinError(i, j)); } } writer.WriteLine("</bins2d>"); writer.Write("<binnedDataAxisAttributes type=\"double\" axis=\"x0\""); writer.Write(" min=\"" + h.XAxis.LowerEdge + "\""); writer.Write(" max=\"" + h.XAxis.UpperEdge + "\""); writer.Write(" numberOfBins=\"" + h.XAxis.Bins + "\""); writer.WriteLine("/>"); writer.Write("<binnedDataAxisAttributes type=\"double\" axis=\"y0\""); writer.Write(" min=\"" + h.YAxis.LowerEdge + "\""); writer.Write(" max=\"" + h.YAxis.UpperEdge + "\""); writer.Write(" numberOfBins=\"" + h.YAxis.Bins + "\""); writer.WriteLine("/>"); //writer.WriteLine("<statistics>"); //writer.WriteLine("<statistic name=\"Entries\" value=\""+h.entries()+"\"/>"); //writer.WriteLine("<statistic name=\"MeanX\" value=\""+h.meanX()+"\"/>"); //writer.WriteLine("<statistic name=\"RmsX\" value=\""+h.rmsX()+"\"/>"); //writer.WriteLine("<statistic name=\"MeanY\" value=\""+h.meanY()+"\"/>"); //writer.WriteLine("<statistic name=\"RmsY\" value=\""+h.rmsY()+"\"/>"); //writer.WriteLine("</statistics>"); writer.WriteLine("</data2d>"); writer.WriteLine("</dataArea>"); writer.WriteLine("</plot>"); writer.WriteLine("</plotML>"); writer.Close(); } catch (IOException x) { using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(x.StackTrace); } } }
/// <summary> /// Returns an array[h.XAxis.Bins][h.YAxis.Bins]; ignoring extra bins. //// protected double[][] ToArrayErrors(IHistogram2D h) { int xBins = h.XAxis.Bins; int yBins = h.YAxis.Bins; double[][] array = new double[xBins][]; for (int i = yBins; --i >= 0;) { array[i] = new double[yBins]; for (int j = xBins; --j >= 0;) { array[j][i] = h.BinError(j, i); } } return(array); }
/// <summary> /// Returns a XML representation of the given argument. //// public String ToXML(IHistogram2D h) { StringBuilder o = new StringBuilder(); String sep = "\n\r"; //System.getProperty("line.separator"); o.Append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"); o.Append(sep); o.Append("<!DOCTYPE plotML SYSTEM \"plotML.dtd\">"); o.Append(sep); o.Append("<plotML>"); o.Append(sep); o.Append("<plot>"); o.Append(sep); o.Append("<dataArea>"); o.Append(sep); o.Append("<data2d type=\"xxx\">"); o.Append(sep); o.Append("<bins2d title=\"" + h.Title + "\" xSize=\"" + h.XAxis.Bins + "\" ySize=\"" + h.YAxis.Bins + "\">"); o.Append(sep); for (int i = 0; i < h.XAxis.Bins; i++) { for (int j = 0; j < h.YAxis.Bins; j++) { o.Append(h.BinEntries(i, j) + "," + h.BinError(i, j)); o.Append(sep); } } o.Append("</bins2d>"); o.Append(sep); o.Append("<binnedDataAxisAttributes type=\"double\" axis=\"x0\""); o.Append(" min=\"" + h.XAxis.LowerEdge + "\""); o.Append(" max=\"" + h.XAxis.UpperEdge + "\""); o.Append(" numberOfBins=\"" + h.XAxis.Bins + "\""); o.Append("/>"); o.Append(sep); o.Append("<binnedDataAxisAttributes type=\"double\" axis=\"y0\""); o.Append(" min=\"" + h.YAxis.LowerEdge + "\""); o.Append(" max=\"" + h.YAxis.UpperEdge + "\""); o.Append(" numberOfBins=\"" + h.YAxis.Bins + "\""); o.Append("/>"); o.Append(sep); //o.Append("<statistics>"); o.Append(sep); //o.Append("<statistic name=\"Entries\" value=\""+h.Entries+"\"/>"); o.Append(sep); //o.Append("<statistic name=\"MeanX\" value=\""+h.MeanX+"\"/>"); o.Append(sep); //o.Append("<statistic name=\"RmsX\" value=\""+h.RmsX+"\"/>"); o.Append(sep); //o.Append("<statistic name=\"MeanY\" value=\""+h.MeanY+"\"/>"); o.Append(sep); //o.Append("<statistic name=\"RmsY\" value=\""+h.RmsY+"\"/>"); o.Append(sep); //o.Append("</statistics>"); o.Append(sep); o.Append("</data2d>"); o.Append(sep); o.Append("</dataArea>"); o.Append(sep); o.Append("</plot>"); o.Append(sep); o.Append("</plotML>"); o.Append(sep); return(o.ToString()); }