예제 #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
 // 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;
   }
 }
예제 #3
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;
 }
예제 #4
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;
 }
예제 #5
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);
     }
   }
 }
예제 #6
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);
  }
예제 #7
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());
   }
 }
예제 #8
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;
 }