Example #1
0
  /**
   * Provides a static entry point for running DAVE as standalone utility.
   *
   * @param args
   */
  public static void main(String args[]) {

    boolean success = false;

    DAVE dave = new DAVE(args);

    if (dave.noProcessingRequired) {
      System.exit(exit_success); // short circuit if just help requested
    }
    try {
      success = dave.parseFile();
    } catch (IOException e) {
      System.err.println(e.getMessage());
    }

    // quit now if problems in parsing
    if (!success) {
      System.exit(exit_failure);
    }

    // If checkcase data is included, run quick verification
    if (dave.checkcases != null) {
      if (dave.ignoreCheckcases) {
        System.out.println("(Verification cases(s) ignored.)");
      } else if (!dave.verify()) {
        System.exit(exit_failure);
      }
    }

    // Did user ask for stats?
    if (dave.genStatsFlag) {
      dave.reportStats(); // report parsing stats
    }

    // Did user ask for a listing?
    if (dave.makeListing) {
      dave.describeSelf();
    }

    // Did user ask to perform evalution?
    if (dave.evaluate) {
      while (true) { // run until ^D entered
        try {
          VectorInfoArrayList inputVec = dave.m.getInputVector();
          int eof = dave.loadInputs(inputVec);
          if (eof == -1) {
            System.out.println();
            System.exit(exit_success);
          }

          dave.m.cycle(); // run model with inputs

          VectorInfoArrayList outputVec = dave.m.getOutputVector();
          if (outputVec == null) {
            System.err.println(" Null output vector returned from Model.cycle() ");
            System.exit(exit_failure);
          }
          dave.listOutputs(outputVec);

          if (dave.createInternalValues) {
            VectorInfoArrayList internalVec = dave.m.getInternalsVector();
            if (internalVec == null) {
              System.err.println(" Null internal results vector returned from Model.cycle() ");
              System.exit(exit_failure);
            }
            dave.listInternals(internalVec);
          }

        } catch (Exception e) {
          System.err.println(e.getMessage());
        }
      }
    }
  }
Example #2
0
 /**
  * Sets the input file and stub name strings.
  *
  * <p>This method needed to support packages that extend DAVE.
  *
  * @param fn the new file name
  */
 public void setInputFileName(String fn) {
   this.inputFileName = fn;
   this.stubName = DAVE.toStubName(fn);
 }
Example #3
0
  /** Parses any command-line options given. */
  private void parseOptions(String inArgs[]) {
    String exampleUse =
        "Usage: java DAVE [-v][-c][-d][-e][-h][-x][-i] [-o [Text_output_file]] DAVE-ML_document";
    int numArgs = inArgs.length;

    // Make sure we have at least the input file

    if (numArgs < 1) {
      System.out.println(exampleUse);
      System.out.println("Need at least one argument.");
      System.exit(0);
    }

    // Save arguments into field
    this.setArgs(inArgs);

    // Retrieve input file name
    this.inputFileName = this.args[numArgs - 1];

    // Don't deal with stub name if no filename provided
    if (this.inputFileName.startsWith("-")) {
      numArgs++; // adjust so we'll look at first argument
    } else {
      // Generate stub file name and list file name
      this.stubName = DAVE.toStubName(this.inputFileName);
      this.listFileName = this.stubName + ".txt";
    }

    // Parse remaining options
    if (numArgs > 1) {
      int parsedArgs = 0;
      if (matchOptionArgs("c", "count")) {
        this.genStatsFlag = true;
        parsedArgs++;
      }
      if (matchOptionArgs("d", "debug")) {
        this.verboseFlag = true;
        parsedArgs++;
      }
      if (matchOptionArgs("e", "eval")) {
        this.evaluate = true;
        parsedArgs++;
      }
      if (matchOptionArgs("i", "internal")) {
        this.createInternalValues = true;
        parsedArgs++;
      }
      if (matchOptionArgs("o", "list")) {
        this.makeListing = true;
        if (numArgs > (this.argNum + 2)) {
          if (!this.args[this.argNum + 1].startsWith("-")) {
            this.listFileName = this.args[this.argNum + 1];
          }
        }
        parsedArgs++;
      }
      if (matchOptionArgs("v", "version")) {
        this.noProcessingRequired = true;
        System.out.println("DAVE version " + getVersion());
        System.exit(0);
      }
      if (matchOptionArgs("x", "no-checkcase")) {
        this.ignoreCheckcases = true;
        parsedArgs++;
        System.out.println("Ignoring checkcases");
      }
      if (matchOptionArgs("h", "help")) {
        this.noProcessingRequired = true;
        this.helpRequested = true;
        parsedArgs++;
      }

      int numSwitches = this.numCmdLineSwitches();

      if (parsedArgs < numSwitches) {
        System.err.print("Unable to understand ");
        if (numSwitches == 1) {
          System.err.println("and parse option switch '" + this.args[this.argNum] + "'.");
        } else if (numSwitches == 2) {
          System.err.println("and parse both option switches.");
        } else {
          System.err.println("and parse all " + numSwitches + " option switches.");
        }
        System.err.println(exampleUse);
        System.exit(0);
      }
    }
  }