private String getDecl( VariableEnhanced ve) { Formatter sb = new Formatter(); sb.format("%s ", ve.getDataType().toString()); ve.getNameAndDimensions(sb, true, true); return sb.toString(); }
private VariableEnhanced findVariableFromOrgName(String orgName) { for (Variable vTop : getVariables()) { Variable v = vTop; while (v instanceof VariableEnhanced) { VariableEnhanced ve = (VariableEnhanced) v; if ((ve.getOriginalName() != null) && (ve.getOriginalName().equals(orgName))) return (VariableEnhanced) vTop; v = ve.getOriginalVariable(); } } return null; }
/** * Clear Coordinate System metadata, to allow them to be redone */ public void clearCoordinateSystems() { coordSys = new ArrayList<CoordinateSystem>(); coordAxes = new ArrayList<CoordinateAxis>(); coordTransforms = new ArrayList<CoordinateTransform>(); for (Variable v : getVariables()) { VariableEnhanced ve = (VariableEnhanced) v; ve.clearCoordinateSystems(); // ?? } enhanceMode.remove(Enhance.CoordSystems); }
public int compare(Object o1, Object o2) { VariableEnhanced v1 = (VariableEnhanced) o1; VariableEnhanced v2 = (VariableEnhanced) o2; List list1 = v1.getCoordinateSystems(); String cs1 = (list1.size() > 0) ? ((CoordinateSystem) list1.get(0)).getName() : ""; List list2 = v2.getCoordinateSystems(); String cs2 = (list2.size() > 0) ? ((CoordinateSystem) list2.get(0)).getName() : ""; if (cs2.equals(cs1)) return v1.getShortName().compareToIgnoreCase(v2.getShortName()); else return cs1.compareToIgnoreCase(cs2); }
varElem.setAttribute("name", var.getShortName()); List dims = var.getDimensions(); for (int i = 0; i < dims.size(); i++) { Dimension dim = (Dimension) dims.get(i); DataType dt = var.getDataType(); if (dt != null) varElem.setAttribute("type", dt.toString()); for (Attribute att : var.getAttributes()) { varElem.addContent(writeAttribute(att, "attribute", ncNS)); if (var.isMetadata() || (var == aggCoord)) varElem.addContent(writeValues(var, ncNS, true));
if (ve.getCoordinateSystems().size() == 1) { existing = ve.getCoordinateSystems().get(0); if (!existing.isImplicit()) continue; // cant overrrride explicit if (existing.getRankRange() >= ve.getRank()) continue; // looks ok implicit = existing; CoordinateSystem cs = ncDataset.findCoordinateSystem(csName); if (cs != null) { if (null != implicit) ve.removeCoordinateSystem(implicit); ve.addCoordinateSystem(cs); parseInfo.format(" assigned maximal CoordSystem '%s' for var= %s%n", cs.getName(), ve.getFullName()); } else { CoordinateSystem csnew = new CoordinateSystem(ncDataset, axisList, null); csnew.setImplicit(true); if (null != implicit) ve.removeCoordinateSystem(implicit); ve.addCoordinateSystem(csnew); ncDataset.addCoordinateSystem(csnew); parseInfo.format(" created maximal CoordSystem '%s' for var= %s%n", csnew.getName(), ve.getFullName());
Array a; try { a = v.read(); } catch (IOException ioe) { return elem; if (v.getDataType() == DataType.CHAR) { char[] data = (char[]) a.getStorage(); elem.setText(new String(data)); } else if (v.getDataType() == DataType.STRING) { // use seperate elements?? IndexIterator iter = a.getIndexIterator(); int count = 0; elem.setAttribute("start", Double.toString(start)); elem.setAttribute("increment", Double.toString(incr)); elem.setAttribute("npts", Long.toString(v.getSize())); return elem; boolean isRealType = (v.getDataType() == DataType.DOUBLE) || (v.getDataType() == DataType.FLOAT); IndexIterator iter = a.getIndexIterator(); buff.append(isRealType ? iter.getDoubleNext() : iter.getIntNext());
} else if (!targetV.hasCachedData() && (targetVe.getOriginalVariable() == null)) { targetVe.setOriginalVariable(v);
public boolean hasCoordinateSystem() { return ((VariableEnhanced) v).getCoordinateSystems().size() > 0; }
rootElem.addContent(gridElem); gridElem.setAttribute("name", ve.getFullName()); gridElem.setAttribute("decl", getDecl(ve)); if (ve.getUnitsString() != null) { gridElem.setAttribute(CDM.UNITS, ve.getUnitsString()); gridElem.setAttribute("udunits", isUdunits(ve.getUnitsString())); rootElem.addContent(elem); elem.setAttribute("name", ve.getFullName()); elem.setAttribute("decl", getDecl(ve)); if (ve.getUnitsString() != null) { elem.setAttribute(CDM.UNITS, ve.getUnitsString()); elem.setAttribute("udunits", isUdunits(ve.getUnitsString()));
protected Variable findVariable(NetcdfFile ncfile, Variable mainV) { Variable v = ncfile.findVariable(mainV.getFullNameEscaped()); if (v == null) { // might be renamed VariableEnhanced ve = (VariableEnhanced) mainV; v = ncfile.findVariable(ve.getOriginalName()); // LOOK not escaped } return v; }
@Override public String getFullName() { return ve.getFullName(); }
ok &= checkAll(orgds.getFullName(), orgds.getCoordinateSystems(), copyds.getCoordinateSystems(), matches); for (int i = 0; i < matches.size(); i += 2) { CoordinateSystem orgCs = (CoordinateSystem) matches.get(i);
ve.addCoordinateSystem(cs); parseInfo.format(" assigned maximal CoordSystem '%s' for var= %s%n", cs.getName(), ve.getFullName()); ve.addCoordinateSystem(csnew); ncDataset.addCoordinateSystem(csnew); parseInfo.format(" created maximal CoordSystem '%s' for var= %s%n", csnew.getName(), ve.getFullName());
assert t1 instanceof VariableEnhanced; VariableEnhanced dsVar = (VariableEnhanced) t1; assert( dsVar.getDataType() == DataType.DOUBLE); A = dsVar.read(); ima = A.getIndex(); shape = A.getShape();
/** * DO NOT USE DIRECTLY. public by accident. * recalc any enhancement info */ public void enhance(Set<NetcdfDataset.Enhance> mode) { for (Variable v : getVariables()) { VariableEnhanced ve = (VariableEnhanced) v; ve.enhance(mode); } }
/** * Determine if the CoordinateSystem cs can be made into a GridCoordSys for the Variable v. * * @param sbuff put debug information into this StringBuffer; may be null. * @param cs CoordinateSystem to check. * @param v Variable to check. * @return the GridCoordSys made from cs, else null. */ public static GridCoordSys makeGridCoordSys(Formatter sbuff, CoordinateSystem cs, VariableEnhanced v) { if (sbuff != null) { sbuff.format(" "); v.getNameAndDimensions(sbuff, false, true); sbuff.format(" check CS %s: ", cs.getName()); } if (isGridCoordSys(sbuff, cs, v)) { GridCoordSys gcs = new GridCoordSys(cs, sbuff); if (sbuff != null) sbuff.format(" OK%n"); return gcs; } return null; }
/** * Does this axis "fit" this variable. * True if all of the dimensions in the axis also appear in the variable. * If char variable, last dimension is left out. * * @param axis check if this axis is ok for the given variable * @param v the given variable * @return true if all of the dimensions in the axis also appear in the variable. */ protected boolean isCoordinateAxisForVariable(Variable axis, VariableEnhanced v) { List<Dimension> varDims = v.getDimensionsAll(); List<Dimension> axisDims = axis.getDimensionsAll(); // a CHAR variable must really be a STRING, so leave out the last (string length) dimension int checkDims = axisDims.size(); if (axis.getDataType() == DataType.CHAR) checkDims--; for (int i = 0; i < checkDims; i++) { Dimension axisDim = axisDims.get(i); if (!varDims.contains(axisDim)) { return false; } } return true; }
ve.addCoordinateSystem(ap.cs); VariableEnhanced ve = (VariableEnhanced) vp.v; if (CoordinateSystem.isSubset(dimList, vp.v.getDimensionsAll()) && CoordinateSystem.isSubset(vp.v.getDimensionsAll(), dimList)) ve.addCoordinateSystem(csVar.cs); CoordinateSystem cs = ncDataset.findCoordinateSystem(coordSysName); if (cs != null) { ve.addCoordinateSystem(cs); parseInfo.format(" assigned explicit CoordSystem '%s' for var= %s\n", cs.getName(), vp.v.getFullName()); } else { CoordinateSystem csnew = new CoordinateSystem(ncDataset, dataAxesList, null); ve.addCoordinateSystem(csnew); ncDataset.addCoordinateSystem(csnew); parseInfo.format(" created explicit CoordSystem '%s' for var= %s\n", csnew.getName(), vp.v.getFullName());
@Override public DataType getDataType() { return ve.getDataType(); }