/** * Read an NcML file from a URL location, and construct a NetcdfDataset. * * @param ncmlLocation the URL location string of the NcML document * @param cancelTask allow user to cancel the task; may be null * @return the resulting NetcdfDataset * @throws IOException on read error, or bad referencedDatasetUri URI */ static public NetcdfDataset readNcML(String ncmlLocation, CancelTask cancelTask) throws IOException { return readNcML(ncmlLocation, (String) null, cancelTask); }
public void augmentDataset(NetcdfDataset ncDataset, CancelTask cancelTask) throws IOException { NcMLReader.wrapNcMLresource(ncDataset, CoordSysBuilder.resourcesDir + "ATDRadar.ncml", cancelTask); }
/** * Use NCML to directly modify the dataset * * @param targetDS referenced dataset * @param parentElem parent element - usually the aggregation element of the ncml * @return new dataset with the merged info * @throws IOException on read error */ static public NetcdfDataset mergeNcMLdirect(NetcdfDataset targetDS, Element parentElem) throws IOException { NcMLReader reader = new NcMLReader(); reader.readGroup(targetDS, targetDS, null, null, parentElem); targetDS.finish(); return targetDS; }
/** * Read NcML from a JDOM Document, and pass in the name of the dataset. Used to augment datasetScan with NcML * * @param ncmlLocation the URL location string of the NcML document, used as a unique name for caching purposes. * @param netcdfElem the JDOM Document's root (netcdf) element * @param referencedDatasetUri the URL location string of the underlying dataset, which overrides anything in netcdfElem. * prepend with "file:" to eliminate reletive resolving against ncmlLocation * @param cancelTask allow user to cancel the task; may be null * @return the resulting NetcdfDataset * @throws IOException on read error, or bad referencedDatasetUri URI */ static public NetcdfDataset readNcML(String ncmlLocation, Element netcdfElem, String referencedDatasetUri, CancelTask cancelTask) throws IOException { NcMLReader reader = new NcMLReader(); return reader._readNcML(ncmlLocation, referencedDatasetUri, netcdfElem, cancelTask); }
/** * Read NcML from a JDOM Document, and construct a NetcdfDataset. * * @param ncmlLocation the URL location string of the NcML document, used to resolve reletive path of the referenced dataset, * or may be just a unique name for caching purposes. * @param netcdfElem the JDOM Document's root (netcdf) element * @param cancelTask allow user to cancel the task; may be null * @return the resulting NetcdfDataset * @throws IOException on read error, or bad referencedDatasetUri URI */ static public NetcdfDataset readNcML(String ncmlLocation, Element netcdfElem, CancelTask cancelTask) throws IOException { // the ncml probably refers to another dataset, but doesnt have to String referencedDatasetUri = netcdfElem.getAttributeValue("location"); if (referencedDatasetUri == null) referencedDatasetUri = netcdfElem.getAttributeValue("url"); NcMLReader reader = new NcMLReader(); return reader.readNcML(ncmlLocation, referencedDatasetUri, netcdfElem, cancelTask); }
if (refv == null) { // new if (debugConstruct) System.out.println(" add new var = " + name); Variable nested = readVariableNew(ds, parentS.getParentGroup(), parentS, varElem); parentS.addMemberVariable(nested); return; readAtt(v, refv, attElem); cmdRemove(v, remElem.getAttributeValue("type"), remElem.getAttributeValue("name")); java.util.List<Element> varList = varElem.getChildren("variable", ncNS); for (Element vElem : varList) { readVariableNested(ds, s, refS, vElem); readValues(ds, v, varElem, valueElem);
readAtt(g, refg, attElem); readEnumTypedef(g, refg, elem); readDim(g, refg, dimElem); readVariable(newds, g, refg, varElem); cmdRemove(g, e.getAttributeValue("type"), e.getAttributeValue("name")); readGroup(newds, refds, g, refg, gElem); if (debugConstruct) System.out.println(" add group = " + g.getFullName());
if (nameInFile == null) nameInFile = name; else if (null == findAttribute(refParent, nameInFile)) { // has to exists errlog.format("NcML attribute orgName '%s' doesnt exist. att=%s in=%s%n", nameInFile, name, parent); return; ucar.nc2.Attribute att = findAttribute(refParent, nameInFile); if (att == null) { // new if (debugConstruct) System.out.println(" add new att = " + name); try { ucar.ma2.Array values = readAttributeValues(attElem); addAttribute(parent, new ucar.nc2.Attribute(name, values)); } catch (RuntimeException e) { errlog.format("NcML new Attribute Exception: %s att=%s in=%s%n", e.getMessage(), name, parent); if (hasValue) { try { ucar.ma2.Array values = readAttributeValues(attElem); addAttribute(parent, new ucar.nc2.Attribute(name, values)); } catch (RuntimeException e) { errlog.format("NcML existing Attribute Exception: %s att=%s in=%s%n", e.getMessage(), name, parent); addAttribute(parent, new ucar.nc2.Attribute(name, att.getValues())); removeAttribute(parent, att); if (debugConstruct) System.out.println(" remove old att = " + nameInFile);
/** * Use NCML to modify the dataset, getting NcML from a URL * * @param ncDataset modify this dataset * @param ncmlLocation URL location of NcML * @param cancelTask allow user to cancel task; may be null * @throws IOException on read error */ static public void wrapNcML(NetcdfDataset ncDataset, String ncmlLocation, CancelTask cancelTask) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(); if (debugURL) System.out.println(" NetcdfDataset URL = <" + ncmlLocation + ">"); doc = builder.build(ncmlLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** NetcdfDataset/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element netcdfElem = doc.getRootElement(); NcMLReader reader = new NcMLReader(); reader.readNetcdf(ncmlLocation, ncDataset, ncDataset, netcdfElem, cancelTask); if (debugOpen) System.out.println("***NcMLReader.wrapNcML result= \n" + ncDataset); }
if (convNcML != null) { CoordSysBuilder csb = new CoordSysBuilder(); NcMLReader.wrapNcML(ds, convNcML, cancelTask); return csb;
public NetcdfFile acquireFile(CancelTask cancelTask) throws IOException { if (debugOpenFile) System.out.println(" try to acquire " + cacheLocation); long start = System.currentTimeMillis(); NetcdfFile ncfile = NetcdfDataset.acquireFile(reader, null, cacheLocation, -1, cancelTask, spiObject); // must merge NcML before enhancing if (mergeNcml != null) ncfile = NcMLReader.mergeNcML(ncfile, mergeNcml); // create new dataset if (enhance == null || enhance.isEmpty()) { if (debugOpenFile) System.out.println(" acquire (no enhance) " + cacheLocation + " took " + (System.currentTimeMillis() - start)); return ncfile; } // must enhance NetcdfDataset ds; if (ncfile instanceof NetcdfDataset) { ds = (NetcdfDataset) ncfile; ds.enhance(enhance); // enhance "in place", ie modify the NetcdfDataset } else { ds = new NetcdfDataset(ncfile, enhance); // enhance when wrapping } if (debugOpenFile) System.out.println(" acquire (enhance) " + cacheLocation + " took " + (System.currentTimeMillis() - start)); return ds; }
NcMLReader.mergeNcMLdirect(result, protoConfig.outerNcml);
if (refv == null) { // new if (debugConstruct) System.out.println(" add new var = " + name); Variable nested = readVariableNew(ds, parentS.getParentGroup(), parentS, varElem); if (nested != null) parentS.addMemberVariable(nested); return; readAtt(v, refv, attElem); cmdRemove(v, remElem.getAttributeValue("type"), remElem.getAttributeValue("name")); java.util.List<Element> varList = varElem.getChildren("variable", ncNS); for (Element vElem : varList) { readVariableNested(ds, s, refS, vElem); readValues(ds, v, varElem, valueElem);
readAtt(g, refg, attElem); readEnumTypedef(g, refg, elem); readDim(g, refg, dimElem); readVariable(newds, g, refg, varElem); cmdRemove(g, e.getAttributeValue("type"), e.getAttributeValue("name")); readGroup(newds, refds, g, refg, gElem); if (debugConstruct) System.out.println(" add group = " + g.getFullName());
if (nameInFile == null) nameInFile = name; else if (null == findAttribute(refParent, nameInFile)) { // has to exists errlog.format("NcML attribute orgName '%s' doesnt exist. att=%s in=%s%n", nameInFile, name, parent); return; ucar.nc2.Attribute oldatt = findAttribute(refParent, nameInFile); if (oldatt == null) { // new if (debugConstruct) System.out.println(" add new att = " + name); try { ucar.ma2.Array values = readAttributeValues(attElem); addAttribute(parent, new ucar.nc2.Attribute(name, values)); } catch (RuntimeException e) { errlog.format("NcML new Attribute Exception: %s att=%s in=%s%n", e.getMessage(), name, parent); if (hasValue) { // has a new value try { ucar.ma2.Array values = readAttributeValues(attElem); addAttribute(parent, new ucar.nc2.Attribute(name, values)); } catch (RuntimeException e) { errlog.format("NcML existing Attribute Exception: %s att=%s in=%s%n", e.getMessage(), name, parent); Array oldval = oldatt.getValues(); if (oldval != null) addAttribute(parent, new ucar.nc2.Attribute(name, oldatt.getValues())); else { // weird corner case of attribute with no value - must use the type String unS = attElem.getAttributeValue("isUnsigned"); String typeS = attElem.getAttributeValue("type");
/** * Use NCML to modify the dataset, getting NcML from a URL * * @param ncDataset modify this dataset * @param ncmlLocation URL location of NcML * @param cancelTask allow user to cancel task; may be null * @throws IOException on read error */ static public void wrapNcML(NetcdfDataset ncDataset, String ncmlLocation, CancelTask cancelTask) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(); if (debugURL) System.out.println(" NetcdfDataset URL = <" + ncmlLocation + ">"); doc = builder.build(ncmlLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** NetcdfDataset/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element netcdfElem = doc.getRootElement(); NcMLReader reader = new NcMLReader(); reader.readNetcdf(ncmlLocation, ncDataset, ncDataset, netcdfElem, cancelTask); if (debugOpen) System.out.println("***NcMLReader.wrapNcML result= \n" + ncDataset); }
/** * Read NcML from a JDOM Document, and pass in the name of the dataset. Used to augment datasetScan with NcML * * @param ncmlLocation the URL location string of the NcML document, used as a unique name for caching purposes. * @param netcdfElem the JDOM Document's root (netcdf) element * @param referencedDatasetUri the URL location string of the underlying dataset, which overrides anything in netcdfElem. * prepend with "file:" to eliminate reletive resolving against ncmlLocation * @param cancelTask allow user to cancel the task; may be null * @return the resulting NetcdfDataset * @throws IOException on read error, or bad referencedDatasetUri URI */ static public NetcdfDataset readNcML(String ncmlLocation, Element netcdfElem, String referencedDatasetUri, CancelTask cancelTask) throws IOException { NcMLReader reader = new NcMLReader(); return reader._readNcML(ncmlLocation, referencedDatasetUri, netcdfElem, cancelTask); }
NcMLReader reader = new NcMLReader(); NetcdfDataset ncd = reader.readNcML(ncmlLocation, referencedDatasetUri, netcdfElem, cancelTask); if (debugOpen) System.out.println("***NcMLReader.readNcML result= \n" + ncd); return ncd;