public void run(String arg) {
    ImageWindow iw = WindowManager.getCurrentWindow();
    pw = jutils.getPW4SelCopy(iw);
    String title = pw.getTitle();
    float[][] yvals = pw.getYValues();
    float[][] xvals = pw.getXValues();
    int length = yvals[0].length;
    if (pw.getShowErrors()) errs = pw.getErrors(0, false);
    int[] colors = pw.getColors();
    colors[0] = 0;
    ScriptEngineManager manager = new ScriptEngineManager();
    engine = manager.getEngineByName("js");
    ce = (Compilable) engine;
    // hitcounter=0;

    c2 = 0.0f;
    iterations = 0;
    checkc2 = false;

    double[] stats = new double[3];
    tempx = new float[length];
    tempdata = new float[length];
    System.arraycopy(xvals[0], 0, tempx, 0, length);
    System.arraycopy(yvals[0], 0, tempdata, 0, length);
    pw.addPoints(tempx, new float[tempx.length], false);
    series = pw.getNpts().length - 1;
    double[] params = new double[10];
    int[] fixes = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1};
    init_options(params, fixes);
    if (!init_functions()) {
      return;
    }

    while (showoptions(params, fixes)) {
      NLLSfit_v2 fitclass;
      if (checkc2) {
        fitclass = new NLLSfit_v2(this, 0);
      } else {
        fitclass = new NLLSfit_v2(this, 0.0001, 50, 0.1);
      }
      float[] fit = fitclass.fitdata(params, fixes, constraints, yvals[0], weights, stats, true);
      pw.updateSeries(fit, series, false);
      c2 = (float) stats[1];
      iterations = (int) stats[0];
    }

    IJ.log("Chi Squared = " + (float) stats[1]);
    IJ.log("Iterations = " + (int) stats[0]);
    for (int i = 0; i < 10; i++) {
      IJ.log("P" + (i + 1) + " = " + (float) params[i] + " fixed = " + fixes[i]);
    }
    IJ.log("AIC = " + (float) stats[2]);
    // IJ.log("hits = "+hitcounter);
    set_options(params, fixes);
  }
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   checkc2 = gd.getNextBoolean();
   double[] params = new double[10];
   int[] fixes = new int[10];
   for (int i = 0; i < params.length; i++) {
     params[i] = gd.getNextNumber();
     if (gd.getNextBoolean()) {
       fixes[i] = 1;
     } else {
       fixes[i] = 0;
     }
   }
   gd.getNextBoolean();
   gd.getNextNumber();
   gd.getNextNumber();
   NLLSfit_v2 fitclass = new NLLSfit_v2(this, 0);
   double[] stats = new double[2];
   float[] fit = fitclass.fitdata(params, fixes, null, tempdata, null, stats, true);
   pw.updateSeries(fit, series, false);
   c2 = (float) stats[1];
   return true;
 }