/** * Evaluate a function at a specific point for one single variable. Evaluation is done between * xmin and xmax. It is assumed that there are no any other variable involved * * @param indvars Define independent variable, like 'x' Only one variable is allowed * @param xmin xmin value for independent varible * @param xmax xmax value for independent varible * @return true if no errors */ public boolean eval(String indvars, double xmin, double xmax) { boolean suc = true; String name = proxy.getName(); int points = proxy.getPoints(); double min = xmin; double max = xmax; x = new double[points]; y = new double[points]; for (int i = 0; i < points; i++) { x[i] = min + i * (max - min) / (points - 1); jep.addVariable(indvars.trim(), x[i]); try { Object result = jep.evaluate(node); if (result instanceof Double) { y[i] = ((Double) jep.evaluate(node)).doubleValue(); } } catch (ParseException e) { jhplot.utils.Util.ErrorMessage( "Failed to parse function " + name + " Error:" + e.toString()); suc = false; } } if (suc) isEvaluated = true; return suc; } // end 1-D evaluation
/** * Construct a data browser using the input file for 2D data. The file can be URL (starts from * http or ftp). * * <p>File must have the extensions <br> * : "jdat" (HBook) <br> * "jser" (HFile) <br> * "jxml" (HFileXML) <br> * "jpbu" (PFile) <br> * "root" (ROOT) <br> * "aida/xml" (AIDA) <br> * * @param file input file or URL * @param frame frame if any. */ public BrowserData(final String file, final GHFrame frame) { String ss = file.toLowerCase(); if (ss.endsWith(".jser")) { HFile hh = new HFile(file); if (frame != null) new BrowserHFile(frame, hh, true); else { BrowserHFile b = new BrowserHFile(null, hh, true); map = b.getMap(); } } else if (ss.endsWith(".jxml")) { HFileXML hh = new HFileXML(file); if (frame != null) new BrowserHFileXML(frame, hh, true); else { BrowserHFileXML b = new BrowserHFileXML(null, hh, true); map = b.getMap(); } } else if (ss.endsWith(".jpbu")) { PFile hh = new PFile(file); if (frame != null) new jhplot.io.BrowserPFile(frame, hh, true); else { BrowserPFile b = new BrowserPFile(null, hh, true); map = b.getMap(); } } else if (ss.endsWith(".jdat")) { jhplot.io.HBook hb = new HBook(file, "r"); // System.out.println("Call to HBook"); if (frame != null) new jhplot.io.BrowserHBook(frame, hb, true); else { BrowserHBook b = new BrowserHBook(null, hb, true); map = b.getMap(); } } else if (ss.endsWith(".root")) { if (frame != null) new jhplot.io.BrowserRoot(frame, file, true); else { BrowserRoot b = new BrowserRoot(null, file, true); map = b.getMap(); } } else if (ss.endsWith(".xml") || ss.endsWith(".aida")) { if (frame != null) new jhplot.io.BrowserAida(frame, file, true); else { BrowserAida b = new BrowserAida(null, file, true); map = b.getMap(); } } else { jhplot.utils.Util.ErrorMessage( "Not supported file format. Required: *.jser, *.jxml, *.jdat, *.root, *.jpbu"); } ; }
/** * Evaluate a function at a specific point for one single variable. Evaluation is done between * xmin and xmax * * @param indvars Define independent variable, like 'x' Only one variable is allowed * @param xmin xmin value for independent varible * @param xmax xmax value for independent varible * @param vars define values for other variables, like 'y=1,z=3' * @return true if no errors */ public boolean eval(String indvars, double xmin, double xmax, String vars) { String name = proxy.getName(); int points = proxy.getPoints(); boolean suc = true; String[] tmp = vars.split(","); // double[] vd = new double[tmp.length]; fixedVars = vars; for (int i = 0; i < tmp.length; i++) { String[] vv = tmp[i].split("="); if (vv.length != 2) { ErrorMessage("Error in parsing list of input variablse. Did you use val=number? "); } try { double d = Double.valueOf(vv[1].trim()).doubleValue(); jep.addVariable(vv[0].trim(), d); } catch (NumberFormatException nfe) { System.out.println("NumberFormatException: " + nfe.getMessage()); suc = false; } } double min = xmin; double max = xmax; x = new double[points]; y = new double[points]; for (int i = 0; i < points; i++) { x[i] = min + i * (max - min) / (points - 1); jep.addVariable(indvars.trim(), x[i]); try { Object result = jep.evaluate(node); if (result instanceof Double) { y[i] = ((Double) jep.evaluate(node)).doubleValue(); } } catch (ParseException e) { jhplot.utils.Util.ErrorMessage( "Failed to parse function " + name + " Error:" + e.toString()); suc = false; } } if (suc) isEvaluated = true; return suc; } // end 1-D evaluation