Ejemplo n.º 1
0
  /**
   * This is used when called from within a program. If args is null or args.length is 0, this
   * loops; otherwise it returns when done.
   *
   * @param args if args has values, they are used to answer the questions.
   * @returns the contents of outFileName (will be "" if trouble)
   */
  public String doIt(String args[], boolean loop) throws Throwable {
    File2.safeRename(logFileName, logFileName + ".previous");
    if (File2.isFile(outFileName)) {
      try {
        File2.rename(outFileName, outFileName + ".previous");
      } catch (Throwable t) {
        File2.delete(outFileName);
      }
    }
    String2.setupLog(
        true,
        false, // toSystemOut, toSystemErr
        logFileName,
        false, // logToStringBuffer
        true,
        20000000); // append
    String2.log(
        "*** Starting DasDds "
            + Calendar2.getCurrentISODateTimeStringLocal()
            + "\n"
            + "logFile="
            + String2.logFileName()
            + "\n"
            + String2.standardHelpAboutMessage());
    outFile = new FileWriter(outFileName); // default charset

    // delete the old log files (pre 1.48 names)
    File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt");
    File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt.previous");

    String datasetID = "";
    if (args == null) args = new String[0];

    // look for -verbose (and remove it)
    boolean verbose = false; // actually controls reallyVerbose
    int vi = String2.indexOf(args, "-verbose");
    if (vi >= 0) {
      String2.log("verbose=true");
      verbose = true;
      StringArray sa = new StringArray(args);
      sa.remove(vi);
      args = sa.toArray();
    }

    do {
      // get the EDD type
      // EDD.reallyVerbose = false;  //sometimes while testing
      datasetID =
          get(
              args,
              0,
              "\n*** DasDds ***\n"
                  + "This generates the DAS and DDS for a dataset and puts it in\n"
                  + outFileName
                  + "\n"
                  + "Press ^D or ^C to exit at any time.\n\n"
                  + "Which datasetID",
              datasetID);
      if (datasetID == null) {
        String2.flushLog();
        outFile.flush();
        outFile.close();
        return String2.readFromFile(outFileName)[1];
      }

      // delete the datasetInfo files for this datasetID (in case incorrect info)
      try {
        String dir = EDD.datasetDir(datasetID);
        String2.log(
            "dataset dir="
                + dir
                + "\n"
                + "dataset n files not deleted = "
                + RegexFilenameFilter.regexDelete(dir, ".*", false));

      } catch (Throwable t) {
        String2.log(
            "\n*** An error occurred while deleting the old info for "
                + datasetID
                + ":\n"
                + MustBe.throwableToString(t));
      }

      try {
        printToBoth(EDD.testDasDds(datasetID, verbose));
      } catch (Throwable t) {
        String2.log(
            "\n*** An error occurred while trying to load "
                + datasetID
                + ":\n"
                + MustBe.throwableToString(t));
      }
      String2.flushLog();

    } while (loop && args.length == 0);

    outFile.flush();
    outFile.close();
    String ret = String2.readFromFile(outFileName)[1];
    String2.returnLoggingToSystemOut();
    return ret;
  }