示例#1
0
 long computeFieldSize(BaseType bt, boolean isAscii) throws Exception {
   long fieldsize = 0;
   // Figure out what this field is (e.g. primitive or not)
   // Somewhat convoluted.
   if (bt instanceof DConstructor) {
     // simple struct, seq, or grid => recurse
     fieldsize = computeSize((DConstructor) bt, isAscii);
   } else if (bt instanceof DArray) {
     SDArray da = (SDArray) bt;
     // Separate structure arrays from primitive arrays
     if (da.getContainerVar() instanceof DPrimitive) {
       fieldsize = computeArraySize(da);
     } else if (da.getContainerVar() instanceof DStructure) {
       fieldsize = computeSize((DStructure) da.getContainerVar(), isAscii); // recurse
     } else { // Some kind of problem
       throw new NoSuchTypeException("Computesize: unexpected type for " + bt.getLongName());
     }
   } else if (bt instanceof DPrimitive) {
     DPrimitive dp = (DPrimitive) bt;
     if (dp instanceof DString) {
       String v = ((DString) dp).getValue();
       fieldsize = (v == null ? 0 : v.length());
     } else {
       DataType dtype = DODSNetcdfFile.convertToNCType(bt);
       fieldsize = dtype.getSize();
     }
   } else { // Some kind of problem
     throw new NoSuchTypeException("Computesize: unknown type for " + bt.getLongName());
   }
   return fieldsize;
 }
示例#2
0
  /**
   * Walks through the DDS, converts DAP data to ptII data, and broadcasts the data onto the
   * appropriate ports.
   *
   * @param dds The DDS from which to get the data to send
   * @throws IllegalActionException When bad things happen.
   */
  private void broadcastDapData(DDS dds) throws IllegalActionException {

    // log.debug("broadcastDapData(): DataDDS prior to broadcast:");
    // dds.print(System.out);

    Enumeration e = dds.getVariables();
    while (e.hasMoreElements()) {
      opendap.dap.BaseType bt = (opendap.dap.BaseType) e.nextElement();

      String columnName = bt.getLongName().trim();
      // Get the port associated with this DDS variable.
      TypedIOPort port = (TypedIOPort) this.getPort(columnName);
      if (port == null) {
        throw new IllegalActionException("Request Output Port Missing: " + columnName);
      }

      log.debug("Translating data.");
      // bt.printDecl(System.out);

      // Map the DAP data for this variable into the ptII Token model.
      ptolemy.data.Token token = TokenMapper.mapDapObjectToToken(bt, false);
      log.debug("Data Translated :");
      // bt.printDecl(System.out);

      // Send the data.
      log.debug("Sending data.");
      port.broadcast(token);
      log.debug("Sent data.");
    }
  }
示例#3
0
 // Recursively compute size of the dds to be returned
 private long computeSize(DConstructor ctor, boolean isAscii) throws Exception {
   long projectsize = 0; // accumulate size of projected variables
   long othersize = 0; // accumulate size of non-projected variables
   long fieldsize = 0;
   int projectedcount = 0;
   int fieldcount = 0;
   Enumeration vars = ctor.getVariables();
   while (vars.hasMoreElements()) {
     fieldcount++;
     BaseType field = (BaseType) vars.nextElement();
     fieldsize = computeFieldSize(field, isAscii);
     // accumulate the field sizes
     if (field.isProject()) {
       projectsize += fieldsize;
       projectedcount++;
     } else {
       othersize += fieldsize;
     }
   }
   // Cases to consider:
   // 1. If all of the fields of this ctor are projected,
   //    then return projectsize
   // 2. If none of the fields of this ctor are projected,
   //    then return othersize
   // 3. otherwise, at least one field, but not all, is projected,
   //    => return projectsize;
   if (projectedcount == fieldcount) return projectsize;
   else if (projectedcount == 0) return othersize;
   else {
     assert (projectedcount > 0 && projectedcount < fieldcount);
     return projectsize;
   }
 }
示例#4
0
 boolean containsChild(BaseType node, List<BaseType> list) {
   String nodename = node.getLongName();
   for (BaseType child : list) {
     String childname = child.getLongName();
     if (childname.startsWith(nodename)) return true;
   }
   return false;
 }
示例#5
0
 BaseType containsParent(BaseType node, List<BaseType> list) {
   String nodename = node.getLongName();
   for (BaseType parent : list) {
     String parentname = parent.getLongName();
     if (nodename.startsWith(parentname)) return parent;
   }
   return null;
 }
示例#6
0
 void gendimrange(List<BaseType> path, StringBuilder buf) {
   for (int i = 0; i < path.size(); i++) {
     BaseType bt = path.get(i);
     int rank = 0;
     if (bt.getParent() instanceof DArray) rank = ((DArray) (bt.getParent())).numDimensions();
     if (i > 0) buf.append('.');
     buf.append(bt.getEncodedName());
     for (int j = 0; j < rank; j++) {
       String dimprojection = dimrangeset[random.nextInt(dimrangeset.length)];
       buf.append(dimprojection);
     }
   }
 }
示例#7
0
  public String getLongName() {

    boolean done = false;

    BaseType parent = (BaseType) getParent();

    String longName = _name;

    while (parent != null && !(parent instanceof DDS)) {
      longName = parent.getClearName() + "." + longName;
      parent = (BaseType) parent.getParent();
    }
    return (longName);
  }
示例#8
0
 public void printConstraint(PrintWriter os) {
   BaseType parent = (BaseType) getParent();
   BaseType array = null;
   if (parent != null) {
     if (parent instanceof DArray) {
       array = parent;
       parent = (BaseType) parent.getParent();
     }
   }
   if (array != null) array.printConstraint(os);
   else {
     if (parent != null && !(parent instanceof DDS)) {
       parent.printConstraint(os);
       os.print(".");
     }
     os.print(getEncodedName());
   }
 }
示例#9
0
  /**
   * Configure the output ports to expose all of the variables at the top level of the (potentially
   * constrained) DDS.
   *
   * @param dds The DDS
   * @throws IllegalActionException When bad things happen.
   */
  private void configureOutputPorts(DDS dds) throws IllegalActionException {

    Vector<Type> types = new Vector<Type>();
    Vector<String> names = new Vector<String>();

    Enumeration e = dds.getVariables();
    while (e.hasMoreElements()) {
      opendap.dap.BaseType bt = (opendap.dap.BaseType) e.nextElement();
      types.add(TypeMapper.mapDapObjectToType(bt, false));
      names.add(bt.getLongName());
    }

    removeOtherOutputPorts(names);

    Iterator ti = types.iterator();
    Iterator ni = names.iterator();

    while (ti.hasNext() && ni.hasNext()) {
      Type type = (Type) ti.next();
      String name = (String) ni.next();
      initializePort(name, type);
    }
  }
示例#10
0
 /**
  * Returns a clone of this <code>BaseType</code>. See DAPNode.cloneDAG.
  *
  * @param map The set of already cloned nodes.
  * @return a clone of this <code>BaseType</code>.
  */
 public DAPNode cloneDAG(CloneMap map) throws CloneNotSupportedException {
   BaseType bt = (BaseType) super.cloneDAG(map);
   if (this._attrTbl != null) bt._attrTbl = (AttributeTable) cloneDAG(map, this._attrTbl);
   if (this._attr != null) bt._attr = new Attribute(getClearName(), bt._attrTbl);
   return bt;
 }