Beispiel #1
0
 public static boolean getEosInfo(NetcdfFile ncfile, Group eosGroup, Formatter f)
     throws IOException {
   String smeta = getStructMetadata(eosGroup);
   if (smeta == null) {
     f.format("No StructMetadata variables in group %s %n", eosGroup.getFullName());
     return false;
   }
   f.format("raw = %n%s%n", smeta);
   ODLparser parser = new ODLparser();
   parser.parseFromString(smeta); // now we have the ODL in JDOM elements
   StringWriter sw = new StringWriter(5000);
   parser.showDoc(new PrintWriter(sw));
   f.format("parsed = %n%s%n", sw.toString());
   return true;
 }
Beispiel #2
0
  /**
   * Amend the given NetcdfFile with metadata from HDF-EOS structMetadata
   *
   * @param ncfile Amend this file
   * @param structMetadata structMetadata as String
   * @throws IOException on read error
   */
  private void amendFromODL(NetcdfFile ncfile, String structMetadata) throws IOException {
    Group rootg = ncfile.getRootGroup();

    ODLparser parser = new ODLparser();
    Element root = parser.parseFromString(structMetadata); // now we have the ODL in JDOM elements
    FeatureType featureType = null;

    // SWATH
    Element swathStructure = root.getChild("SwathStructure");
    if (swathStructure != null) {
      List<Element> swaths = swathStructure.getChildren();
      for (Element elemSwath : swaths) {
        Element swathNameElem = elemSwath.getChild("SwathName");
        if (swathNameElem == null) {
          log.warn("No SwathName element in {} {} ", elemSwath.getName(), ncfile.getLocation());
          continue;
        }
        String swathName = NetcdfFile.makeValidCdmObjectName(swathNameElem.getText().trim());
        Group swathGroup = findGroupNested(rootg, swathName);
        // if (swathGroup == null)
        //  swathGroup = findGroupNested(rootg, H4header.createValidObjectName(swathName));

        if (swathGroup != null) {
          featureType = amendSwath(ncfile, elemSwath, swathGroup);
        } else {
          log.warn("Cant find swath group {} {}", swathName, ncfile.getLocation());
        }
      }
    }

    // GRID
    Element gridStructure = root.getChild("GridStructure");
    if (gridStructure != null) {
      List<Element> grids = gridStructure.getChildren();
      for (Element elemGrid : grids) {
        Element gridNameElem = elemGrid.getChild("GridName");
        if (gridNameElem == null) {
          log.warn("No GridName element in {} {} ", elemGrid.getName(), ncfile.getLocation());
          continue;
        }
        String gridName = NetcdfFile.makeValidCdmObjectName(gridNameElem.getText().trim());
        Group gridGroup = findGroupNested(rootg, gridName);
        // if (gridGroup == null)
        //  gridGroup = findGroupNested(rootg, H4header.createValidObjectName(gridName));
        if (gridGroup != null) {
          featureType = amendGrid(elemGrid, ncfile, gridGroup, ncfile.getLocation());
        } else {
          log.warn("Cant find Grid group {} {}", gridName, ncfile.getLocation());
        }
      }
    }

    // POINT - NOT DONE YET
    Element pointStructure = root.getChild("PointStructure");
    if (pointStructure != null) {
      List<Element> pts = pointStructure.getChildren();
      for (Element elem : pts) {
        Element nameElem = elem.getChild("PointName");
        if (nameElem == null) {
          log.warn("No PointName element in {} {}", elem.getName(), ncfile.getLocation());
          continue;
        }
        String name = nameElem.getText().trim();
        Group ptGroup = findGroupNested(rootg, name);
        // if (ptGroup == null)
        //  ptGroup = findGroupNested(rootg, H4header.createValidObjectName(name));
        if (ptGroup != null) {
          featureType = FeatureType.POINT;
        } else {
          log.warn("Cant find Point group {} {}", name, ncfile.getLocation());
        }
      }
    }

    if (featureType != null) {
      if (showWork) System.out.println("***EOS featureType= " + featureType.toString());
      rootg.addAttribute(new Attribute(CF.FEATURE_TYPE, featureType.toString()));
      // rootg.addAttribute(new Attribute(CDM.CONVENTIONS, "HDFEOS"));
    }
  }