public void run(String arg) {
   GenericDialog gd = new GenericDialog("Options");
   gd.addCheckbox("Add_Titles", true);
   gd.addCheckbox("Close Original", false);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return;
   }
   boolean addtitles = gd.getNextBoolean();
   boolean closeorig = gd.getNextBoolean();
   // first get the table window
   Frame[] niframes = WindowManager.getNonImageWindows();
   boolean first = true;
   TextWindow tw2 = null;
   int ncols = 0;
   String[] col_labels = null;
   for (int i = 0; i < niframes.length; i++) {
     if (niframes[i] instanceof TextWindow && !niframes[i].getTitle().equals("Log")) {
       TextWindow tw = (TextWindow) niframes[i];
       TextPanel tp = tw.getTextPanel();
       List<List<String>> listtable = table_tools.table2listtable(tp);
       if (listtable.size() == 0) {
         col_labels = table_tools.getcollabels(tp);
         ncols = col_labels.length;
         ArrayList<String> temp = new ArrayList<String>();
         for (int j = 0; j < ncols; j++) temp.add("");
         listtable.add(temp);
       }
       if (first) {
         col_labels = table_tools.getcollabels(tp);
         ncols = col_labels.length;
         String headings = tp.getColumnHeadings();
         if (addtitles) {
           String[] titles = repeated(tw.getTitle(), listtable.size());
           table_tools.add_listtable_column(listtable, titles, 0);
           headings = "name\t" + headings;
         }
         tw2 =
             new TextWindow(
                 "Combined Table", headings, table_tools.print_listtable(listtable), 400, 200);
         first = false;
       } else {
         if (addtitles) {
           String[] titles = repeated(tw.getTitle(), listtable.size());
           table_tools.add_listtable_column(listtable, titles, 0);
         }
         tw2.append(table_tools.print_listtable(listtable));
       }
       if (closeorig) tw.close();
     }
   }
 }
 public void showresults(String results) {
   if (redirect) tw.append(results);
   else IJ.log(results);
 }
 public boolean get_errors(double[] params, int[] fixes) {
   GenericDialog gd = new GenericDialog("Error Options");
   String[] methods = {"Support Plane", "Monte Carlo"};
   gd.addChoice("Method", methods, methods[0]);
   float conf = 0.67f;
   gd.addNumericField("SP_Confidence Limit (%)", (int) (conf * 100.0f), 5, 10, null);
   String[] labels = {"P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10"};
   gd.addChoice("SP_Parameter", labels, labels[0]);
   double spacing = 0.01;
   gd.addNumericField("SP_Chi^2_plot_spacing (% of value)?", spacing * 100.0, 2, 10, null);
   int ntrials = 100;
   gd.addNumericField("MC_#_Trials", ntrials, 0);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return false;
   }
   int methodindex = gd.getNextChoiceIndex();
   conf = 0.01f * (float) gd.getNextNumber();
   int paramindex = gd.getNextChoiceIndex();
   spacing = 0.01 * gd.getNextNumber();
   ntrials = (int) gd.getNextNumber();
   if (methodindex == 0) {
     support_plane_errors_v2 erclass = new support_plane_errors_v2(this, 0.0001, 50, false, 0.1);
     int errindex = paramindex;
     int nfit = 0;
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) {
         nfit++;
       }
     }
     int npts = tempdata.length;
     int dofnum = npts - (nfit - 1) - 1;
     int dofden = npts - nfit - 1;
     double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf);
     IJ.log("FLimit = " + (float) flim);
     if (flim == Double.NaN && flim < 1.0) {
       IJ.showMessage("Invalid Limiting F Value");
       return false;
     }
     double truespacing = Math.abs(params[errindex] * spacing);
     double[][] c2plot =
         erclass.geterrors(
             params, fixes, constraints, tempdata, weights, flim, truespacing, errindex);
     IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]);
     IJ.log(
         "upper error = "
             + (c2plot[1][0] - params[errindex])
             + " lower error = "
             + (params[errindex] - c2plot[0][0]));
     int templength = c2plot[0].length;
     float[][] c2plotf = new float[2][templength - 1];
     for (int i = 0; i < (templength - 1); i++) {
       c2plotf[0][i] = (float) c2plot[0][i + 1];
       c2plotf[1][i] = (float) c2plot[1][i + 1];
     }
     new PlotWindow4("c2 plot", labels[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw();
   } else {
     StringBuffer sb = new StringBuffer();
     sb.append("Trial\t");
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) sb.append(labels[i] + "\t");
     }
     sb.append("chi^2");
     tw = new TextWindow("Monte Carlo Results", sb.toString(), "", 400, 400);
     redirect = true;
     monte_carlo_errors_v2 erclass = new monte_carlo_errors_v2(this, 0.0001, 50, false, 0.1);
     double[][] errors = erclass.geterrors(params, fixes, constraints, tempdata, weights, ntrials);
     sb = new StringBuffer();
     sb.append("StDev\t");
     for (int i = 0; i < errors.length; i++) {
       float[] ferr = new float[errors[0].length];
       for (int j = 0; j < ferr.length; j++) ferr[j] = (float) errors[i][j];
       float stdev = jstatistics.getstatistic("StDev", ferr, null);
       sb.append("" + stdev);
       if (i < (errors.length - 1)) sb.append("\t");
     }
     tw.append(sb.toString());
     redirect = false;
   }
   return true;
 }
  public void run(String arg) {
    GenericDialog gd = new GenericDialog("Options");
    gd.addCheckbox("Acceptor_First", true);
    gd.showDialog();
    if (gd.wasCanceled()) return;
    boolean a1 = gd.getNextBoolean();
    int asp = 0;
    int dsp = 1;
    int aop = 2;
    int dop = 3;
    int atp = 4;
    int dtp = 5;
    if (!a1) {
      asp = 1;
      dsp = 0;
      aop = 3;
      dop = 2;
      atp = 5;
      dtp = 4;
    }
    ImageWindow iw = WindowManager.getCurrentWindow();
    float[][] xvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues");
    float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues");
    int[] npts = (int[]) jutils.runPW4VoidMethod(iw, "getNpts");
    int maxpts = (int) jstatistics.getstatistic("Max", npts, null);
    int nsets = npts.length / 6;
    float[][] rtxvals = new float[nsets][maxpts];
    float[][] rtavals = new float[nsets][maxpts];
    float[][] rtdvals = new float[nsets][maxpts];
    int[] rtnpts = new int[nsets];
    int fretlength = 10;
    float[][] stfretvals = new float[nsets][fretlength];
    float[][] offfretvals = new float[nsets][fretlength];
    TextWindow tw = jutils.selectTable("DNA Damage FRET");
    if (tw == null)
      tw =
          new TextWindow(
              "DNA Damage FRET",
              "title\tacceptor\tdonor\testripe\teoff\tmaxart\tmaxdrt",
              "",
              400,
              200);
    // note that st stands for stripe and off is for areas off the damage stripe
    for (int i = 0; i < npts.length / 6; i++) {
      int len = npts[i * 6];
      int damageindex = findbleach(yvals[i * 6 + dsp], len);
      int fretindex = findbleach(yvals[i * 6 + atp], len);
      IJ.log("set " + i + " damage pos = " + damageindex + " , fret pos = " + fretindex);
      int predamagestart = damageindex - 4;
      int prefretstart = fretindex - 5;
      float staccpredam = getavg(yvals[i * 6 + asp], len, predamagestart, damageindex - 1);
      float stdonpredam = getavg(yvals[i * 6 + dsp], len, predamagestart, damageindex - 1);
      float nucaccpredam = getavg(yvals[i * 6 + atp], len, predamagestart, damageindex - 1);
      float nucdonpredam = getavg(yvals[i * 6 + dtp], len, predamagestart, damageindex - 1);
      float stdonprefret = getavg(yvals[i * 6 + dsp], len, prefretstart, fretindex - 2);
      float stdonafret = getavg(yvals[i * 6 + dsp], len, fretindex, fretindex + 3);
      float offdonprefret = getavg(yvals[i * 6 + dop], len, prefretstart, fretindex - 2);
      float offdonafret = getavg(yvals[i * 6 + dop], len, fretindex, fretindex + 3);
      float estripe = 1.0f - stdonprefret / stdonafret;
      float eoff = 1.0f - offdonprefret / offdonafret;
      rtnpts[i] = len;
      for (int j = 0; j < len; j++) {
        rtxvals[i][j] = j - damageindex - 1;
        rtavals[i][j] =
            (yvals[i * 6 + asp][j] / staccpredam) / (yvals[i * 6 + atp][j] / nucaccpredam);
        rtdvals[i][j] =
            (yvals[i * 6 + dsp][j] / stdonpredam) / (yvals[i * 6 + dtp][j] / nucdonpredam);
      }
      float[] smart = (float[]) algutils.get_subarray(rtavals[i], 0, fretindex);
      float[] smdrt = (float[]) algutils.get_subarray(rtdvals[i], 0, fretindex);
      jsmooth.blur1D(smart, 2.0f);
      jsmooth.blur1D(smdrt, 2.0f);
      float maxart = 0.0f;
      float maxdrt = 0.0f;
      for (int j = 0; j < fretindex - 2; j++) {
        if (smart[j] > maxart) maxart = smart[j];
        if (smdrt[j] > maxdrt) maxdrt = smdrt[j];
      }

      stfretvals[i] = getregion(yvals[i * 6 + dsp], len, prefretstart, fretlength);
      offfretvals[i] = getregion(yvals[i * 6 + dop], len, prefretstart, fretlength);
      tw.append(
          iw.getTitle()
              + "-"
              + (i + 1)
              + "\t"
              + staccpredam
              + "\t"
              + stdonpredam
              + "\t"
              + estripe
              + "\t"
              + eoff
              + "\t"
              + maxart
              + "\t"
              + maxdrt);
    }
    new PlotWindow4("Stripe_FRET_profiles", "time", "intensity", stfretvals, null).draw();
    new PlotWindow4("OffStripe_FRET_profiles", "time", "intensity", offfretvals, null).draw();
    new PlotWindow4("Acc_Rt_profiles", "time", "intensity", rtxvals, rtavals, rtnpts).draw();
    new PlotWindow4("Don_Rt_profiles", "time", "intensity", rtxvals, rtdvals, rtnpts).draw();
  }