/** monitors the run. */
  public boolean monitorAndCleanUpShell() {
    lastModified = null;
    boolean stillGoing = true;
    if (outputFilePaths != null) {
      lastModified = new long[outputFilePaths.length];
      LongArray.deassignArray(lastModified);
    }

    if (!StringUtil.blank(
        runningFilePath)) // is file at runningFilePath; watch for its disappearance
    while (MesquiteFile.fileExists(runningFilePath) && stillGoing) {
        processOutputFiles();
        try {
          Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
          MesquiteMessage.notifyProgrammer(
              "InterruptedException in shell script executed by " + name);
          return false;
        }
        stillGoing = watcher == null || watcher.continueShellProcess(proc);
      }

    if (outputFileProcessor != null)
      outputFileProcessor.processCompletedOutputFiles(outputFilePaths);
    return true;
  }
  /**
   * executes a shell script at "scriptPath". If runningFilePath is not blank and not null, then
   * Mesquite will create a file there that will serve as a flag to Mesquite that the script is
   * running.
   */
  public boolean executeInShell() {
    proc = null;
    try {
      ShellScriptUtil.setScriptFileToBeExecutable(scriptPath);
      if (!StringUtil.blank(runningFilePath)) {
        if (StringUtil.blank(runningFileMessage))
          MesquiteFile.putFileContents(runningFilePath, "Script running...", true);
        else MesquiteFile.putFileContents(runningFilePath, runningFileMessage, true);
        if (appendRemoveCommand && MesquiteFile.fileExists(runningFilePath))
          MesquiteFile.appendFileContents(
              scriptPath,
              StringUtil.lineEnding() + ShellScriptUtil.getRemoveCommand(runningFilePath),
              true); // append remove command to guarantee that the runningFile is deleted
        // +StringUtil.lineEnding()+ShellScriptUtil.getExitCommand()
      }
      proc = ShellScriptUtil.executeScript(scriptPath, visibleTerminal);

    } catch (IOException e) {
      MesquiteMessage.warnProgrammer("IOException in shell script executed by " + name);
      return false;
    }
    return true;
  }
Example #3
0
  public void runFilesAvailable(int fileNum) {
    String[] logFileNames = getLogFileNames();
    if ((progIndicator != null && progIndicator.isAborted()) || logFileNames == null) return;
    String[] outputFilePaths = new String[logFileNames.length];
    outputFilePaths[fileNum] = externalProcRunner.getOutputFilePath(logFileNames[fileNum]);
    String filePath = outputFilePaths[fileNum];

    if (fileNum == 0
        && outputFilePaths.length > 0
        && !StringUtil.blank(outputFilePaths[0])
        && !bootstrapOrJackknife()) { // tree file
      if (ownerModule instanceof NewTreeProcessor) {
        String treeFilePath = filePath;
        if (taxa != null) {
          TaxaSelectionSet outgroupSet =
              (TaxaSelectionSet) taxa.getSpecsSet(outgroupTaxSetString, TaxaSelectionSet.class);
          ((NewTreeProcessor) ownerModule).newTreeAvailable(treeFilePath, outgroupSet);

        } else ((NewTreeProcessor) ownerModule).newTreeAvailable(treeFilePath, null);
      }
    } else if (fileNum == 1
        && outputFilePaths.length > 1
        && !StringUtil.blank(outputFilePaths[1])
        && !bootstrapOrJackknife()) { // log file
      if (MesquiteFile.fileExists(filePath)) {
        String s = MesquiteFile.getFileLastContents(filePath);
        if (!StringUtil.blank(s))
          if (progIndicator != null) {
            parser.setString(s);
            String rep = parser.getFirstToken(); // generation number
            logln("");
            if (MesquiteInteger.isNumber(rep)) {
              int numReps = MesquiteInteger.fromString(rep) + 1;
              progIndicator.setText(
                  "Replicate: " + numReps); // + ", ln L = " + parser.getNextToken());
              if (bootstrapOrJackknife()) {
                logln("Replicate " + numReps + " of " + bootstrapreps);
              }
              logln("Replicate " + numReps + " of " + totalNumHits);

              progIndicator.spin();
              double timePerRep = 0;
              if (MesquiteInteger.isCombinable(numReps) && numReps > 0) {
                timePerRep = timer.timeSinceVeryStartInSeconds() / numReps; // this is time per rep
              }
              int timeLeft = 0;
              if (bootstrapOrJackknife()) {
                timeLeft = (int) ((bootstrapreps - numReps) * timePerRep);
              } else {
                String token = parser.getNextToken(); // algorithm
                token = parser.getNextToken(); // Tree
                token = parser.getNextToken(); // Score
                String best = parser.getNextToken(); // Best
                logln("  Score " + token + "; best found so far " + best);
                timeLeft = (int) ((totalNumHits - numReps) * timePerRep);
              }

              logln(
                  "  Running time so far "
                      + StringUtil.secondsToHHMMSS((int) timer.timeSinceVeryStartInSeconds())
                      + ", approximate time remaining "
                      + StringUtil.secondsToHHMMSS(timeLeft));
            }
          }
        count++;
      } else if (MesquiteTrunk.debugMode) logln("*** File does not exist (" + filePath + ") ***");
    }
  }