/** * 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()); }
/** * 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 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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; }
/** * 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()); }
/** * 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()); } }