@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()); }
/** * Default constructor. */ public NetCDFServiceImpl() { // One check from each package checkClassDependency(ucar.nc2.Attribute.class); checkClassDependency(ucar.ma2.Array.class); }
@Override public Object getVariableValue(String name) throws ServiceException { return getArray(name, null, null); }
@Override public void setFile(String file) throws IOException { this.currentFile = file; init(); attributeList = new Vector<String>(); variableList = new Vector<String>(); List<Group> groups = new ArrayList<Group>(); groups.add(root); parseAttributesAndVariables(groups); }
@Override public int getDimension(String name) { String groupName = getDirectory(name); String variableName = getName(name); Group group = getGroup(groupName); return group.findDimension(variableName).getLength(); }
@Override public void read(Kryo kryo, Input in) { currentFile = kryo.readObjectOrNull(in, String.class); attributeList = kryo.readObjectOrNull(in, Vector.class); variableList = kryo.readObjectOrNull(in, Vector.class); try { init(); } catch (IOException e) { } }
/** * Recursively parses attribute and variable paths, filling * <code>attributeList</code> and <code>variableList</code>. * @param groups List of groups to recursively parse. */ private void parseAttributesAndVariables(List<Group> groups) { for (Group group : groups) { String groupName = group.getName(); List<Attribute> attributes = group.getAttributes(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!groupName.endsWith("/")) attributeName = "/" + attributeName; attributeList.add(groupName + attributeName); } List<Variable> variables = group.getVariables(); for (Variable variable : variables) { String variableName = variable.getName(); if (!groupName.endsWith("/")) variableName = "/" + variableName; variableList.add(variableName); } groups = group.getGroups(); parseAttributesAndVariables(groups); } }
@Override public int getDimension(String name) { String groupName = getDirectory(name); String variableName = getName(name); Group group = getGroup(groupName); return group.findDimension(variableName).getLength(); }
@Override public void setFile(String file) throws IOException { this.currentFile = file; init(); attributeList = new Vector<String>(); variableList = new Vector<String>(); List<Group> groups = new ArrayList<Group>(); groups.add(root); parseAttributesAndVariables(groups); }
@Override public void read(Kryo kryo, Input in) { currentFile = kryo.readObjectOrNull(in, String.class); attributeList = kryo.readObjectOrNull(in, Vector.class); variableList = kryo.readObjectOrNull(in, Vector.class); try { init(); } catch (IOException e) { } }
/** * Recursively parses attribute and variable paths, filling * <code>attributeList</code> and <code>variableList</code>. * @param groups List of groups to recursively parse. */ private void parseAttributesAndVariables(List<Group> groups) { for (Group group : groups) { String groupName = group.getName(); List<Attribute> attributes = group.getAttributes(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); if (!groupName.endsWith("/")) attributeName = "/" + attributeName; attributeList.add(groupName + attributeName); } List<Variable> variables = group.getVariables(); for (Variable variable : variables) { String variableName = variable.getName(); if (!groupName.endsWith("/")) variableName = "/" + variableName; variableList.add(variableName); } groups = group.getGroups(); parseAttributesAndVariables(groups); } }
@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 Object getArray(String path, int[] origin, int[] shape) throws ServiceException { String groupName = getDirectory(path); String variableName = getName(path); Group group = getGroup(groupName); Variable variable = group.findVariable(variableName); try { if (origin != null && shape != null) { return variable.read(origin, shape).reduce().copyToNDJavaArray(); } return variable.read().copyToNDJavaArray(); } catch (InvalidRangeException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } catch (NullPointerException e) { return null; } }
/** * Default constructor. */ public NetCDFServiceImpl() { // One check from each package checkClassDependency(ucar.nc2.Attribute.class); checkClassDependency(ucar.ma2.Array.class); }
@Override public Object getVariableValue(String name) throws ServiceException { return getArray(name, null, null); }
@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; }
@Override public Object getArray(String path, int[] origin, int[] shape) throws ServiceException { String groupName = getDirectory(path); String variableName = getName(path); Group group = getGroup(groupName); Variable variable = group.findVariable(variableName); try { if (origin != null && shape != null) { return variable.read(origin, shape).reduce().copyToNDJavaArray(); } return variable.read().copyToNDJavaArray(); } catch (InvalidRangeException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } catch (NullPointerException e) { return null; } }
@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; }