protected GribCollectionProto.TimeCoordUnion writeTimeCoordUnionProto( TimeCoordUnion tcu, int index) throws IOException { GribCollectionProto.TimeCoordUnion.Builder b = GribCollectionProto.TimeCoordUnion.newBuilder(); b.setCode(index); b.setUnit(tcu.getUnits()); if (tcu.isInterval()) { for (TimeCoord.Tinv tinv : tcu.getIntervals()) { b.addValues((float) tinv.getBounds1()); b.addBound((float) tinv.getBounds2()); } } else { for (int value : tcu.getCoords()) b.addValues((float) value); } for (TimeCoordUnion.Val val : tcu.getValues()) { b.addPartition(val.getPartition()); b.addIndex(val.getIndex()); } return b.build(); }
protected TimeCoord readTimePartition(GribCollectionProto.TimeCoordUnion pc, int timeIndex) { int[] partition = new int[pc.getPartitionCount()]; int[] index = new int[pc.getPartitionCount()]; // better be the same for (int i = 0; i < pc.getPartitionCount(); i++) { partition[i] = pc.getPartition(i); index[i] = pc.getIndex(i); } 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))); TimeCoordUnion tc = new TimeCoordUnion(pc.getCode(), pc.getUnit(), coords, partition, index); return tc.setIndex(timeIndex); } else { List<Integer> coords = new ArrayList<Integer>(pc.getValuesCount()); for (float value : pc.getValuesList()) coords.add((int) value); TimeCoordUnion tc = new TimeCoordUnion(pc.getCode(), pc.getUnit(), coords, partition, index); return tc.setIndex(timeIndex); } }