private TimeCoord readTimeCoord(GribCollectionProto.Coord pc) throws IOException {
   if (pc.getBoundCount() > 0) { // its an interval
     List<TimeCoord.Tinv> coords = new ArrayList<TimeCoord.Tinv>(pc.getValuesCount());
     for (int i = 0; i < pc.getValuesCount(); i++)
       coords.add(new TimeCoord.Tinv((int) pc.getValues(i), (int) pc.getBound(i)));
     TimeCoord tc = new TimeCoord(pc.getCode(), pc.getUnit(), coords);
     return tc.setIndex(pc.getIndex());
   } else {
     List<Integer> coords = new ArrayList<Integer>(pc.getValuesCount());
     for (float value : pc.getValuesList()) coords.add((int) value);
     TimeCoord tc = new TimeCoord(pc.getCode(), pc.getUnit(), coords);
     return tc.setIndex(pc.getIndex());
   }
 }
 protected GribCollectionProto.Coord writeCoordProto(TimeCoord tc, int index) throws IOException {
   GribCollectionProto.Coord.Builder b = GribCollectionProto.Coord.newBuilder();
   b.setCode(index);
   b.setUnit(tc.getUnits());
   float scale =
       (float) tc.getTimeUnitScale(); // deal with, eg, "6 hours" by multiplying values by 6
   if (tc.isInterval()) {
     for (TimeCoord.Tinv tinv : tc.getIntervals()) {
       b.addValues(tinv.getBounds1() * scale);
       b.addBound(tinv.getBounds2() * scale);
     }
   } else {
     for (int value : tc.getCoords()) b.addValues(value * scale);
   }
   return b.build();
 }
  GribCollection.GroupHcs readGroup(GribCollectionProto.Group p, GribCollection.GroupHcs group)
      throws IOException {

    byte[] rawGds = p.getGds().toByteArray();
    Grib2SectionGridDefinition gdss = new Grib2SectionGridDefinition(rawGds);
    Grib2Gds gds = gdss.getGDS();
    int gdsHash = (p.getGdsHash() != 0) ? p.getGdsHash() : gds.hashCode();
    group.setHorizCoordSystem(gds.makeHorizCoordSys(), rawGds, gdsHash);

    group.varIndex = new ArrayList<GribCollection.VariableIndex>();
    for (int i = 0; i < p.getVariablesCount(); i++)
      group.varIndex.add(readVariable(p.getVariables(i), group));
    Collections.sort(group.varIndex);

    group.timeCoords = new ArrayList<TimeCoord>(p.getTimeCoordsCount());
    for (int i = 0; i < p.getTimeCoordsCount(); i++)
      group.timeCoords.add(readTimeCoord(p.getTimeCoords(i)));

    group.vertCoords = new ArrayList<VertCoord>(p.getVertCoordsCount());
    for (int i = 0; i < p.getVertCoordsCount(); i++)
      group.vertCoords.add(readVertCoord(p.getVertCoords(i)));

    group.ensCoords = new ArrayList<EnsCoord>(p.getEnsCoordsCount());
    for (int i = 0; i < p.getEnsCoordsCount(); i++)
      group.ensCoords.add(readEnsCoord(p.getEnsCoords(i)));

    group.filenose = new int[p.getFilenoCount()];
    for (int i = 0; i < p.getFilenoCount(); i++) group.filenose[i] = p.getFileno(i);

    readTimePartitions(group, p);

    // finish
    for (GribCollection.VariableIndex vi : group.varIndex) {
      TimeCoord tc = group.timeCoords.get(vi.timeIdx);
      vi.ntimes = tc.getSize();
      VertCoord vc = (vi.vertIdx < 0) ? null : group.vertCoords.get(vi.vertIdx);
      vi.nverts = (vc == null) ? 0 : vc.getSize();
      EnsCoord ec = (vi.ensIdx < 0) ? null : group.ensCoords.get(vi.ensIdx);
      vi.nens = (ec == null) ? 0 : ec.getSize();
    }

    // group.assignVertNames();

    return group;
  }