public static double[] getDoubleValues(Attribute attribute) { final Array values = attribute.getValues(); final long size = values.getSize(); final double[] result = new double[(int) size]; for (int i = 0; i < size; i++) { result[i] = values.getDouble(i); } return result; }
public static float[] getFloatValues(Attribute attribute) { final Array values = attribute.getValues(); final long size = values.getSize(); final float[] result = new float[(int) size]; for (int i = 0; i < size; i++) { result[i] = values.getFloat(i); } return result; }
public static int[] getIntValues(Attribute attribute) { final Array values = attribute.getValues(); final long size = values.getSize(); final int[] result = new int[(int) size]; for (int i = 0; i < size; i++) { result[i] = values.getInt(i); } return result; } }
/** * Rename a global Attribute. Must be in define mode. * @param oldName existing Attribute has this name * @param newName rename to this * @return renamed Attribute, or null if not found */ public Attribute renameGlobalAttribute(String oldName, String newName) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); Attribute att = findGlobalAttribute(oldName); if (null == att) return null; rootGroup.remove(att); att = new Attribute( newName, att.getValues()); rootGroup.addAttribute( att); return att; }
/** * Rename a global Attribute. Must be in define mode. * @param oldName existing Attribute has this name * @param newName rename to this * @return renamed Attribute, or null if not found */ public Attribute renameGlobalAttribute(String oldName, String newName) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); Attribute att = findGlobalAttribute(oldName); if (null == att) return null; rootGroup.remove(att); att = new Attribute( newName, att.getValues()); rootGroup.addAttribute( att); return att; }
/** * Rename a global Attribute. Must be in define mode. * @param oldName existing Attribute has this name * @param newName rename to this * @return renamed Attribute, or null if not found */ public Attribute renameGlobalAttribute(String oldName, String newName) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); Attribute att = findGlobalAttribute(oldName); if (null == att) return null; rootGroup.remove(att); att = new Attribute( newName, att.getValues()); rootGroup.addAttribute( att); return att; }
/** * Rename a variable Attribute. Must be in define mode. * @param v Variable to modify attribute * @param attName existing Attribute has this name * @param newName rename to this * @return renamed Attribute, or null if not found */ public Attribute renameVariableAttribute(Variable v, String attName, String newName) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); Attribute att = v.findAttribute(attName); if (null == att) return null; v.remove(att); att = new Attribute( newName, att.getValues()); v.addAttribute(att); return att; }
/** * Add a Global attribute to the file. Must be in define mode. * @param att the attribute. * @return the created attribute */ public Attribute addGlobalAttribute(Attribute att) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); if (!N3iosp.isValidNetcdfObjectName(att.getShortName())) { String attName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); log.warn("illegal netCDF-3 attribute name= "+att.getShortName() + " change to "+ attName); att = new Attribute(attName, att.getValues()); } return super.addAttribute(null, att); }
@Override public Hashtable<String, Object> getVariableAttributes(String name) { String groupName = getDirectory(name); String variableName = getName(name); Group group = getGroup(groupName); Variable variable = group.findVariable(variableName); Hashtable<String, Object> toReturn = new Hashtable<String, Object>(); if (variable != null) { List<Attribute> attributes = variable.getAttributes(); for (Attribute attribute: attributes) { toReturn.put(attribute.getName(), arrayToString(attribute.getValues())); } } return toReturn; }
/** * Add a Global attribute to the file. Must be in define mode. * @param g the group to add to. if null, use root group * @param att the attribute. * @return the created attribute */ public Attribute addGroupAttribute(Group g, Attribute att) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); if (!isValidObjectName(att.getShortName())) { String attName = createValidObjectName(att.getShortName()); log.warn("illegal attribute name= "+att.getShortName() + " change to "+ attName); att = new Attribute(attName, att.getValues()); } return ncfile.addAttribute(g, att); }
/** * Add a Global attribute to the file. Must be in define mode. * @param att the attribute. * @return the created attribute */ public Attribute addGlobalAttribute(Attribute att) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); if (!N3iosp.isValidNetcdfObjectName(att.getShortName())) { String attName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); log.warn("illegal netCDF-3 attribute name= "+att.getShortName() + " change to "+ attName); att = new Attribute(attName, att.getValues()); } return super.addAttribute(null, att); }
/** * Add a Global attribute to the file. Must be in define mode. * @param att the attribute. * @return the created attribute */ public Attribute addGlobalAttribute(Attribute att) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); if (!N3iosp.isValidNetcdfObjectName(att.getShortName())) { String attName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); log.warn("illegal netCDF-3 attribute name= "+att.getShortName() + " change to "+ attName); att = new Attribute(attName, att.getValues()); } return super.addAttribute(null, att); }
@Override public String getAttributeValue(String path) { String groupName = getDirectory(path); String attributeName = getName(path); Group group = getGroup(groupName); Attribute attribute = group.findAttribute(attributeName); if (attribute == null) return null; return arrayToString(attribute.getValues()); }
@Override public String getAttributeValue(String path) { String groupName = getDirectory(path); String attributeName = getName(path); Group group = getGroup(groupName); Attribute attribute = group.findAttribute(attributeName); if (attribute == null) return null; return arrayToString(attribute.getValues()); }
/** converts a ucar.nc2.Attribute into an ncsa.hdf.object.Attribute */ public static ncsa.hdf.object.Attribute convertAttribute( ucar.nc2.Attribute netcdfAttr) { ncsa.hdf.object.Attribute ncsaAttr = null; if (netcdfAttr == null) { return null; } String attrName = netcdfAttr.getName(); long[] attrDims = { netcdfAttr.getLength() }; Datatype attrType = new NC2Datatype(netcdfAttr.getDataType()); ncsaAttr = new ncsa.hdf.object.Attribute(attrName, attrType, attrDims); ncsaAttr.setValue(netcdfAttr.getValues()); return ncsaAttr; }
private Attribute convertAttribute(Attribute org) { if (version.isExtendedModel()) return org; if (!org.getDataType().isUnsigned()) return org; Array orgValues = org.getValues(); Array nc3Values = Array.makeFromJavaArray(orgValues.getStorage(), false); return new Attribute(org.getShortName(), nc3Values); }
/** * Write a global attribute to the file. * * @param att take attribute name, value, from here */ public void writeGlobalAttribute(Attribute att) { String useName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); if (att.isArray()) // why rewrite them ?? ncfile.addGlobalAttribute(useName, att.getValues()); else if (att.isString()) ncfile.addGlobalAttribute(useName, att.getStringValue()); else ncfile.addGlobalAttribute(useName, att.getNumericValue()); }
/** * Write a global attribute to the file. * * @param att take attribute name, value, from here */ public void writeGlobalAttribute(Attribute att) { String useName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); if (att.isArray()) // why rewrite them ?? ncfile.addGlobalAttribute(useName, att.getValues()); else if (att.isString()) ncfile.addGlobalAttribute(useName, att.getStringValue()); else ncfile.addGlobalAttribute(useName, att.getNumericValue()); }
/** * Write a global attribute to the file. * * @param att take attribute name, value, from here */ public void writeGlobalAttribute(Attribute att) { String useName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); if (att.isArray()) // why rewrite them ?? ncfile.addGlobalAttribute(useName, att.getValues()); else if (att.isString()) ncfile.addGlobalAttribute(useName, att.getStringValue()); else ncfile.addGlobalAttribute(useName, att.getNumericValue()); }
/** * Write a Variable attribute to the file. * * @param varName name of variable to attach attribute to * @param att take attribute name, value, from here */ public void writeAttribute(String varName, Attribute att) { String attName = N3iosp.makeValidNetcdfObjectName(att.getShortName()); varName = N3iosp.makeValidNetcdfObjectName(varName); if (att.isArray()) ncfile.addVariableAttribute(varName, attName, att.getValues()); else if (att.isString()) ncfile.addVariableAttribute(varName, attName, att.getStringValue()); else ncfile.addVariableAttribute(varName, attName, att.getNumericValue()); }