/** * Write the NcML representation. * * @param os write to this Output Stream. * @param uri use this for the url attribute; if null use getLocation(). * @throws IOException */ @Override public void writeNcML(java.io.OutputStream os, String uri) throws IOException { NcMLWriter ncmlWriter = new NcMLWriter(); Element netcdfElem = ncmlWriter.makeNetcdfElement(this, uri); ncmlWriter.writeToStream(netcdfElem, os); }
/** * CDL representation of Netcdf header info, non strict */ public String toNcML(String url) throws IOException { NcMLWriter ncmlWriter = new NcMLWriter(); ncmlWriter.setWriteVariablesPredicate(NcMLWriter.writeNoVariablesPredicate); Element netcdfElement = ncmlWriter.makeNetcdfElement(this, url); return ncmlWriter.writeToString(netcdfElement); }
/** * Write the NcML representation. * * @param os write to this Output Stream. * @param uri use this for the url attribute; if null use getLocation(). * @throws IOException */ public void writeNcML(java.io.OutputStream os, String uri) throws IOException { new NcMLWriter().writeXML(this, os, uri); }
NcMLWriter ncmlWriter = new NcMLWriter(); Element netcdfElement; netcdfElement = ncmlWriter.makeExplicitNetcdfElement(org, null); } else { netcdfElement = ncmlWriter.makeNetcdfElement(org, null); ncmlWriter.writeToFile(netcdfElement, new File(ncmlOut)); } catch (IOException ioe) {
/** * Write the NcML representation: dont show coodinate values * * @param writer : write to this Writer, should have encoding of UTF-8 if applicable. Will be closed at end of the * method. * @param uri use this for the url attribute; if null use getLocation(). * @throws IOException if error * @see NcMLWriter#writeToWriter */ public void writeNcML(java.io.Writer writer, String uri) throws IOException { NcMLWriter ncmlWriter = new NcMLWriter(); Element netcdfElem = ncmlWriter.makeNetcdfElement(this, uri); ncmlWriter.writeToWriter(netcdfElem, writer); }
private Element writeVariable(VariableSimpleIF v) { NcMLWriter ncmlWriter = new NcMLWriter(); Element varElem = new Element("variable"); varElem.setAttribute("name", v.getShortName()); ucar.ma2.DataType dt = v.getDataType(); if (dt != null) varElem.setAttribute("type", dt.toString()); // attributes Iterator atts = v.getAttributes().iterator(); while (atts.hasNext()) { ucar.nc2.Attribute att = (ucar.nc2.Attribute) atts.next(); varElem.addContent(ncmlWriter.makeAttributeElement(att)); } return varElem; }
NcMLWriter ncmlWriter = new NcMLWriter(); ncmlWriter.setWriteVariablesPredicate(writeVarsPred); Element netcdfElement = ncmlWriter.makeNetcdfElement(ncfile, url); ncmlWriter.writeToWriter(netcdfElement, writer);
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; NcMLWriter ncmlWriter = new NcMLWriter(); Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ncmlWriter.makeAttributeElement(att)); try { Element values = ncmlWriter.makeValuesElement(axis, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); } catch (IOException e) { String message = String.format( "Couldn't read values for %s. Omitting <values> element.", axis.getFullName()); logger.warn(message, e); } return varElem; }
elem.addContent(writeEnumTypedef(etd, ncNS)); elem.addContent(writeDimension(dim, ncNS)); elem.addContent(writeAttribute(att, "attribute", ncNS)); elem.addContent(writeVariable((VariableEnhanced) var)); } catch (ClassCastException e) { log.error("var not instanceof VariableEnhanced = " + var.getFullName(), e); Element groupElem = new Element("group", ncNS); groupElem.setAttribute("name", g.getShortName()); elem.addContent(writeGroup(groupElem, g));
varElem.addContent(writeAttribute(att, "attribute", ncNS)); varElem.addContent(writeValues(var, ncNS, true)); for (Variable variable : s.getVariables()) { VariableEnhanced nestedV = (VariableEnhanced) variable; varElem.addContent(writeVariable(nestedV));
private Element writeAxis2(CoordinateAxis axis, String name) { if (axis == null) return null; Element varElem = new Element(name); varElem.setAttribute("name", axis.getFullName()); varElem.setAttribute("shape", getShapeString(axis.getShape())); // axis.getDimensionsString()); DataType dt = axis.getDataType(); varElem.setAttribute("type", dt.toString()); AxisType axisType = axis.getAxisType(); if (null != axisType) varElem.setAttribute("axisType", axisType.toString()); // attributes for (Attribute att : axis.getAttributes()) varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); Element values = ucar.nc2.ncml.NcMLWriter.writeValues(axis, null, false); values.setAttribute("npts", Long.toString(axis.getSize())); varElem.addContent(values); return varElem; }
public Element makeGroupElement(Group group) { Element elem = new Element("group", namespace); elem.setAttribute("name", group.getShortName()); // enumTypeDef for (EnumTypedef etd : group.getEnumTypedefs()) { elem.addContent(makeEnumTypedefElement(etd)); } // dimensions for (Dimension dim : group.getDimensions()) { elem.addContent(makeDimensionElement(dim)); } // regular variables for (Variable var : group.getVariables()) { boolean showValues = writeVariablesPredicate.apply(var); elem.addContent(makeVariableElement(var, showValues)); } // nested groups for (Group g : group.getGroups()) { Element groupElem = new Element("group", namespace); groupElem.setAttribute("name", g.getShortName()); elem.addContent(makeGroupElement(g)); } // attributes for (Attribute att : group.getAttributes()) { elem.addContent(makeAttributeElement(att)); } return elem; }
public String writeXML(Variable v) throws IOException { // Output the document, use standard formatter //fmt = new XMLOutputter(" ", true); //fmt.setLineSeparator("\n"); fmt = new XMLOutputter(Format.getPrettyFormat()); return fmt.outputString(makeDocument( null)); }
private Element writeVariable(VariableSimpleIF v) { Element varElem = new Element("variable"); varElem.setAttribute("name", v.getShortName()); ucar.ma2.DataType dt = v.getDataType(); if (dt != null) varElem.setAttribute("type", dt.toString()); // attributes Iterator atts = v.getAttributes().iterator(); while (atts.hasNext()) { ucar.nc2.Attribute att = (ucar.nc2.Attribute) atts.next(); varElem.addContent(ucar.nc2.ncml.NcMLWriter.writeAttribute(att, "attribute", null)); } return varElem; }
varElem.addContent(makeAttributeElement(att)); Structure s = (Structure) var; for (Variable variable : s.getVariables()) { varElem.addContent(makeVariableElement(variable, showValues)); varElem.addContent(makeValuesElement(var, true)); } catch (IOException e) { String message = String.format("Couldn't read values for %s. Omitting <values> element.%n\t%s",
Element runDateAttr = ncmlWriter.makeAttributeElement(new Attribute(_Coordinate.ModelRunDate, runDate.toString())); config.innerNcml = element.addContent(runDateAttr);
public Element makeExplicitNetcdfElement(NetcdfFile ncFile, String location) { Element netcdfElem = makeNetcdfElement(ncFile, location); netcdfElem.addContent(0, new Element("explicit", namespace)); return netcdfElem; }
writeGroup(rootElem, rootGroup);
/** * Writes an NcML element to an output file. * * @param elem an NcML element. * @param outFile the file to write the NcML document to. * @throws IOException if there's any problem writing. */ public void writeToFile(Element elem, File outFile) throws IOException { try (OutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile, false))) { writeToStream(elem, outStream); } }
/** * Write the NcML representation. * * @param os write to this Output Stream. * @param uri use this for the url attribute; if null use getLocation(). * @throws IOException */ public void writeNcML(java.io.OutputStream os, String uri) throws IOException { new NcMLWriter().writeXML(this, os, uri); }