示例#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
 long computeArraySize(SDArray da) throws Exception {
   assert (da.getContainerVar() instanceof DPrimitive);
   BaseType base = da.getPrimitiveVector().getTemplate();
   DataType dtype = DODSNetcdfFile.convertToNCType(base);
   int elemSize = dtype.getSize();
   int n = da.numDimensions();
   List<Range> ranges = new ArrayList<Range>(n);
   long size = 0;
   for (int i = 0; i < n; i++) {
     ranges.add(new Range(da.getStart(i), da.getStop(i), da.getStride(i)));
     Section s = new Section(ranges);
     size += s.computeSize() * elemSize;
   }
   return size;
 }