public boolean compareVariables(NetcdfFile org, NetcdfFile copy) { f.format("Original = %s%n", org.getLocation()); f.format("CompareTo= %s%n", copy.getLocation()); boolean ok = true; for (Variable orgV : org.getVariables()) { if (orgV.isCoordinateVariable()) continue; Variable copyVar = copy.findVariable(orgV.getShortName()); if (copyVar == null) { f.format(" MISSING '%s' in 2nd file%n", orgV.getFullName()); ok = false; } else { List<Dimension> dims1 = orgV.getDimensions(); List<Dimension> dims2 = copyVar.getDimensions(); if (!compare(dims1, dims2)) { f.format(" %s != %s%n", orgV.getNameAndDimensions(), copyVar.getNameAndDimensions()); } else { // f.format(" ok %s%n", orgV.getName()); } } } f.format("%n"); for (Variable orgV : copy.getVariables()) { if (orgV.isCoordinateVariable()) continue; Variable copyVar = org.findVariable(orgV.getShortName()); if (copyVar == null) { f.format(" MISSING '%s' in 1st file%n", orgV.getFullName()); ok = false; } } return ok; }
public List<VariableBean> getVariableBeans(NetcdfFile ds) { List<VariableBean> vlist = new ArrayList<VariableBean>(); for (Variable v : ds.getVariables()) { vlist.add(new VariableBean(v)); } return vlist; }
/** Create a DAS for this netcdf file */ NcDAS(NetcdfFile ncfile) { // Variable attributes Iterator iter = ncfile.getVariables().iterator(); while (iter.hasNext()) { Variable v = (Variable) iter.next(); doVariable(v, null); } // Global attributes opendap.dap.AttributeTable gtable = new opendap.dap.AttributeTable("NC_GLOBAL"); int count = addAttributes(gtable, null, ncfile.getGlobalAttributes().iterator()); if (count > 0) try { addAttributeTable("NC_GLOBAL", gtable); } catch (AttributeExistsException e) { log.error("Cant add NC_GLOBAL", e); } // unlimited dimension iter = ncfile.getDimensions().iterator(); while (iter.hasNext()) { Dimension d = (Dimension) iter.next(); if (d.isUnlimited()) { opendap.dap.AttributeTable table = new opendap.dap.AttributeTable("DODS_EXTRA"); try { table.appendAttribute("Unlimited_Dimension", opendap.dap.Attribute.STRING, d.getName()); addAttributeTable("DODS_EXTRA", table); } catch (Exception e) { log.error("Error adding Unlimited_Dimension =" + e); } break; } } // unused dimensions opendap.dap.AttributeTable dimTable = null; iter = ncfile.getDimensions().iterator(); while (iter.hasNext()) { Dimension d = (Dimension) iter.next(); if (null == usedDims.get(d.getName())) { if (dimTable == null) dimTable = new opendap.dap.AttributeTable("EXTRA_DIMENSION"); try { dimTable.appendAttribute( d.getName(), opendap.dap.Attribute.INT32, Integer.toString(d.getLength())); } catch (Exception e) { log.error("Error adding Unlimited_Dimension =" + e); } } } if (dimTable != null) try { addAttributeTable("EXTRA_DIMENSION", dimTable); } catch (AttributeExistsException e) { log.error("Cant add EXTRA_DIMENSION", e); } }