// look for a group with the given name. recurse into subgroups if needed. breadth first private Group findGroupNested(Group parent, String name) { for (Group g : parent.getGroups()) { if (g.getShortName().equals(name)) return g; } for (Group g : parent.getGroups()) { Group result = findGroupNested(g, name); if (result != null) return result; } return null; }
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); }
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; }
private void fixAttributes(Group g) { for (Variable v : g.getVariables()) { for (Attribute a : v.getAttributes()) { if (a.getShortName().equalsIgnoreCase("UNIT") || a.getShortName().equalsIgnoreCase("UNITS")) a.setShortName(CDM.UNITS); if (a.getShortName().equalsIgnoreCase("SCALE_FACTOR")) a.setShortName(CDM.SCALE_FACTOR); if (a.getShortName().equalsIgnoreCase("OFFSET")) a.setShortName(CDM.ADD_OFFSET); } } for (Group ng : g.getGroups()) { fixAttributes(ng); } }
void makeChildren() { children = new ArrayList<>(); List dims = group.getDimensions(); for (int i = 0; i < dims.size(); i++) children.add(new DimensionNode(this, (Dimension) dims.get(i))); List vars = group.getVariables(); for (int i = 0; i < vars.size(); i++) children.add(new VariableNode(this, (VariableIF) vars.get(i))); List groups = group.getGroups(); for (int i = 0; i < groups.size(); i++) children.add(new GroupNode(this, (Group) groups.get(i))); if (debugTree) System.out.println("children=" + group.getFullName() + " "); }