예제 #1
0
파일: DAVE.java 프로젝트: nasa/DAVEtools
  /**
   * Reports contents of model internals vector to user on <code>stdout</code>.
   *
   * @param outVec A <code>VectorInfoArrayList</code> listing output names and values
   */
  public void listInternals(VectorInfoArrayList outVec) {
    System.out.println();
    System.out.println("Intermediate values are:");
    Iterator<VectorInfo> it = outVec.iterator();
    while (it.hasNext()) {
      VectorInfo vi = it.next();
      System.out.print("  " + vi.getName() + " = " + vi.getValue());

      // add units if any
      if (vi.getUnits().length() > 0) {
        System.out.println(" (" + vi.getUnits() + ")");
      } else {
        System.out.println();
      }
    }
    System.out.println();
    //      this.describeSelf();
  }
예제 #2
0
파일: DAVE.java 프로젝트: nasa/DAVEtools
  /**
   * Requests new model inputs from user.
   *
   * <p>Will return -1 if user signals end-of-input ( <code>^d</code>)
   *
   * @param inVec A {@link VectorInfoArrayList} listing inputs and default values
   * @return int -1 to quit, 0 to keep going
   * @throws IOException;
   */
  public int loadInputs(VectorInfoArrayList inVec) throws IOException {
    int tokenType;

    // The following mumbo-jumbo necessary to take stdin and parse it
    FileReader frin = new FileReader(FileDescriptor.in);
    StreamTokenizer st = new StreamTokenizer(frin);

    // Tell parser to look for double-precision numbers and EOLs
    // Note - can't use exponential notation; only 0-9, -, .
    st.parseNumbers();
    st.eolIsSignificant(true);

    // Write header
    System.out.println();
    System.out.println(" Specify input values:");

    // Loop for each input block that might need value
    Iterator<VectorInfo> in = inVec.iterator();
    while (in.hasNext()) {
      boolean blankLine = false;
      VectorInfo inVal = in.next();

      // write name, units, default value
      System.out.print(
          "   " + inVal.getName() + " (" + inVal.getUnits() + ") [" + inVal.getValue() + "]  : ");

      // look for number in input stream; abort on EOF; skip to next on EOL
      do { // look for number or EOL or EOF
        tokenType = st.nextToken();
        // System.out.println("tokenType was " + tokenType);
        if (tokenType == StreamTokenizer.TT_EOF) {
          return -1; // quit
        }
        if (tokenType == StreamTokenizer.TT_EOL) { // skip to next param
          blankLine = true;
          break;
        }
      } while (tokenType != StreamTokenizer.TT_NUMBER); // keep looking until number found

      if (!blankLine) {
        // if not empty line, interpret number and save in block
        //              System.out.println("Input value was " + st.nval);
        try {
          inVal.setValue(st.nval);
          //              System.out.println("setValue called for " + inVal.getName() + " with value
          // of " + st.nval);
        } catch (NumberFormatException e) {
          // take no action - leave value as is
        }

        // look for EOL so we can ignore it
        do {
          tokenType = st.nextToken();
          //              System.out.println("skipping tokenType " + tokenType );
          if (tokenType == StreamTokenizer.TT_EOF) {
            return -1;
          }
        } while (tokenType != StreamTokenizer.TT_EOL);
      }
    }
    return 0; // indicate keep going
  }