Beispiel #1
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;
   }
 }
  /**
   * Eliminates array dimensions whose dimensions are 1 (and thus in practice don't exisit)
   *
   * @param dds The DDS to traverse and squeeze its member arrays.
   */
  public static void squeezeArrays(DConstructor dds) {

    DArray a;

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

      if (bt instanceof DArray) {
        a = (DArray) bt;
        log.debug("Squeezing array " + a.getTypeName() + " " + a.getLongName() + ";");
        a.squeeze();
        // System.out.print("Post squeezing: ");
        // a.printDecl(System.out);
        bt = a.getPrimitiveVector().getTemplate();
        if (bt instanceof DConstructor) squeezeArrays((DConstructor) bt);
      } else if (bt instanceof DConstructor) {
        squeezeArrays((DConstructor) bt);
      }
    }
  }