/** * Returns the name of this variable, or {@code null} if none. */ @Override public String getName() { return variable.getShortName(); }
/** * Returns the data type which most closely represents the "raw" internal data of the variable. * This is the value returned by the default implementation of {@link * NetcdfImageReader#getRawDataType}. * * @param variable The variable. * @return The data type, or {@link DataBuffer#TYPE_UNDEFINED} if unknown. * @see NetcdfImageReader#getRawDataType */ public static int getRawDataType(final VariableIF variable) { VariableDS ds = (VariableDS) variable; final DataType type; if (Boolean.getBoolean(ENHANCE_SCALE_MISSING)) { type = ds.getDataType(); } else { type = ds.getOriginalDataType(); } return transcodeNetCDFDataType(type, variable.isUnsigned()); }
private static List<Range> makeSpec(StringBuilder sb, VariableIF v, List<Range> orgRanges) throws InvalidRangeException { if (v.isMemberOfStructure()) { orgRanges = makeSpec(sb, v.getParentStructure(), orgRanges); sb.append('.'); } List<Range> ranges = (orgRanges == null) ? v.getRanges() : orgRanges; sb.append( v.isMemberOfStructure() ? v.getShortName() : v.getFullNameEscaped()); if (!v.isVariableLength() && !v.isScalar()) { // sequences cant be sectioned sb.append('('); for (int count=0; count<v.getRank(); count++) { Range r = ranges.get(count); if (r == null) r = new Range( 0, v.getDimension(count).getLength()); if (count>0) sb.append(", "); sb.append(r.first()); sb.append(':'); sb.append(r.last()); sb.append(':'); sb.append(r.stride()); } sb.append(')'); } return (orgRanges == null) ? null : ranges.subList(v.getRank(), ranges.size()); }
/** * Print a section of the data of the given Variable. * @param v variable to print * @param sectionSpec string specification * @param ct allow task to be cancelled; may be null. * @return String result formatted data ouptut * @throws IOException on write error * @throws InvalidRangeException is specified section doesnt match variable shape */ static public String printVariableDataSection(VariableIF v, String sectionSpec, ucar.nc2.util.CancelTask ct) throws IOException, InvalidRangeException { Array data = v.read(sectionSpec); ByteArrayOutputStream bos = new ByteArrayOutputStream(); printArray( data, v.getFullName(), new PrintStream( bos), ct); return bos.toString(); }
/** * Reads all the data for this variable and returns them as an array of a Java primitive type. * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a vector). * This method may cache the returned vector, at UCAR library choice. */ @Override public Vector read() throws IOException { final Array array = variable.read(); // May be cached by the UCAR library. return Vector.create(array.get1DJavaArray(array.getElementType()), variable.isUnsigned()); }
/** * Check if this Coordinate System is complete for v, ie if all its dimensions are also used by v. * @param v check for this variable * @return true if all dimensions in V (including parents) are in the domain of this coordinate system. */ public boolean isComplete(VariableIF v) { return isSubset(v.getDimensionsAll(), domain); }
/** * Returns the variable data type. * This method may return {@code UNKNOWN} if the datatype is unknown. */ @Override public DataType getDataType() { final DataType type; switch (variable.getDataType()) { case STRING: return DataType.STRING; case CHAR: return DataType.CHAR; case BYTE: type = DataType.BYTE; break; case SHORT: type = DataType.SHORT; break; case INT: type = DataType.INT; break; case LONG: type = DataType.INT64; break; case FLOAT: return DataType.FLOAT; case DOUBLE: return DataType.DOUBLE; default: return DataType.UNKNOWN; } return type.unsigned(variable.isUnsigned()); }
private static List<Range> makeSpec(StringBuilder sb, VariableIF v, List<Range> orgRanges) throws InvalidRangeException { if (v.isMemberOfStructure()) { orgRanges = makeSpec(sb, v.getParentStructure(), orgRanges); sb.append('.'); } List<Range> ranges = (orgRanges == null) ? v.getRanges() : orgRanges; sb.append( v.isMemberOfStructure() ? v.getShortName() : v.getFullNameEscaped()); if (!v.isVariableLength() && !v.isScalar()) { // sequences cant be sectioned sb.append('('); for (int count=0; count<v.getRank(); count++) { Range r = ranges.get(count); if (r == null) r = new Range( 0, v.getDimension(count).getLength()); if (count>0) sb.append(", "); sb.append(r.first()); sb.append(':'); sb.append(r.last()); sb.append(':'); sb.append(r.stride()); } sb.append(')'); } return (orgRanges == null) ? null : ranges.subList(v.getRank(), ranges.size()); }
/** * Print a section of the data of the given Variable. * @param v variable to print * @param sectionSpec string specification * @param ct allow task to be cancelled; may be null. * @return String result formatted data ouptut * @throws IOException on write error * @throws InvalidRangeException is specified section doesnt match variable shape */ static public String printVariableDataSection(VariableIF v, String sectionSpec, ucar.nc2.util.CancelTask ct) throws IOException, InvalidRangeException { Array data = v.read(sectionSpec); ByteArrayOutputStream bos = new ByteArrayOutputStream(); printArray( data, v.getFullName(), new PrintStream( bos), ct); return bos.toString(); }
/** * Reads all the data for this variable and returns them as an array of a Java primitive type. * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a vector). * This method may replace fill/missing values by NaN values and caches the returned vector. */ @Override @SuppressWarnings("ReturnOfCollectionOrArrayField") public Vector read() throws IOException { if (values == null) { final Array array = variable.read(); // May be already cached by the UCAR library. values = createDecimalVector(get1DJavaArray(array), variable.isUnsigned()); values = SHARED_VECTORS.unique(values); } return values; }
/** * Check if this Coordinate System can be used for the given variable. * A CoordinateAxis can only be part of a Variable's CoordinateSystem if the CoordinateAxis' set of Dimensions is a * subset of the Variable's set of Dimensions. * So, a CoordinateSystem' set of Dimensions must be a subset of the Variable's set of Dimensions. * @param v check for this variable * @return true if all dimensions in the domain of this coordinate system are in V (including parents). */ public boolean isCoordinateSystemFor(VariableIF v) { return isSubset(domain, v.getDimensionsAll()); }
/** * Returns the variable data type. * This method may return {@code UNKNOWN} if the datatype is unknown. * * @see #getAttributeType(String) */ @Override public DataType getDataType() { final DataType type; switch (variable.getDataType()) { case STRING: return DataType.STRING; case CHAR: return DataType.CHAR; case BYTE: type = DataType.BYTE; break; case SHORT: type = DataType.SHORT; break; case INT: type = DataType.INT; break; case LONG: type = DataType.INT64; break; case FLOAT: return DataType.FLOAT; case DOUBLE: return DataType.DOUBLE; default: return DataType.UNKNOWN; } return type.unsigned(variable.isUnsigned()); }
/** * Print all the data of the given Variable. * * @param v variable to print * @param ct allow task to be cancelled; may be null. * @return String result * @throws java.io.IOException on write error */ static public String printVariableData(VariableIF v, ucar.nc2.util.CancelTask ct) throws IOException { Array data = v.read(); /* try { data = v.isMemberOfStructure() ? v.readAllStructures(null, true) : v.read(); } catch (InvalidRangeException ex) { return ex.getMessage(); } */ StringWriter writer = new StringWriter(10000); printArray(data, v.getFullName(), new PrintWriter(writer), ct); return writer.toString(); }
/** * Reads a sub-sampled sub-area of the variable. * * @param areaLower index of the first value to read along each dimension. * @param areaUpper index after the last value to read along each dimension. * @param subsampling sub-sampling along each dimension. 1 means no sub-sampling. * @return the data as an array of a Java primitive type. */ @Override public Vector read(final int[] areaLower, final int[] areaUpper, final int[] subsampling) throws IOException, DataStoreException { final int[] size = new int[areaUpper.length]; for (int i=0; i<size.length; i++) { size[i] = areaUpper[i] - areaLower[i]; } final Array array; try { array = variable.read(new Section(areaLower, size, subsampling)); } catch (InvalidRangeException e) { throw new DataStoreContentException(e); } return Vector.create(array.get1DJavaArray(array.getElementType()), variable.isUnsigned()); } }
/** * Check if this Coordinate System can be used for the given variable. * A CoordinateAxis can only be part of a Variable's CoordinateSystem if the CoordinateAxis' set of Dimensions is a * subset of the Variable's set of Dimensions. * So, a CoordinateSystem' set of Dimensions must be a subset of the Variable's set of Dimensions. * @param v check for this variable * @return true if all dimensions in the domain of this coordinate system are in V (including parents). */ public boolean isCoordinateSystemFor(VariableIF v) { return isSubset(domain, v.getDimensionsAll()); }
/** * Returns the data type which most closely represents the "raw" internal * data of the variable. This is the value returned by the default * implementation of {@link NetcdfImageReader#getRawDataType}. * * @param variable * The variable. * @return The data type, or {@link DataBuffer#TYPE_UNDEFINED} if unknown. * * @see NetcdfImageReader#getRawDataType */ public static int getRawDataType(final VariableIF variable) { VariableDS ds = (VariableDS) variable; final DataType type = ds.getOriginalDataType(); return transcodeNetCDFDataType(type,variable.isUnsigned()); }
/** * Returns the name of this variable, or {@code null} if none. */ @Override public String getName() { return variable.getShortName(); }
/** * Print all the data of the given Variable. * @param v variable to print * @param ct allow task to be cancelled; may be null. * @return String result * @throws IOException on write error */ static public String printVariableData(VariableIF v, ucar.nc2.util.CancelTask ct) throws IOException { Array data = v.read(); /* try { data = v.isMemberOfStructure() ? v.readAllStructures(null, true) : v.read(); } catch (InvalidRangeException ex) { return ex.getMessage(); } */ ByteArrayOutputStream bos = new ByteArrayOutputStream(); printArray( data, v.getFullName(), new PrintStream( bos), ct); return bos.toString(); }
/** * Reads a sub-sampled sub-area of the variable. * Array elements are in inverse of netCDF order. * * @param area indices of cell values to read along each dimension, in "natural" order. * @param subsampling sub-sampling along each dimension. 1 means no sub-sampling. * @return the data as an array of a Java primitive type. */ @Override public Vector read(final GridExtent area, final int[] subsampling) throws IOException, DataStoreException { int n = area.getDimension(); final int[] lower = new int[n]; final int[] size = new int[n]; final int[] sub = new int[n--]; for (int i=0; i<=n; i++) { final int j = (n - i); lower[j] = Math.toIntExact(area.getLow(i)); size [j] = Math.toIntExact(area.getSize(i)); sub [j] = subsampling[i]; } final Array array; try { array = variable.read(new Section(lower, size, sub)); } catch (InvalidRangeException e) { throw new DataStoreException(e); } return Vector.create(get1DJavaArray(array), variable.isUnsigned()); }
/** * Check if this Coordinate System is complete, * ie if all its dimensions are also used by the Variable. * @param v check for this variable * @return true if all dimensions in V (including parents) are in the domain of this coordinate system. */ public boolean isComplete(VariableIF v) { return /* isCoordinateSystemFor(v) && */ isSubset(v.getDimensionsAll(), domain); }