Example #1
0
  /** Creates new {@link Signal} for each variableDef in model. */
  @SuppressWarnings("unchecked") // since Element.getChildren() method returns generic List
  public void parseVariableDefs() {
    Signal dummySig;

    List<Element> variableList = root.getChildren("variableDef", this.ns);
    if (variableList.size() > 0) {
      Iterator<Element> variableIterator = variableList.iterator();
      this.varDefCount = variableList.size();
      if (this.isVerbose()) {
        System.out.println("");
        System.out.println("Parsing " + varDefCount + " variable definitions");
        System.out.println("--------------------------------");
        System.out.println("");
      }
      while (variableIterator.hasNext()) {
        try {
          dummySig = new Signal(variableIterator.next(), m);
        } catch (DAVEException ex) {
          System.err.println(
              "Exception thrown while parsing variableDefs: " + ex.getLocalizedMessage());
          System.err.println("aborting further parsing.");
        }
      }
    }
  }
Example #2
0
  /**
   * Using specified output (dependent) variable name, look for such a declared variable. If not
   * found, create appropriate one.
   *
   * @param function JDOM function Element
   */
  protected String hookUpOutput(Element function) {

    // Parse and discover dependent variable ID

    Element depVar = function.getChild("dependentVarRef", this.ns);
    if (depVar == null) depVar = function.getChild("dependentVarPts", this.ns); // simple table
    String depVarID = depVar.getAttributeValue("varID");

    Iterator<Signal> sigIterator = this.ourModel.getSignals().iterator();
    boolean depVarSignalFound = false;
    Signal dVsig = null;

    // Look for existing variable definition (signal)

    while (sigIterator.hasNext()) {
      // look for matching explicit signal
      dVsig = sigIterator.next();
      if (depVarID.equals(dVsig.getVarID())) {
        depVarSignalFound = true;
        break;
      }
    }

    /*
    // if not found, make our own
    if (!depVarSignalFound) {
        // create and connect to new signal
        dVsig = new Signal( depVarName, depVarName, "unkn", 10, m );
    }
    */

    // if not found, complain
    if (!depVarSignalFound) {
      System.err.println(
          "Unable to locate output signal with ID '"
              + depVarID
              + "' for Function block '"
              + this.getName()
              + "'.");
      System.exit(0);
    }

    try {
      this.addOutput(dVsig); // connect to new or existing signal
    } catch (DAVEException e) {
      System.err.println(
          "Unexpected error: new Function block '"
              + this.getName()
              + "' is unable to hook up to output signal ID '"
              + depVarID
              + "':");
      System.err.println(e.getMessage());
      System.exit(0);
    }

    return dVsig.getName();
  }
Example #3
0
  /**
   * Create a new breakpoint block and associated index-and-weight signal to serve as an input to
   * this block.
   */
  protected void createAndHookUpIWPath(String bpID, String varID, String iwSignalID, int portNum) {

    Signal connector = null; // signal wire to join Breakpoint to Function

    // Look at predeclared signals to match breakpoint input varID
    // to get name & units
    if (this.isVerbose()) System.out.print("Looking for input signal named '" + varID + "'...");

    Signal theBPInputSignal = ourModel.getSignals().findByID(varID);

    if (theBPInputSignal != null) {
      if (this.isVerbose()) System.out.println(" found it.");
      // create and connect to new intermediate signal
      String connectorName = theBPInputSignal.getName() + "_by_" + bpID;
      String units = theBPInputSignal.getUnits();
      if (this.isVerbose())
        System.out.println(
            "Creating new index-and-weights signal named '"
                + connectorName
                + "' with a varID of '"
                + iwSignalID
                + "' and units of '"
                + units
                + "'");
      connector = new Signal(connectorName, iwSignalID, units, 2, ourModel);
      connector.setAutoFlag(); // flag as an automatic variable
      connector.addSink(this, portNum + 1); // hook up to new signal
    } else {
      // else block - error
      if (this.isVerbose()) System.out.println(" DIDN'T FIND IT!! - ERROR!");

      System.err.println(
          "Error: in BlockFuncTable.createAndHookUpIWPath() for Function block '"
              + this.getName()
              + "', can't find independent (input) variable with ID '"
              + iwSignalID
              + "'.");
      System.exit(0);
    }

    // Create new breakpoint block to generate the index-and-weights signal

    try {
      new BlockBP(bpID, bpID, theBPInputSignal, connector, ourModel);
    } catch (DAVEException e) {
      System.err.println(
          "BlockFuncTable.createAndHookUpIWPath: in hooking up Function block '"
              + this.getName()
              + "':");
      System.err.println(e.getMessage());
      System.exit(0);
    }
  }
Example #4
0
  /**
   * Parse elements of a simple function (no explicit breakpoint refs or table refs/defs). Must
   * create & hook up own breakpoint objects.
   *
   * @param function JDOM "function" element
   * @throws IOException
   */
  @SuppressWarnings("unchecked")
  void parseSimpleFunction(Element function) throws IOException {
    // calling method has already confirmed this child exists.
    Element outTable = function.getChild("dependentVarPts", this.ns);

    // get varIDs of input variables
    List<Element> iVarPts = function.getChildren("independentVarPts", this.ns);
    Iterator<Element> iVarPtsIterator = iVarPts.iterator();

    // create automatic breakpoint name/ID for this input variable
    String funcTableName = "auto_" + this.myName + "_table";

    // create new funcTable from simple table info
    this.functionTableDef =
        new FuncTable(
            funcTableName, funcTableName, outTable.getTextTrim(), "", iVarPts.size(), ourModel);

    if (this.functionTableDef == null) {
      System.err.println("Unable to create new FuncTable from simple table");
      System.exit(0);
    }

    this.functionTableDef.register(this); // register ourself

    this.outVarID = outTable.getAttributeValue("varID");

    // Since this is a simple table, we need to create unique breakpoint sets

    int i = 1;
    while (iVarPtsIterator.hasNext()) {

      // get name of independent variable
      Element iVarPtsElement = iVarPtsIterator.next();
      String inVarID = iVarPtsElement.getAttributeValue("varID");
      this.addVarID(i, inVarID);

      if (this.isVerbose())
        System.out.println(
            "Added input varID '"
                + inVarID
                + "' for simple table function "
                + this.functionDefName);

      // create automatic breakpoint name/ID for this input variable
      String bpName = "auto_" + this.myName + "_bpID_" + i;

      // record fake breakpoint ID for future creation
      this.functionTableDef.addBPID(i - 1, bpName);

      // create new  breakpoint set
      Element inTable = function.getChild("independentVarPts", this.ns);
      if (inTable == null) {
        System.err.println(
            "No breakpoint values found in simple function defn of " + this.functionDefName);
        System.exit(0);
      }

      String bpDescription =
          new String(
              "Automatic breakpoint set created from simple table element named " + this.getName());
      try {
        new BreakpointSet(bpName, bpName, inTable.getTextTrim(), bpDescription, this.ourModel);
      } catch (DAVEException e) {
        System.err.println(
            "Unable to create new breakpoint set named '"
                + bpName
                + "' to support function '"
                + this.getName()
                + "':");
        System.err.println(e.getMessage());
        System.exit(0);
      }

      if (this.isVerbose())
        System.out.println(
            "Created new BreakpointSet named '"
                + bpName
                + "' for simple function "
                + this.functionDefName);

      i++; // increment count
    }
    //  tell our table to determine it's dimensionality (from bpIDs previously loaded)

    this.functionTableDef.setDimensions();
  }