/** * Returns the netCDF attribute of the given name in the given group, or {@code null} if none. * This method is invoked for every global and group attributes to be read by this class (but * not {@linkplain ucar.nc2.VariableSimpleIF variable} attributes), thus providing a single point * where we can filter the attributes to be read - if we want to do that in a future version. * * <p>The {@code name} argument is typically (but is not restricted too) one of the constants * defined in the {@link org.apache.sis.storage.netcdf.AttributeNames} class.</p> * * @param group the group in which to search the attribute, or {@code null} for global attributes. * @param name the name of the attribute to search (can not be null). * @return the attribute, or {@code null} if none. */ private Attribute findAttribute(final Group group, final String name) { return (group != null) ? group.findAttributeIgnoreCase(name) : file.findGlobalAttributeIgnoreCase(name); }
/** * Returns the netCDF attribute of the given name in the given group, or {@code null} if none. * This method is invoked for every global and group attributes to be read by this class (but * not {@linkplain ucar.nc2.VariableSimpleIF variable} attributes), thus providing a single point * where we can filter the attributes to be read - if we want to do that in a future version. * * <p>The {@code name} argument is typically (but is not restricted too) one of the constants * defined in the {@link org.apache.sis.storage.netcdf.AttributeNames} class.</p> * * @param group the group in which to search the attribute, or {@code null} for global attributes. * @param name the name of the attribute to search (can not be null). * @return the attribute, or {@code null} if none. */ private Attribute findAttribute(final Group group, final String name) { return (group != null) ? group.findAttributeIgnoreCase(name) : file.findGlobalAttributeIgnoreCase(name); }
public int readAttributeInteger(Variable v, String attName, int defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Integer.parseInt(att.getStringValue()); else return att.getNumericValue().intValue(); }
public double readAttributeDouble(Variable v, String attName, double defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Double.parseDouble(att.getStringValue()); else return att.getNumericValue().doubleValue(); }
public int readAttributeInteger(Variable v, String attName, int defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Integer.parseInt(att.getStringValue()); else return att.getNumericValue().intValue(); }
public int readAttributeInteger(Variable v, String attName, int defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Integer.parseInt(att.getStringValue()); else return att.getNumericValue().intValue(); }
public double readAttributeDouble(Variable v, String attName, double defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Double.parseDouble(att.getStringValue()); else return att.getNumericValue().doubleValue(); }
public double readAttributeDouble(Variable v, String attName, double defValue) { Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if (att == null) return defValue; if (att.isString()) return Double.parseDouble(att.getStringValue()); else return att.getNumericValue().doubleValue(); }
/** * Find a String-valued global or variable Attribute by * Attribute name (ignore case), return the Value of the Attribute. * If not found return defaultValue * * @param v the variable or null for global attribute * @param attName the (full) name of the attribute, case insensitive * @param defaultValue return this if attribute not found * @return the attribute value, or defaultValue if not found */ public String findAttValueIgnoreCase(Variable v, String attName, String defaultValue) { String attValue = null; Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if ((att != null) && att.isString()) attValue = att.getStringValue(); if (null == attValue) // not found, use default attValue = defaultValue; return attValue; }
/** * Find a String-valued global or variable Attribute by * Attribute name (ignore case), return the Value of the Attribute. * If not found return defaultValue * * @param v the variable or null for global attribute * @param attName the (full) name of the attribute, case insensitive * @param defaultValue return this if attribute not found * @return the attribute value, or defaultValue if not found */ public String findAttValueIgnoreCase(Variable v, String attName, String defaultValue) { String attValue = null; Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if ((att != null) && att.isString()) attValue = att.getStringValue(); if (null == attValue) // not found, use default attValue = defaultValue; return attValue; }
/** * Find a String-valued global or variable Attribute by * Attribute name (ignore case), return the Value of the Attribute. * If not found return defaultValue * * @param v the variable or null for global attribute * @param attName the (full) name of the attribute, case insensitive * @param defaultValue return this if attribute not found * @return the attribute value, or defaultValue if not found */ public String findAttValueIgnoreCase(Variable v, String attName, String defaultValue) { String attValue = null; Attribute att; if (v == null) att = rootGroup.findAttributeIgnoreCase(attName); else att = v.findAttributeIgnoreCase(attName); if ((att != null) && att.isString()) attValue = att.getStringValue(); if (null == attValue) // not found, use default attValue = defaultValue; return attValue; }
Attribute orgConv = root.findAttributeIgnoreCase(CDM.CONVENTIONS); String convAtt = CoordSysBuilder.buildConventionAttribute("CF-1.4", (orgConv == null ? null : orgConv.getStringValue())); root.addAttribute(new Attribute(CDM.CONVENTIONS, convAtt));