/** * Amend the given NetcdfFile with metadata from HDF-EOS structMetadata. All Variables named * StructMetadata.n, where n= 1, 2, 3 ... are read in and their contents concatenated to make the * structMetadata String. * * @param ncfile Amend this file * @param eosGroup the group containing variables named StructMetadata.* * @throws IOException on read error * @return true if HDF-EOS info was found */ public static boolean amendFromODL(NetcdfFile ncfile, Group eosGroup) throws IOException { String smeta = getStructMetadata(eosGroup); if (smeta == null) return false; HdfEos fixer = new HdfEos(); fixer.fixAttributes(ncfile.getRootGroup()); fixer.amendFromODL(ncfile, smeta); return true; }
/** * 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")); } }