/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); } */ StringWriter writer = new StringWriter(10000); printArray(data, v.getFullName(), new PrintWriter(writer), new Indent(2), ct); return writer.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()); }
/** * 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()); } }