- Common ways to obtain Dimension
private void myMethod () {Dimension d =
Variable v;v.getDimension(0)
NetcdfDataset ds;String str;ds.findDimension(str)
Group g;String name;g.findDimension(name)
- Smart code suggestions by Codota
}
public static int getDimensionLength(Variable var, final int dimensionIndex) { return var.getDimension(dimensionIndex).getLength(); }
/** * Get Z Dimension Lenght for standard CF variables * * @param var * @return */ public static int getZDimensionLength(Variable var) { final int rank = var.getRank(); if (rank > 2) { return var.getDimension(rank - Z_DIMENSION).getLength(); } // TODO: Should I avoid use this method in case of 2D Variables? return 0; }
private int[] getDimShapes(List<Dimension> dims) { int[] dimShapes = new int[dims.size()]; int dimCounter = 0; for (Dimension dim : dims) { dimShapes[dimCounter++] = dim.getLength(); } return dimShapes; }
xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";"); xhtml.newline();
private long[] _computeChunkingUnlimited(Variable v) { List<Dimension> dims = v.getDimensions(); long[] result = new long[dims.size()]; int count = 0; for (Dimension d : dims) { if (d.isUnlimited()) result[count++] = 1; else result[count++] = d.getLength(); } return result; }
public static void writeFromFile(NetcdfFile fileIn, String fileOutName) throws IOException { DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileOutName), 10 * 1000)); N3outputStreamWriter writer = new N3outputStreamWriter(fileIn); int numrec = fileIn.getUnlimitedDimension() == null ? 0 : fileIn.getUnlimitedDimension().getLength(); writer.writeHeader(stream, numrec); writer.writeDataAll(stream); stream.close(); }
static private boolean hasDimension_( NetcdfFile ncFile, String name, int min, int max ) { boolean result = false; Dimension d = ncFile.findDimension( name ); if ( d != null ) { final int size = d.getLength(); result = inRangeI_( size, min, max ); } return result; }
private int[] computeChunkingGrib(Variable v) { int n = v.getRank(); int[] result = new int[n]; if( n < 2 ) { result[0] = 1; // Unlimited variable with rank 1 } else { for (int i=0; i<n; i++) result[i] = (i<n-2) ? 1 : v.getDimension(i).getLength(); } return result; } }
private int[] computeChunkingGrib(Variable v) { int n = v.getRank(); int[] result = new int[n]; if( n < 2 ) { result[0] = 1; // Unlimited variable with rank 1 } else { for (int i=0; i<n; i++) result[i] = (i<n-2) ? 1 : v.getDimension(i).getLength(); } return result; } }
xhtml.newline(); for (Dimension dim : ncFile.getDimensions()) { xhtml.element("li", dim.getFullName() + " = " + dim.getLength());
@Override public void hashCodeShow(Indent indent) { System.out.printf("%sDim hash = %d%n", indent, hashCode()); System.out.printf("%s shortName '%s' = %d%n", indent, getShortName(), getShortName() == null ? -1 : getShortName().hashCode()); System.out.printf("%s getLength %s%n", indent, getLength()); System.out.printf("%s isUnlimited %s%n", indent, isUnlimited()); System.out.printf("%s isVariableLength %s%n", indent, isVariableLength()); System.out.printf("%s isShared %s%n", indent, isShared()); if (getGroup() != null) System.out.printf("%s parentGroup %s = %d%n", indent, getGroup(), getGroup().hashCode()); }
@Override public int getDimension(String name) { String groupName = getDirectory(name); String variableName = getName(name); Group group = getGroup(groupName); return group.findDimension(variableName).getLength(); }
private Element makeDim( Dimension dim) { Element dimElem = new Element("dimension", thredds.client.catalog.Catalog.ncmlNS); dimElem.setAttribute("name", dim.getShortName()); dimElem.setAttribute("length", Integer.toString(dim.getLength())); if (dim.isUnlimited()) dimElem.setAttribute("isUnlimited", "true"); return dimElem; }
public StructureDataIterator getStructureDataIterator(Cursor cursor, int bufferSize) throws IOException { StructureData parentStruct = cursor.getParentStructure(); if (parentStruct instanceof StructureDataProxy) parentStruct = ((StructureDataProxy) parentStruct).getOriginalStructureData(); // tricky dicky ArrayStructureMA asma = new ArrayStructureMA(sm, new int[]{inner.getLength()}); for (String colName : cols.keySet()) { Array data = parentStruct.getArray(colName); StructureMembers.Member childm = sm.findMember(colName); childm.setDataArray(data); } return asma.getStructureDataIterator(); }
private static void read(GridDatatype gdt, Count count, int rtIndex, int tIndex, Dimension zDim) throws IOException { if (zDim != null) { for (int z = 0; z < zDim.getLength(); z++) read(gdt, count, rtIndex, tIndex, z); } else { read(gdt, count, rtIndex, tIndex, -1); } }
public static Element writeDimension(Dimension dim, Namespace ns) { Element dimElem = new Element("dimension", ns); dimElem.setAttribute("name", dim.getShortName()); dimElem.setAttribute("length", Integer.toString(dim.getLength())); if (dim.isUnlimited()) dimElem.setAttribute("isUnlimited", "true"); if (dim.isVariableLength()) dimElem.setAttribute("isVariableLength", "true"); return dimElem; }
private CoordinateAxis makeFakeCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) { if (dim == null) return null; CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.SHORT, dim.getShortName(), "", "synthesized coordinate: only an index"); v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoZ")); if (!axisName.equals(dim.getShortName())) v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); v.setValues(dim.getLength(), 0, 1); return v; }
private CoordinateAxis makeLonCoordAxis(NetcdfDataset ds, String axisName, Dimension dim) { if (dim == null) return null; double dx = 4 * findAttributeDouble(ds, "DX"); int nx = dim.getLength(); double startx = centerX - dx * (nx - 1) / 2; CoordinateAxis v = new CoordinateAxis1D(ds, null, axisName, DataType.DOUBLE, dim.getShortName(), "degrees_east", "synthesized longitude coordinate"); ds.setValues(v, nx, startx, dx); v.addAttribute(new Attribute(_Coordinate.AxisType, "Lon")); if (!axisName.equals(dim.getShortName())) v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); return v; }
static NcStreamProto.Dimension.Builder encodeDim(Dimension dim) { NcStreamProto.Dimension.Builder dimBuilder = NcStreamProto.Dimension.newBuilder(); if (dim.getShortName() != null) dimBuilder.setName(dim.getShortName()); if (!dim.isVariableLength()) dimBuilder.setLength(dim.getLength()); dimBuilder.setIsPrivate(!dim.isShared()); dimBuilder.setIsVlen(dim.isVariableLength()); dimBuilder.setIsUnlimited(dim.isUnlimited()); return dimBuilder; }