/** algorithm performed */
  public void algorithmPerformed(AlgorithmBase algorithm) {
    if (alg.isCompleted()) {
      alg = null;
      // if OKButton is not null, then the rest are not null
      // we don't want to do these if this algoritm was done via a script
      if (OKButton != null) {
        OKButton.setEnabled(true);
        dwiPathBrowseButton.setEnabled(true);
        gradFileRadio.setEnabled(true);
        bmtxtFileRadio.setEnabled(true);
        performRegistrationCheckbox.setEnabled(true);
        registrationSettingsButton.setEnabled(true);
        dwiLabel.setEnabled(true);
        dicomB0VolumeLabel.setEnabled(true);
        // interleavedCheckbox.setEnabled(true);
        if (gradFileRadio.isSelected()) {
          gradientFileBrowseButton.setEnabled(true);
        } else {
          bmtxtFileBrowseButton.setEnabled(true);
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        outputTextArea.append("*** End DTI Sorting Process *** \n");
      }

      // insertScriptLine();
      Preferences.debug("*** End DTI Sorting Process *** \n", Preferences.DEBUG_ALGORITHM);
      // System.out.println("*** End DTI Sorting Process *** \n");
    }
  }
  /** call algorithm */
  protected void callAlgorithm() {
    boolean performRegistration = performRegistrationCheckbox.isSelected();

    Preferences.debug("*** Beginning DTI Sorting Process *** \n", Preferences.DEBUG_ALGORITHM);
    if (outputTextArea != null) {
      outputTextArea.append("*** Beginning DTI Sorting Process *** \n");
    }
    // System.out.println("*** Beginning DTI Sorting Process *** \n");
    if (isDICOM) {
      if (performRegistration) {
        int cost = regOptions.getCost();
        int DOF = regOptions.getDOF();
        int interp = regOptions.getInterp();
        int interp2 = regOptions.getInterp2();
        float rotateBeginX = regOptions.getRotateBeginX();
        float rotateEndX = regOptions.getRotateEndX();
        float coarseRateX = regOptions.getCoarseRateX();
        float fineRateX = regOptions.getFineRateX();
        float rotateBeginY = regOptions.getRotateBeginY();
        float rotateEndY = regOptions.getRotateEndY();
        float coarseRateY = regOptions.getCoarseRateY();
        float fineRateY = regOptions.getFineRateY();
        float rotateBeginZ = regOptions.getRotateBeginZ();
        float rotateEndZ = regOptions.getRotateEndZ();
        float coarseRateZ = regOptions.getCoarseRateZ();
        float fineRateZ = regOptions.getFineRateZ();
        boolean maxOfMinResol = regOptions.isMaxOfMinResol();
        boolean doSubsample = regOptions.isDoSubsample();
        boolean doMultiThread = regOptions.isDoMultiThread();
        boolean fastMode = regOptions.isFastMode();
        int bracketBound = regOptions.getBracketBound();
        int maxIterations = regOptions.getMaxIterations();
        int numMinima = regOptions.getNumMinima();
        alg =
            new AlgorithmDTICreateListFile(
                studyPath,
                studyName,
                dicomB0VolumePath,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                isInterleaved,
                performRegistration,
                cost,
                DOF,
                interp,
                interp2,
                rotateBeginX,
                rotateEndX,
                coarseRateX,
                fineRateX,
                rotateBeginY,
                rotateEndY,
                coarseRateY,
                fineRateY,
                rotateBeginZ,
                rotateEndZ,
                coarseRateZ,
                fineRateZ,
                maxOfMinResol,
                doSubsample,
                doMultiThread,
                fastMode,
                bracketBound,
                maxIterations,
                numMinima,
                dwiPathTextField);
      } else {
        alg =
            new AlgorithmDTICreateListFile(
                studyPath,
                studyName,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                isInterleaved,
                performRegistration);
      }
    } else {
      if (performRegistration) {
        int cost = regOptions.getCost();
        int DOF = regOptions.getDOF();
        int interp = regOptions.getInterp();
        int interp2 = regOptions.getInterp2();
        int registerTo = regOptions.getRegisterTo();
        float rotateBegin = regOptions.getRotateBegin();
        float rotateEnd = regOptions.getRotateEnd();
        float coarseRate = regOptions.getCoarseRate();
        float fineRate = regOptions.getFineRate();
        boolean doSubsample = regOptions.isDoSubsample();
        boolean doMultiThread = regOptions.isDoMultiThread();
        boolean fastMode = regOptions.isFastMode();
        int bracketBound = regOptions.getBracketBound();
        int maxIterations = regOptions.getMaxIterations();
        int numMinima = regOptions.getNumMinima();

        alg =
            new AlgorithmDTICreateListFile(
                prFileName,
                prFileDir,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                performRegistration,
                cost,
                DOF,
                interp,
                interp2,
                registerTo,
                rotateBegin,
                rotateEnd,
                coarseRate,
                fineRate,
                doSubsample,
                doMultiThread,
                fastMode,
                bracketBound,
                maxIterations,
                numMinima,
                dwiPathTextField);
      } else {
        alg =
            new AlgorithmDTICreateListFile(
                prFileName,
                prFileDir,
                gradientPath,
                bmatrixPath,
                outputTextArea,
                performRegistration);
      }
    }
    alg.addListener(this);

    if (isRunInSeparateThread()) {

      // Start the thread as a low priority because we wish to still
      // have user interface work fast.
      if (alg.startMethod(Thread.MIN_PRIORITY) == false) {
        MipavUtil.displayError("A thread is already running on this object");
      }
    } else {
      alg.run();
    }
  }