private static int getRasterDataType(final Variable variable) { return getProductDataType(variable.getDataType(), variable.isUnsigned(), true); }
public static int getProductDataType(Variable variable) { return getProductDataType(variable.getDataType(), variable.isUnsigned(), true); }
public static int getRasterDataType(Variable variable) { return getRasterDataType(variable.getDataType(), variable.isUnsigned()); }
protected Array readData(ucar.nc2.Variable v, Section ranges) throws IOException, InvalidRangeException { long start = 0; if (showRequest) { System.out.printf("Data request for variable: %s section %s", v.getFullName(), ranges); start = System.currentTimeMillis(); } /* if (unlocked) { String info = cache.getInfo(this); throw new IllegalStateException("File is unlocked - cannot use\n" + info); } */ if (spi == null) { throw new IOException("spi is null, perhaps file has been closed. Trying to read variable " + v.getFullName()); } Array result = spi.readData(v, ranges); result.setUnsigned(v.isUnsigned()); if (showRequest) { long took = System.currentTimeMillis() - start; System.out.printf(" took= %d msecs%n", took); } return result; }
protected Array readData(ucar.nc2.Variable v, Section ranges) throws IOException, InvalidRangeException { long start = 0; if (showRequest) { System.out.printf("Data request for variable: %s section %s", v.getFullName(), ranges); start = System.currentTimeMillis(); } /* if (unlocked) { String info = cache.getInfo(this); throw new IllegalStateException("File is unlocked - cannot use\n" + info); } */ if (spi == null) { throw new IOException("spi is null, perhaps file has been closed. Trying to read variable " + v.getFullName()); } Array result = spi.readData(v, ranges); result.setUnsigned(v.isUnsigned()); if (showRequest) { long took = System.currentTimeMillis() - start; System.out.printf(" took= %d msecs%n", took); } return result; }
private void processVariable(Variable v, Array mdata, Counter count) throws IOException { String name = v.getShortName(); String units = v.getUnitsString(); Attribute bwAtt = v.findAttribute("BUFR:bitWidth"); int bitWidth = bwAtt == null ? 0 : bwAtt.getNumericValue().intValue(); if (showData) out.format("%svar='%s' units='%s' : ", indent, name, units); mdata.resetLocalIterator(); while (mdata.hasNext()) { count.nvals++; if (v.isUnsigned()) { if (isMissingUnsigned(v, mdata, bitWidth)) count.nmiss++; } else { if (isMissing(v, mdata, bitWidth)) count.nmiss++; } } if (showData) out.format("%n"); }
/** * Read a variable using the given section specification. * The result is always an array of the type of the innermost variable. * Its shape is the accumulation of all the shapes of its parent structures. * * @param variableSection the constraint expression. * @return data requested * @throws IOException if error * @throws InvalidRangeException if variableSection is invalid * @see <a href="http://www.unidata.ucar.edu/software/netcdf-java/reference/SectionSpecification.html">SectionSpecification</a> */ public Array readSection(String variableSection) throws IOException, InvalidRangeException { /* if (unlocked) throw new IllegalStateException("File is unlocked - cannot use"); */ ParsedSectionSpec cer = ParsedSectionSpec.parseVariableSection(this, variableSection); if (cer.child == null) { Array result = cer.v.read(cer.section); result.setUnsigned(cer.v.isUnsigned()); return result; } if (spi == null) return IospHelper.readSection(cer); else // allow iosp to optimize return spi.readSection(cer); }
/** * Read a variable using the given section specification. * The result is always an array of the type of the innermost variable. * Its shape is the accumulation of all the shapes of its parent structures. * * @param variableSection the constraint expression. * @return data requested * @throws IOException if error * @throws InvalidRangeException if variableSection is invalid * @see <a href="http://www.unidata.ucar.edu/software/netcdf-java/reference/SectionSpecification.html">SectionSpecification</a> */ public Array readSection(String variableSection) throws IOException, InvalidRangeException { /* if (unlocked) throw new IllegalStateException("File is unlocked - cannot use"); */ ParsedSectionSpec cer = ParsedSectionSpec.parseVariableSection(this, variableSection); if (cer.child == null) { Array result = cer.v.read(cer.section); result.setUnsigned(cer.v.isUnsigned()); return result; } if (spi == null) return IospHelper.readSection(cer); else // allow iosp to optimize return spi.readSection(cer); }
static public ucar.ma2.Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException { Variable inner = null; List<Range> totalRanges = new ArrayList<>(); ParsedSectionSpec current = cer; while (current != null) { totalRanges.addAll(current.section.getRanges()); inner = current.v; current = current.child; } assert inner != null; Section total = new Section(totalRanges); Array result = Array.factory(inner.getDataType(), total.getShape()); // must be a Structure Structure outer = (Structure) cer.v; Structure outerSubset = outer.select(cer.child.v.getShortName()); // allows IOSPs to optimize for this case ArrayStructure outerData = (ArrayStructure) outerSubset.read(cer.section); extractSection(cer.child, outerData, result.getIndexIterator()); result.setUnsigned(cer.v.isUnsigned()); return result; }
result.data.setUnsigned(v.isUnsigned()); return result.data;
static public ucar.ma2.Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException { Variable inner = null; List<Range> totalRanges = new ArrayList<Range>(); ParsedSectionSpec current = cer; while (current != null) { totalRanges.addAll(current.section.getRanges()); inner = current.v; current = current.child; } Section total = new Section(totalRanges); Array result = Array.factory(inner.getDataType(), total.getShape()); // must be a Structure Structure outer = (Structure) cer.v; Structure outerSubset = outer.select(cer.child.v.getShortName()); // allows IOSPs to optimize for this case ArrayStructure outerData = (ArrayStructure) outerSubset.read(cer.section); extractSection(cer.child, outerData, result.getIndexIterator()); result.setUnsigned(cer.v.isUnsigned()); return result; }
private static int getRasterDataType(Variable variable, DataTypeWorkarounds workarounds) { if (workarounds != null && workarounds.hasWorkaround(variable.getFullName(), variable.getDataType())) { return workarounds.getRasterDataType(variable.getFullName(), variable.getDataType()); } int rasterDataType = DataTypeUtils.getRasterDataType(variable); if (rasterDataType == -1) { if (variable.getDataType() == DataType.LONG) { rasterDataType = variable.isUnsigned() ? ProductData.TYPE_UINT32 : ProductData.TYPE_INT32; } } return rasterDataType; }
private static FlagCoding readFlagCoding(Variable variable, String codingName) { final Attribute flagMasks = variable.findAttribute(FLAG_MASKS); final int[] maskValues; if (flagMasks != null) { final Array flagMasksArray = flagMasks.getValues(); // must set the unsigned property explicitly, // even though it is set when writing the flag_masks attribute flagMasksArray.setUnsigned(variable.isUnsigned()); maskValues = new int[flagMasks.getLength()]; for (int i = 0; i < maskValues.length; i++) { maskValues[i] = flagMasksArray.getInt(i); } } else { maskValues = null; } final Attribute flagMeanings = variable.findAttribute(FLAG_MEANINGS); final String[] flagNames; if (flagMeanings != null) { flagNames = flagMeanings.getStringValue().split(" "); } else { flagNames = null; } return createFlagCoding(codingName, maskValues, flagNames); }
private static FlagCoding readFlagCoding(Variable variable, String codingName) { final Attribute flagMasks = variable.findAttribute(FLAG_MASKS); final int[] maskValues; if (flagMasks != null) { final Array flagMasksArray = flagMasks.getValues(); // must set the unsigned property explicitly, // even though it is set when writing the flag_masks attribute flagMasksArray.setUnsigned(variable.isUnsigned()); maskValues = new int[flagMasks.getLength()]; for (int i = 0; i < maskValues.length; i++) { maskValues[i] = flagMasksArray.getInt(i); } } else { maskValues = null; } final Attribute flagMeanings = variable.findAttribute(FLAG_MEANINGS); final String[] flagNames; if (flagMeanings != null) { flagNames = flagMeanings.getStringValue().split(" "); } else { flagNames = null; } return createFlagCoding(codingName, maskValues, flagNames); }
/** * Set the data values from a list of Strings. * * @param values list of Strings * @throws IllegalArgumentException if values array not correct size, or values wont parse to the correct type */ public void setValues(List<String> values) throws IllegalArgumentException { Array data = Array.makeArray(getDataType(), isUnsigned(), values); if (data.getSize() != getSize()) throw new IllegalArgumentException("Incorrect number of values specified for the Variable " + getFullName() + " needed= " + getSize() + " given=" + data.getSize()); if (getRank() != 1) // dont have to reshape for rank 1 data = data.reshape(getShape()); setCachedData(data, true); }
/** * Set the data values from a list of Strings. * * @param v for this variable * @param values list of Strings * @throws IllegalArgumentException if values array not correct size, or values wont parse to the correct type * @deprecated use Variable.setValues() */ public void setValues(Variable v, List<String> values) throws IllegalArgumentException { Array data = Array.makeArray(v.getDataType(), v.isUnsigned(), values); if (data.getSize() != v.getSize()) throw new IllegalArgumentException("Incorrect number of values specified for the Variable " + v.getFullName() + " needed= " + v.getSize() + " given=" + data.getSize()); if (v.getRank() != 1) // dont have to reshape for rank 1 data = data.reshape(v.getShape()); v.setCachedData(data, true); }
private static void addAttribute(Variable variable, MetadataElement valuesElem, int maxNumValuesRead) { final DataType ncDataType = variable.getDataType(); final boolean unsigned = variable.isUnsigned(); final boolean rasterDataOnly = false; final int productDataType = DataTypeUtils.getEquivalentProductDataType(ncDataType, unsigned, rasterDataOnly); if (productDataType == -1) { return; } final Array values; try { long variableSize = variable.getSize(); if (variableSize >= maxNumValuesRead && maxNumValuesRead >= 0) { values = variable.read(new int[]{0}, new int[]{maxNumValuesRead}); valuesElem.setDescription("Showing " + maxNumValuesRead + " of " + variableSize + " values."); } else { values = variable.read(); } final ProductData pd = ReaderUtils.createProductData(productDataType, values); final MetadataAttribute attribute = new MetadataAttribute("data", pd, true); valuesElem.addAttribute(attribute); } catch (IOException | InvalidRangeException e) { Debug.trace(e); } } }
if (v.getDataType() == DataType.STRING) continue; int field_typeid = convertDataType(v.getDataType(), v.isUnsigned()); if (v.isScalar()) ret = nc4.nc_insert_compound(g4.grpid, typeid, v.getShortName(), new SizeT(offset), field_typeid);
static NcStreamProto.Variable.Builder encodeVar(Variable var, int sizeToCache) throws IOException { NcStreamProto.Variable.Builder builder = NcStreamProto.Variable.newBuilder(); builder.setName(var.getShortName()); builder.setDataType(encodeDataType(var.getDataType())); if (var.isUnsigned()) builder.setUnsigned(true); if (var.getDataType().isEnum()) { EnumTypedef enumType = var.getEnumTypedef(); if (enumType != null) builder.setEnumType(enumType.getShortName()); } for (Dimension dim : var.getDimensions()) { builder.addShape(encodeDim(dim)); } for (Attribute att : var.getAttributes()) { builder.addAtts(encodeAtt(att)); } // put small amounts of data in header "immediate mode" if (var.isCaching() && var.getDataType().isNumeric()) { if (var.isCoordinateVariable() || var.getSize() * var.getElementSize() < sizeToCache) { Array data = var.read(); ByteBuffer bb = data.getDataAsByteBuffer(); builder.setData(ByteString.copyFrom(bb.array())); } } return builder; }
static NcStreamProto.Variable.Builder encodeVar(Variable var, int sizeToCache) throws IOException { NcStreamProto.Variable.Builder builder = NcStreamProto.Variable.newBuilder(); builder.setName(var.getShortName()); builder.setDataType(encodeDataType(var.getDataType())); if (var.isUnsigned()) builder.setUnsigned(true); if (var.getDataType().isEnum()) { EnumTypedef enumType = var.getEnumTypedef(); if (enumType != null) builder.setEnumType(enumType.getShortName()); } for (Dimension dim : var.getDimensions()) { builder.addShape(encodeDim(dim)); } for (Attribute att : var.getAttributes()) { builder.addAtts(encodeAtt(att)); } // put small amounts of data in header "immediate mode" if (var.isCaching() && var.getDataType().isNumeric()) { if (var.isCoordinateVariable() || var.getSize() * var.getElementSize() < sizeToCache) { Array data = var.read(); ByteBuffer bb = data.getDataAsByteBuffer(); builder.setData(ByteString.copyFrom(bb.array())); } } return builder; }