public double[] fitfunc(double[] fitparams) {
   Bindings b = engine.createBindings();
   for (int i = 0; i < 10; i++) b.put("P" + (i + 1), fitparams[i]);
   /*String script1="P1="+fitparams[0]+"; "+
   "P2="+fitparams[1]+"; "+
   "P3="+fitparams[2]+"; "+
   "P4="+fitparams[3]+"; "+
   "P5="+fitparams[4]+"; "+
   "P6="+fitparams[5]+"; "+
   "P7="+fitparams[6]+"; "+
   "P8="+fitparams[7]+"; "+
   "P9="+fitparams[8]+"; "+
   "P10="+fitparams[9]+"; "+
   exdef+"; x=";
   String script2="; retval="+function+";";*/
   try {
     double[] temp = new double[tempx.length];
     for (int i = 0; i < tempx.length; i++) {
       // temp[i]=((Double)engine.eval(script1+(double)tempx[i]+script2)).doubleValue();
       b.put("x", tempx[i]);
       b.put("y", tempdata[i]);
       temp[i] = (Double) cs.eval(b);
     }
     return temp;
   } catch (Exception e) {
     IJ.log(e.getMessage());
     return null;
   }
 }
Пример #2
0
  /**
   * Perform mediation with static inline script of the given scripting language
   *
   * @param synCtx message context
   * @return true, or the script return value
   * @throws ScriptException For any errors , when compile , run the script
   */
  private Object mediateForInlineScript(MessageContext synCtx) throws ScriptException {
    ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, xmlHelper);
    processJSONPayload(synCtx, scriptMC);
    Bindings bindings = scriptEngine.createBindings();
    bindings.put(MC_VAR_NAME, scriptMC);

    Object response;
    if (compiledScript != null) {
      response = compiledScript.eval(bindings);
    } else {
      response = scriptEngine.eval(scriptSourceCode, bindings);
    }

    return response;
  }