Esempio n. 1
0
  private void handleMetadataGroup(Group group, MetadataElement metadataElement)
      throws ProductIOException {
    List<Variable> variables = group.getVariables();
    for (Variable variable : variables) {
      final String name = variable.getShortName();
      final int dataType = getProductDataType(variable);
      Array array;
      try {
        array = variable.read();
      } catch (IOException e) {
        throw new ProductIOException(e.getMessage());
      }
      final ProductData data = ProductData.createInstance(dataType, array.getStorage());
      final MetadataAttribute attribute = new MetadataAttribute("data", data, true);

      final MetadataElement sdsElement = new MetadataElement(name);
      sdsElement.addAttribute(attribute);
      metadataElement.addElement(sdsElement);

      final List<Attribute> list = variable.getAttributes();
      for (Attribute hdfAttribute : list) {
        final String attribName = hdfAttribute.getShortName();
        if ("units".equals(attribName)) {
          attribute.setUnit(hdfAttribute.getStringValue());
        } else if ("long_name".equals(attribName)) {
          attribute.setDescription(hdfAttribute.getStringValue());
        } else {
          addAttributeToElement(sdsElement, hdfAttribute);
        }
      }
    }
  }
 /**
  * Adds a new coding value to this sample coding.
  *
  * @param name the coding name
  * @param values the values
  * @param description the description text
  * @throws IllegalArgumentException if <code>name</code> is null
  * @return A new attribute representing the coded sample.
  */
 public MetadataAttribute addSamples(String name, int[] values, String description) {
   Guardian.assertNotNull("name", name);
   final ProductData productData =
       ProductData.createInstance(ProductData.TYPE_INT32, values.length);
   MetadataAttribute attribute = new MetadataAttribute(name, productData, false);
   attribute.setDataElems(values);
   if (description != null) {
     attribute.setDescription(description);
   }
   addAttribute(attribute);
   return attribute;
 }