예제 #1
0
  private boolean compareGroups(Group org, Group copy) {
    if (showCompare) f.format("compare Group %s to %s %n", org.getName(), copy.getName());
    boolean ok = true;

    if (!org.getName().equals(copy.getName())) {
      f.format(" ** names are different %s != %s %n", org.getName(), copy.getName());
      ok = false;
    }

    // dimensions
    ok &= checkAll(org.getDimensions(), copy.getDimensions(), null);

    // attributes
    ok &= checkAll(org.getAttributes(), copy.getAttributes(), null);

    // variables
    // cant use object equality, just match on short name
    for (Variable orgV : org.getVariables()) {
      Variable copyVar = copy.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" ** cant find variable %s in 2nd file%n", orgV.getFullName());
        ok = false;
      } else {
        ok &= compareVariables(orgV, copyVar, compareData, true);
      }
    }

    for (Variable copyV : copy.getVariables()) {
      Variable orgV = org.findVariable(copyV.getShortName());
      if (orgV == null) {
        f.format(" ** cant find variable %s in 1st file%n", copyV.getFullName());
        ok = false;
      }
    }

    // nested groups
    List groups = new ArrayList();
    ok &= checkAll(org.getGroups(), copy.getGroups(), groups);
    for (int i = 0; i < groups.size(); i += 2) {
      Group orgGroup = (Group) groups.get(i);
      Group ncmlGroup = (Group) groups.get(i + 1);
      ok &= compareGroups(orgGroup, ncmlGroup);
    }

    return ok;
  }
예제 #2
0
 /**
  * Test of globalAttributesToMeta method, of class NcMLUtilTest.
  *
  * @throws Exception
  */
 @Test
 public void testGlobalAttributesToMeta() throws Exception {
   Group metaGroup = NcMLUtil.globalAttributesToMeta(testFile, wrapper);
   Attribute attr = metaGroup.findAttribute("history");
   // TODO review the generated test code and remove the default call to fail.
   assertThat(attr, is(notNullValue()));
   assertThat(metaGroup.getAttributes().size(), is(equalTo(7)));
   assertThat(metaGroup.getShortName().contains("QPE.20110214.009.105"), is(true));
 }
예제 #3
0
    private void count(Group g) {
      ndims += g.getDimensions().size();
      nvars += g.getVariables().size();
      ngatts += g.getAttributes().size();
      ngroups += g.getGroups().size();

      for (Variable v : g.getVariables()) {
        natts += v.getAttributes().size();
        if (v instanceof Structure) {
          nstructFields += ((Structure) v).getVariables().size();
        }
      }
      for (Group ng : g.getGroups()) count(ng);
    }
 /**
  * Recursively parses attribute and variable paths, filling <code>attributeList</code> and <code>
  * variableList</code>.
  *
  * @param groups List of groups to recursively parse.
  */
 private void parseAttributesAndVariables(List<Group> groups) {
   for (Group group : groups) {
     String groupName = group.getName();
     List<Attribute> attributes = group.getAttributes();
     for (Attribute attribute : attributes) {
       String attributeName = attribute.getName();
       if (!groupName.endsWith("/")) attributeName = "/" + attributeName;
       attributeList.add(groupName + attributeName);
     }
     List<Variable> variables = group.getVariables();
     for (Variable variable : variables) {
       String variableName = variable.getName();
       if (!groupName.endsWith("/")) variableName = "/" + variableName;
       variableList.add(variableName);
     }
     groups = group.getGroups();
     parseAttributesAndVariables(groups);
   }
 }