public TableConfig readConfigXML( String fileLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + fileLocation + ">"); doc = builder.build(fileLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println( "*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; }
public TableConfig readConfigXMLfromResource( String resourceLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { ClassLoader cl = this.getClass().getClassLoader(); try (InputStream is = cl.getResourceAsStream(resourceLocation)) { if (is == null) throw new FileNotFoundException(resourceLocation); if (debugXML) { System.out.println(" PointConfig URL = <" + resourceLocation + ">"); try (InputStream is2 = cl.getResourceAsStream(resourceLocation)) { System.out.println(" contents=\n" + IO.readContents(is2)); } } org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + resourceLocation + ">"); doc = builder.build(is); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println( "*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); assert tableElem != null; TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; } }
/** * 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")); } }
public static void read(org.jdom2.Element root, StringBuilder errlog) { List children = root.getChildren(); for (int i = 0; i < children.size(); i++) { Element elem = (Element) children.get(i); if (elem.getName().equals("ioServiceProvider")) { String className = elem.getAttributeValue("class"); try { ucar.nc2.NetcdfFile.registerIOProvider(className); } catch (ClassNotFoundException e) { errlog.append( "CoordSysBuilder class not found= " + className + "; check your classpath\n"); } catch (Exception e) { errlog.append("IOServiceProvider " + className + " failed= " + e.getMessage() + "\n"); } } else if (elem.getName().equals("coordSysBuilder")) { String conventionName = elem.getAttributeValue("convention"); String className = elem.getAttributeValue("class"); try { ucar.nc2.dataset.CoordSysBuilder.registerConvention(conventionName, className); } catch (ClassNotFoundException e) { errlog.append( "CoordSysBuilder class not found= " + className + "; check your classpath\n"); } catch (Exception e) { errlog.append("CoordSysBuilder " + className + " failed= " + e.getMessage() + "\n"); } } else if (elem.getName().equals("coordTransBuilder")) { String transformName = elem.getAttributeValue("name"); String className = elem.getAttributeValue("class"); try { ucar.nc2.dataset.CoordTransBuilder.registerTransform(transformName, className); } catch (ClassNotFoundException e) { errlog.append( "CoordSysBuilder class not found= " + className + "; check your classpath\n"); } catch (Exception e) { errlog.append("CoordTransBuilder " + className + " failed= " + e.getMessage() + "\n"); } } else if (elem.getName().equals("typedDatasetFactory")) { String typeName = elem.getAttributeValue("datatype"); String className = elem.getAttributeValue("class"); FeatureType datatype = FeatureType.valueOf(typeName.toUpperCase()); if (null == datatype) { errlog.append( "TypedDatasetFactory " + className + " unknown datatype= " + typeName + "\n"); continue; } try { ucar.nc2.dt.TypedDatasetFactory.registerFactory(datatype, className); } catch (ClassNotFoundException e) { errlog.append( "CoordSysBuilder class not found= " + className + "; check your classpath\n"); } catch (Exception e) { errlog.append("TypedDatasetFactory " + className + " failed= " + e.getMessage() + "\n"); } } else if (elem.getName().equals("gribParameterTable")) { String editionS = elem.getAttributeValue("edition"); String centerS = elem.getAttributeValue("center"); String subcenterS = elem.getAttributeValue("subcenter"); String versionS = elem.getAttributeValue("version"); String filename = elem.getText(); if ((centerS == null) || (versionS == null) || (filename == null)) { errlog.append("table element must center, version and filename attributes\n"); continue; } // Grib1ParamTables.addParameterTable(int center, int subcenter, int tableVersion, String // filename) { // use reflection to decouple from the grib package try { int center = Integer.parseInt(centerS); int subcenter = (subcenterS == null) ? -1 : Integer.parseInt(subcenterS); int version = Integer.parseInt(versionS); // ucar.nc2.grib.grib1.tables.Grib1ParamTables.addParameterTable(int center, int // subcenter, int tableVersion, String tableFilename) Class c = RuntimeConfigParser.class .getClassLoader() .loadClass("ucar.nc2.grib.grib1.tables.Grib1ParamTables"); Method m = c.getMethod("addParameterTable", int.class, int.class, int.class, String.class); m.invoke(null, center, subcenter, version, filename); } catch (Exception e) { e.printStackTrace(); } String strictS = elem.getAttributeValue("strict"); if (strictS != null) { boolean notStrict = strictS.equalsIgnoreCase("false"); try { Class c = RuntimeConfigParser.class .getClassLoader() .loadClass("ucar.grib.grib1.tables.Grib1ParamTables"); Method m = c.getMethod("setStrict", boolean.class); m.invoke(null, !notStrict); } catch (Exception e) { e.printStackTrace(); } continue; } } else if (elem.getName().equals("gribParameterTableLookup")) { String editionS = elem.getAttributeValue("edition"); String filename = elem.getText(); // ucar.nc2.grib.grib1.tables.Grib1ParamTables.addParameterTableLookup(String // lookupFilename) try { Class c = RuntimeConfigParser.class .getClassLoader() .loadClass("ucar.nc2.grib.grib1.tables.Grib1ParamTables"); Method m = c.getMethod("addParameterTableLookup", String.class); m.invoke(null, filename); } catch (Exception e) { e.printStackTrace(); } } else if (elem.getName().equals("table")) { String type = elem.getAttributeValue("type"); String filename = elem.getAttributeValue("filename"); if ((type == null) || (filename == null)) { errlog.append("table element must have both type and filename attributes\n"); continue; } try { if (type.equalsIgnoreCase("GRIB1")) { // ucar.grib.grib1.GribPDSParamTable.addParameterUserLookup( filename); // use reflection instead to decouple from the grib package try { Class c = RuntimeConfigParser.class .getClassLoader() .loadClass("ucar.grib.grib1.GribPDSParamTable"); Method m = c.getMethod("addParameterUserLookup", String.class); m.invoke(null, filename); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } else if (type.equalsIgnoreCase("GRIB2")) { // ucar.grib.grib2.ParameterTable.addParametersUser( filename); try { Class c = RuntimeConfigParser.class .getClassLoader() .loadClass(" ucar.grib.grib2.ParameterTable"); Method m = c.getMethod("addParametersUser", String.class); m.invoke(null, filename); } catch (Exception e) { e.printStackTrace(); } } else { errlog.append("Unknown table type " + type + "\n"); continue; } } catch (Exception e) { errlog.append("table read failed on " + filename + " = " + e.getMessage() + "\n"); } } else if (elem.getName().equals("bufrtable")) { String filename = elem.getAttributeValue("filename"); if (filename == null) { errlog.append("bufrtable must have filename attribute\n"); continue; } // reflection is used to decouple optional jars Class bufrTablesClass; try { bufrTablesClass = RuntimeConfigParser.class .getClassLoader() .loadClass( "ucar.nc2.iosp.bufr.tables.BufrTables"); // only load if bufr.jar is present java.lang.Class[] params = new Class[1]; params[0] = String.class; Method method = bufrTablesClass.getMethod("addLookupFile", params); Object[] args = new Object[1]; args[0] = filename; method.invoke(null, args); // static method has null for object } catch (Throwable e) { if (e instanceof FileNotFoundException) errlog.append("bufrtable read failed on " + filename + " = " + e.getMessage() + "\n"); else errlog.append("bufr.jar is not on classpath\n"); } } else if (elem.getName().equals("Netcdf4Clibrary")) { // cdm does not have a dependency on netcdf4 (and we don't want to introduce one), // so we cannot refer to the Nc4Iosp.class object. String nc4IospClassName = "ucar.nc2.jni.netcdf.Nc4Iosp"; /* <Netcdf4Clibrary> <libraryPath>/usr/local/lib</libraryPath> <libraryName>netcdf</libraryName> <useForReading>false</useForReading> </Netcdf4Clibrary> */ String path = elem.getChildText("libraryPath"); String name = elem.getChildText("libraryName"); if (path != null && name != null) { // reflection is used to decouple optional jars try { Class nc4IospClass = RuntimeConfigParser.class.getClassLoader().loadClass(nc4IospClassName); Method method = nc4IospClass.getMethod( "setLibraryAndPath", new Class[] {String.class, String.class}); method.invoke(null, path, name); // static method has null for object } catch (Throwable e) { errlog.append(nc4IospClassName + " is not on classpath\n"); } } boolean useForReading = Boolean.parseBoolean(elem.getChildText("useForReading")); if (useForReading) { try { // Registers Nc4Iosp in front of all the other IOSPs already registered in // NetcdfFile.<clinit>(). // Crucially, this means that we'll try to open a file with Nc4Iosp before we try it // with H5iosp. NetcdfFile.registerIOProvider(nc4IospClassName); } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) { errlog.append( String.format( "Could not register IOSP '%s': %s%n", nc4IospClassName, e.getMessage())); } } } } }
public DatasetEditor() { JTabbedPane tabs = new JTabbedPane(); metadataPP = new PrefPanel("Edit Catalog Dataset", null, null); tabs.add("metadata", metadataPP); int row = 0; metadataPP.addHeading("Basic", row++); // row 0 metadataPP.addTextField(NAME, "Name", "", 0, row++, "8,1"); // row 1 metadataPP.addTextField(ID, "ID", "", 0, row, null); addPopups(metadataPP.addTextField(AUTHORITY, "Authority", "", 2, row, null)); addPopups(metadataPP.addTextField(SERVICE_NAME, "Service", "", 4, row, null)); row++; // row 2 addPopups( metadataPP.addEnumComboField( FORMAT_TYPE, "Data format", DataFormatType.getAllTypes(), true, 0, row, null)); addPopups( metadataPP.addEnumComboField( DATA_TYPE, "Data type", Arrays.asList(FeatureType.values()), true, 2, row, null)); metadataPP.addEnumComboField( COLLECTION_TYPE, "Collection type", CollectionType.getAllTypes(), true, 4, row++, null); //////////// metadataPP.addHeading("GeoSpatial Coverage", row++); // addCheckBoxField("localMetadata.geospatialCoverage.global", "Global", false, 0, row); gc_type = metadataPP.addEnumComboField(GC_TYPE, "type", inherit_types, false, 0, row, null); gc_type.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String mode = (String) gc_type.getValue(); setGCmode(getMode(mode)); } }); extractGCButton = makeButton("Extract Geospatial"); extractGCButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { extractGeospatial(); } }); metadataPP.addComponent(extractGCButton, 2, row, "left, center"); metadataPP.addCheckBoxField(ZPOSITIVE_UP, "Z positive up", false, 4, row); row++; /* JPanel geoPanel = new JPanel(); Field.CheckBox global = new Field.CheckBox( "localMetadata.geospatialCoverage.global", "Global", false, persBean); geoPanel.add( new JLabel("Global: ")); geoPanel.add( global.getEditComponent()); geoPanel.add( new JButton("Read Dataset")); pp.addComponent(geoPanel, 0, row++, "left, center"); */ // 4 columns in 3 rows metadataPP.addDoubleField(LAT_START, "Starting Latitude", 0.0, 5, 0, row, null); metadataPP.addDoubleField(LAT_EXTENT, "Size", 0.0, 5, 2, row, null); metadataPP.addDoubleField(LAT_RESOLUTION, "Resolution", 0.0, 5, 4, row, null); metadataPP.addTextField(LAT_UNITS, "Units", "", 6, row, null); metadataPP.addDoubleField(LON_START, "Starting Longitude", 0.0, 5, 0, row + 1, null); metadataPP.addDoubleField(LON_EXTENT, "Size", 0.0, 5, 2, row + 1, null); metadataPP.addDoubleField(LON_RESOLUTION, "Resolution", 0.0, 5, 4, row + 1, null); metadataPP.addTextField(LON_UNITS, "Units", "", 6, row + 1, null); metadataPP.addDoubleField(HEIGHT_START, "Starting Height", 0.0, 5, 0, row + 2, null); metadataPP.addDoubleField(HEIGHT_EXTENT, "Size", 0.0, 5, 2, row + 2, null); metadataPP.addDoubleField(HEIGHT_RESOLUTION, "Resolution", 0.0, 5, 4, row + 2, null); metadataPP.addTextField(HEIGHT_UNITS, "Units", "", 6, row + 2, null); // addTextField("localMetadata.geospatialCoverage.ZPositive", "Z is Positive", "up", 6, row+3, // null); row += 3; ////// metadataPP.addHeading("Temporal Coverage", row++); tc_type = metadataPP.addEnumComboField(TC_TYPE, "type", inherit_types, false, 0, row++, null); tc_type.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String mode = (String) tc_type.getValue(); setTCmode(getMode(mode)); } }); DateRange range = null; try { range = new DateRange(); } catch (Exception e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } dateRangeSelector = new RangeDateSelector("", range, false, false, null, false, false); DateField minDateField = dateRangeSelector.getMinDateField(); DateField maxDateField = dateRangeSelector.getMaxDateField(); DurationField durationField = dateRangeSelector.getDurationField(); DurationField resolutionField = dateRangeSelector.getResolutionField(); metadataPP.addField(minDateField, 0, row, null); metadataPP.addField(maxDateField, 2, row, null); metadataPP.addField(durationField, 4, row, null); metadataPP.addField(resolutionField, 6, row++, null); //// metadataPP.addHeading("Digital Library Info", row++); metadataPP.addCheckBoxField(HARVEST, "Harvest", false, 0, row++); addPopups(metadataPP.addTextAreaField(SUMMARY, "Summary", null, 7, 0, row, "3,1")); addPopups(metadataPP.addTextAreaField(RIGHTS, "Rights", null, 2, 0, row + 1, "3,1")); addPopups(metadataPP.addTextAreaField(HISTORY, "History", null, 7, 4, row, "3,1")); addPopups(metadataPP.addTextAreaField(PROCESSING, "Process", null, 2, 4, row + 1, "3,1")); row += 2; metadataPP.addEmptyRow(row++, 10); JTabbedPane tabPane = new JTabbedPane(); metadataPP.addComponent(tabPane, 0, row, "8,1"); ArrayList<Field.BeanTableField> tables = new ArrayList<>(); tabPane.addTab("Variables", makeVariablesPanel()); tables.add(variablesFld); creatorsFld = new Field.BeanTableField( CREATORS, "Creators", null, ThreddsMetadata.Source.class, null, null); tabPane.addTab("Creators", creatorsFld.getEditComponent()); tables.add(creatorsFld); publishersFld = new Field.BeanTableField( PUBLISHERS, "Publishers", null, ThreddsMetadata.Source.class, null, null); tabPane.addTab("Publishers", publishersFld.getEditComponent()); tables.add(publishersFld); projectsFld = new Field.BeanTableField( PROJECTS, "Projects", null, ThreddsMetadata.Vocab.class, null, null); tabPane.addTab("Projects", projectsFld.getEditComponent()); tables.add(projectsFld); keywordsFld = new Field.BeanTableField( KEYWORDS, "Keywords", null, ThreddsMetadata.Vocab.class, null, null); tabPane.addTab("Keywords", keywordsFld.getEditComponent()); tables.add(keywordsFld); datesFld = new Field.BeanTableField(DATES, "Dates", null, DateType.class, null, null); tabPane.addTab("Dates", datesFld.getEditComponent()); tables.add(datesFld); contributorsFld = new Field.BeanTableField( CONTRIBUTORS, "Contributors", null, ThreddsMetadata.Contributor.class, null, null); tabPane.addTab("Contributors", contributorsFld.getEditComponent()); tables.add(contributorsFld); docsFld = new Field.BeanTableField( DOCUMENTATION, "Documentation", null, InvDocumentation.class, null, null); tabPane.addTab("Documentation", docsFld.getEditComponent()); tables.add(docsFld); for (Field.BeanTableField table : tables) addPopups(table); metadataPP.finish(false); makeDscanPanel(); tabs.add("datasetScan", dscanPP); setLayout(new BorderLayout()); add(tabs, BorderLayout.CENTER); }