cdm/src/main/java/ucar/nc2/ft/fmrc/GridDatasetInv.java
private static GridDatasetInv readXML(byte[] xmlString) throws IOException {
    InputStream is = new BufferedInputStream(new ByteArrayInputStream(xmlString));
    org.jdom2.Document doc;
    try {
      SAXBuilder builder = new SAXBuilder();
      doc = builder.build(is);
    } catch (JDOMException e) {
      throw new IOException(e.getMessage() + " reading from XML ");
    }

    Element rootElem = doc.getRootElement();
    GridDatasetInv fmr = new GridDatasetInv();
    fmr.runTimeString = rootElem.getAttributeValue("runTime");
    fmr.location = rootElem.getAttributeValue("location");
    if (fmr.location == null)
      fmr.location = rootElem.getAttributeValue("name"); // old way
    String lastModifiedS = rootElem.getAttributeValue("lastModified");
    if (lastModifiedS != null)
      fmr.lastModified = CalendarDateFormatter.isoStringToDate(lastModifiedS);
    String version = rootElem.getAttributeValue("version");
    fmr.version = (version == null) ? 0 : Integer.parseInt(version);
    if (fmr.version < REQ_VERSION) return fmr;

    fmr.runDate = DateUnit.parseCalendarDate(fmr.runTimeString);

    java.util.List<Element> vList = rootElem.getChildren("vertCoord");
    for (Element vertElem : vList) {
      VertCoord vc = new VertCoord();
      fmr.vaxes.add(vc);
      vc.setId( Integer.parseInt(vertElem.getAttributeValue("id")));
      vc.setName(vertElem.getAttributeValue("name"));
      vc.setUnits(vertElem.getAttributeValue(CDM.UNITS));

      // parse the values
      String values = vertElem.getTextNormalize();
      StringTokenizer stoke = new StringTokenizer(values);
      int n = stoke.countTokens();
      double[] values1 = new double[n];
      double[] values2 = null;
      int count = 0;
      while (stoke.hasMoreTokens()) {
        String toke = stoke.nextToken();
        int pos = toke.indexOf(',');
        if (pos < 0)
          values1[count] = Double.parseDouble(toke);
        else {
          if (values2 == null)
            values2 = new double[n];
          String val1 = toke.substring(0, pos);
          String val2 = toke.substring(pos + 1);
          values1[count] = Double.parseDouble(val1);
          values2[count] = Double.parseDouble(val2);
        }
        count++;
      }
      vc.setValues1(values1);
      vc.setValues2(values2);
    }

    java.util.List<Element> tList = rootElem.getChildren("timeCoord");
    for (Element timeElem : tList) {
      TimeCoord tc = new TimeCoord(fmr.runDate);
      fmr.times.add(tc);
      tc.setId(Integer.parseInt(timeElem.getAttributeValue("id")));
      String s = timeElem.getAttributeValue("isInterval");
      boolean isInterval = (s != null) && (s.equals("true"));

      if (isInterval) {
        String boundsAll = timeElem.getTextNormalize();
        String[] bounds = boundsAll.split(",");
        int n = bounds.length;
        double[] bound1 = new double[n];
        double[] bound2 = new double[n];
        int count = 0;
        for (String b : bounds) {
          String[] value = b.split(" ");
          bound1[count] = Double.parseDouble(value[0]);
          bound2[count] = Double.parseDouble(value[1]);
          count++;
        }
        tc.setBounds(bound1, bound2);

      } else {
        String values = timeElem.getTextNormalize();
        String[] value = values.split(",");
        int n = value.length;
        double[] offsets = new double[n];
        int count = 0;
        for (String v : value)
          offsets[count++] = Double.parseDouble(v);
        tc.setOffsetTimes(offsets);
      }

      //get the variable names
      List<Element> varList = timeElem.getChildren("grid");
      for (Element vElem : varList) {
        Grid grid = fmr.makeGrid(vElem.getAttributeValue("name"));
        if (vElem.getAttributeValue("ens_id") != null)
          grid.ec = fmr.getEnsCoordinate( Integer.parseInt(vElem.getAttributeValue("ens_id")));
        if (vElem.getAttributeValue("vert_id") != null)
          grid.vc = fmr.getVertCoordinate( Integer.parseInt(vElem.getAttributeValue("vert_id")));
        tc.addGridInventory(grid);
        grid.tc = tc;
      }
    }

    return fmr;
  }
private static GridDatasetInv readXML(byte[] xmlString) throws IOException {
    InputStream is = new BufferedInputStream(new ByteArrayInputStream(xmlString));
    org.jdom2.Document doc;
    try {
      SAXBuilder builder = new SAXBuilder();
      doc = builder.build(is);
    } catch (JDOMException e) {
      throw new IOException(e.getMessage() + " reading from XML ");
    }

    Element rootElem = doc.getRootElement();
    GridDatasetInv fmr = new GridDatasetInv();
    fmr.runTimeString = rootElem.getAttributeValue("runTime");
    fmr.location = rootElem.getAttributeValue("location");
    if (fmr.location == null)
      fmr.location = rootElem.getAttributeValue("name"); // old way
    String lastModifiedS = rootElem.getAttributeValue("lastModified");
    if (lastModifiedS != null)
      fmr.lastModified = CalendarDateFormatter.isoStringToDate(lastModifiedS);
    String version = rootElem.getAttributeValue("version");
    fmr.version = (version == null) ? 0 : Integer.parseInt(version);
    if (fmr.version < REQ_VERSION) return fmr;

    fmr.runDate = DateUnit.parseCalendarDate(fmr.runTimeString);

    java.util.List<Element> vList = rootElem.getChildren("vertCoord");
    for (Element vertElem : vList) {
      VertCoord vc = new VertCoord();
      fmr.vaxes.add(vc);
      vc.setId( Integer.parseInt(vertElem.getAttributeValue("id")));
      vc.setName(vertElem.getAttributeValue("name"));
      vc.setUnits(vertElem.getAttributeValue(CDM.UNITS));

      // parse the values
      String values = vertElem.getTextNormalize();
      StringTokenizer stoke = new StringTokenizer(values);
      int n = stoke.countTokens();
      double[] values1 = new double[n];
      double[] values2 = null;
      int count = 0;
      while (stoke.hasMoreTokens()) {
        String toke = stoke.nextToken();
        int pos = toke.indexOf(',');
        if (pos < 0)
          values1[count] = Double.parseDouble(toke);
        else {
          if (values2 == null)
            values2 = new double[n];
          String val1 = toke.substring(0, pos);
          String val2 = toke.substring(pos + 1);
          values1[count] = Double.parseDouble(val1);
          values2[count] = Double.parseDouble(val2);
        }
        count++;
      }
      vc.setValues1(values1);
      vc.setValues2(values2);
    }

    java.util.List<Element> tList = rootElem.getChildren("timeCoord");
    for (Element timeElem : tList) {
      TimeCoord tc = new TimeCoord(fmr.runDate);
      fmr.times.add(tc);
      tc.setId(Integer.parseInt(timeElem.getAttributeValue("id")));
      String s = timeElem.getAttributeValue("isInterval");
      boolean isInterval = (s != null) && (s.equals("true"));

      if (isInterval) {
        String boundsAll = timeElem.getTextNormalize();
        String[] bounds = boundsAll.split(",");
        int n = bounds.length;
        double[] bound1 = new double[n];
        double[] bound2 = new double[n];
        int count = 0;
        for (String b : bounds) {
          String[] value = b.split(" ");
          bound1[count] = Double.parseDouble(value[0]);
          bound2[count] = Double.parseDouble(value[1]);
          count++;
        }
        tc.setBounds(bound1, bound2);

      } else {
        String values = timeElem.getTextNormalize();
        String[] value = values.split(",");
        int n = value.length;
        double[] offsets = new double[n];
        int count = 0;
        for (String v : value)
          offsets[count++] = Double.parseDouble(v);
        tc.setOffsetTimes(offsets);
      }

      //get the variable names
      List<Element> varList = timeElem.getChildren("grid");
      for (Element vElem : varList) {
        Grid grid = fmr.makeGrid(vElem.getAttributeValue("name"));
        if (vElem.getAttributeValue("ens_id") != null)
          grid.ec = fmr.getEnsCoordinate( Integer.parseInt(vElem.getAttributeValue("ens_id")));
        if (vElem.getAttributeValue("vert_id") != null)
          grid.vc = fmr.getVertCoordinate( Integer.parseInt(vElem.getAttributeValue("vert_id")));
        tc.addGridInventory(grid);
        grid.tc = tc;
      }
    }

    return fmr;
  }
private static GridDatasetInv readXML ( byte [ ] xmlString ) throws IOException { InputStream is = new BufferedInputStream ( new ByteArrayInputStream ( xmlString ) ) ; org . jdom2 . Document doc ; try { SAXBuilder builder = new SAXBuilder ( ) ; doc = builder . build ( is ) ; } catch ( JDOMException e ) { throw new IOException ( e . getMessage ( ) + " reading from XML " ) ; } Element rootElem = doc . getRootElement ( ) ; GridDatasetInv fmr = new GridDatasetInv ( ) ; fmr . runTimeString = rootElem . getAttributeValue ( "runTime" ) ; fmr . location = rootElem . getAttributeValue ( "location" ) ; if ( fmr . location == null ) fmr . location = rootElem . getAttributeValue ( "name" ) ; // old way
 String lastModifiedS = rootElem . getAttributeValue ( "lastModified" ) ; if ( lastModifiedS != null ) fmr . lastModified = CalendarDateFormatter . isoStringToDate ( lastModifiedS ) ; String version = rootElem . getAttributeValue ( "version" ) ; fmr . version = ( version == null ) ? 0 : Integer . parseInt ( version ) ; if ( fmr . version < REQ_VERSION ) return fmr ; fmr . runDate = DateUnit . parseCalendarDate ( fmr . runTimeString ) ; java . util . List < Element > vList = rootElem . getChildren ( "vertCoord" ) ; for ( Element vertElem : vList ) { VertCoord vc = new VertCoord ( ) ; fmr . vaxes . add ( vc ) ; vc . setId ( Integer . parseInt ( vertElem . getAttributeValue ( "id" ) ) ) ; vc . setName ( vertElem . getAttributeValue ( "name" ) ) ; vc . setUnits ( vertElem . getAttributeValue ( CDM . UNITS ) ) ; // parse the values
 String values = vertElem . getTextNormalize ( ) ; StringTokenizer stoke = new StringTokenizer ( values ) ; int n = stoke . countTokens ( ) ; double [ ] values1 = new double [ n ] ; double [ ] values2 = null ; int count = 0 ; while ( stoke . hasMoreTokens ( ) ) { String toke = stoke . nextToken ( ) ; int pos = toke . indexOf ( ' ' ) ; if ( pos < 0 ) values1 [ count ] = Double . parseDouble ( toke ) ; else { if ( values2 == null ) values2 = new double [ n ] ; String val1 = toke . substring ( 0 , pos ) ; String val2 = toke . substring ( pos + 1 ) ; values1 [ count ] = Double . parseDouble ( val1 ) ; values2 [ count ] = Double . parseDouble ( val2 ) ; } count ++ ; } vc . setValues1 ( values1 ) ; vc . setValues2 ( values2 ) ; } java . util . List < Element > tList = rootElem . getChildren ( "timeCoord" ) ; for ( Element timeElem : tList ) { TimeCoord tc = new TimeCoord ( fmr . runDate ) ; fmr . times . add ( tc ) ; tc . setId ( Integer . parseInt ( timeElem . getAttributeValue ( "id" ) ) ) ; String s = timeElem . getAttributeValue ( "isInterval" ) ; boolean isInterval = ( s != null ) && ( s . equals ( "true" ) ) ; if ( isInterval ) { String boundsAll = timeElem . getTextNormalize ( ) ; String [ ] bounds = boundsAll . split ( "," ) ; int n = bounds . length ; double [ ] bound1 = new double [ n ] ; double [ ] bound2 = new double [ n ] ; int count = 0 ; for ( String b : bounds ) { String [ ] value = b . split ( " " ) ; bound1 [ count ] = Double . parseDouble ( value [ 0 ] ) ; bound2 [ count ] = Double . parseDouble ( value [ 1 ] ) ; count ++ ; } tc . setBounds ( bound1 , bound2 ) ; } else { String values = timeElem . getTextNormalize ( ) ; String [ ] value = values . split ( "," ) ; int n = value . length ; double [ ] offsets = new double [ n ] ; int count = 0 ; for ( String v : value ) offsets [ count ++ ] = Double . parseDouble ( v ) ; tc . setOffsetTimes ( offsets ) ; } //get the variable names
 List < Element > varList = timeElem . getChildren ( "grid" ) ; for ( Element vElem : varList ) { Grid grid = fmr . makeGrid ( vElem . getAttributeValue ( "name" ) ) ; if ( vElem . getAttributeValue ( "ens_id" ) != null ) grid . ec = fmr . getEnsCoordinate ( Integer . parseInt ( vElem . getAttributeValue ( "ens_id" ) ) ) ; if ( vElem . getAttributeValue ( "vert_id" ) != null ) grid . vc = fmr . getVertCoordinate ( Integer . parseInt ( vElem . getAttributeValue ( "vert_id" ) ) ) ; tc . addGridInventory ( grid ) ; grid . tc = tc ; } } return fmr ; }
Construct a GridDatasetInv from its XML representation

@param xmlString the xml string
@return ForecastModelRun
@throws IOException on io error
Construct a GridDatasetInv from its XML representation