private void makeDatasetBest(GribCollectionMutable.Dataset ds2D, boolean isComplete) {
    GribCollectionMutable.Dataset dsBest = result.makeDataset(isComplete ? GribCollectionImmutable.Type.BestComplete : GribCollectionImmutable.Type.Best);

    int npart = result.getPartitionSize();

    // for each 2D group
    for (GribCollectionMutable.GroupGC group2D : ds2D.groups) {
      GribCollectionMutable.GroupGC groupB = dsBest.addGroupCopy(group2D);  // make copy of group, add to Best dataset
      groupB.isTwoD = false;

      // for each time2D, create the best time coordinates
      HashMap<Coordinate, CoordinateTimeAbstract> map2DtoBest = new HashMap<>(); // associate 2D coord with best
      CoordinateSharerBest sharer = new CoordinateSharerBest();
      for (Coordinate coord : group2D.coords) {
        if (coord instanceof CoordinateRuntime) continue; // skip it
        if (coord instanceof CoordinateTime2D) {
          CoordinateTimeAbstract best = ((CoordinateTime2D) coord).makeBestTimeCoordinate(result.masterRuntime);
          if (!isComplete) best = best.makeBestFromComplete();
          sharer.addCoordinate(best);
          map2DtoBest.put(coord, best);
        } else {
          sharer.addCoordinate(coord);
        }
      }
      groupB.coords = sharer.finish();  // these are the unique coords for group Best

      // transfer variables to Best group, set shared Coordinates
      for (GribCollectionMutable.VariableIndex vi2d : group2D.variList) {
        // copy vi2d and add to groupB
        PartitionCollectionMutable.VariableIndexPartitioned vip = result.makeVariableIndexPartitioned(groupB, vi2d, npart);
        vip.finish();

        // set shared coordinates
        List<Coordinate> newCoords = new ArrayList<>();
        for (Integer groupIndex : vi2d.coordIndex) {
          Coordinate coord2D = group2D.coords.get(groupIndex);
          if (coord2D instanceof CoordinateRuntime) continue; // skip runtime;
          if (coord2D instanceof CoordinateTime2D) {
            newCoords.add(map2DtoBest.get(coord2D)); // add the best coordinate for that CoordinateTime2D
          } else {
            newCoords.add(coord2D);
          }
        }
        vip.coordIndex = sharer.reindex(newCoords);
      }

    } // loop over groups
  }
private void makeDatasetBest(GribCollectionMutable.Dataset ds2D, boolean isComplete) {
    GribCollectionMutable.Dataset dsBest = result.makeDataset(isComplete ? GribCollectionImmutable.Type.BestComplete : GribCollectionImmutable.Type.Best);

    int npart = result.getPartitionSize();

    
    for (GribCollectionMutable.GroupGC group2D : ds2D.groups) {
      GribCollectionMutable.GroupGC groupB = dsBest.addGroupCopy(group2D);  
      groupB.isTwoD = false;

      
      HashMap<Coordinate, CoordinateTimeAbstract> map2DtoBest = new HashMap<>(); 
      CoordinateSharerBest sharer = new CoordinateSharerBest();
      for (Coordinate coord : group2D.coords) {
        if (coord instanceof CoordinateRuntime) continue; 
        if (coord instanceof CoordinateTime2D) {
          CoordinateTimeAbstract best = ((CoordinateTime2D) coord).makeBestTimeCoordinate(result.masterRuntime);
          if (!isComplete) best = best.makeBestFromComplete();
          sharer.addCoordinate(best);
          map2DtoBest.put(coord, best);
        } else {
          sharer.addCoordinate(coord);
        }
      }
      groupB.coords = sharer.finish();  

      
      for (GribCollectionMutable.VariableIndex vi2d : group2D.variList) {
        
        PartitionCollectionMutable.VariableIndexPartitioned vip = result.makeVariableIndexPartitioned(groupB, vi2d, npart);
        vip.finish();

        
        List<Coordinate> newCoords = new ArrayList<>();
        for (Integer groupIndex : vi2d.coordIndex) {
          Coordinate coord2D = group2D.coords.get(groupIndex);
          if (coord2D instanceof CoordinateRuntime) continue; 
          if (coord2D instanceof CoordinateTime2D) {
            newCoords.add(map2DtoBest.get(coord2D)); 
          } else {
            newCoords.add(coord2D);
          }
        }
        vip.coordIndex = sharer.reindex(newCoords);
      }

    } 
  }
private void makeDatasetBest ( GribCollectionMutable . Dataset ds2D , boolean isComplete ) { GribCollectionMutable . Dataset dsBest = result . makeDataset ( isComplete ? GribCollectionImmutable . Type . BestComplete : GribCollectionImmutable . Type . Best ) ; int npart = result . getPartitionSize ( ) ; // for each 2D group for ( GribCollectionMutable . GroupGC group2D : ds2D . groups ) { GribCollectionMutable . GroupGC groupB = dsBest . addGroupCopy ( group2D ) ; // make copy of group, add to Best dataset groupB . isTwoD = false ; // for each time2D, create the best time coordinates HashMap < Coordinate , CoordinateTimeAbstract > map2DtoBest = new HashMap <> ( ) ; // associate 2D coord with best CoordinateSharerBest sharer = new CoordinateSharerBest ( ) ; for ( Coordinate coord : group2D . coords ) { if ( coord instanceof CoordinateRuntime ) continue ; // skip it if ( coord instanceof CoordinateTime2D ) { CoordinateTimeAbstract best = ( ( CoordinateTime2D ) coord ) . makeBestTimeCoordinate ( result . masterRuntime ) ; if ( ! isComplete ) best = best . makeBestFromComplete ( ) ; sharer . addCoordinate ( best ) ; map2DtoBest . put ( coord , best ) ; } else { sharer . addCoordinate ( coord ) ; } } groupB . coords = sharer . finish ( ) ; // these are the unique coords for group Best // transfer variables to Best group, set shared Coordinates for ( GribCollectionMutable . VariableIndex vi2d : group2D . variList ) { // copy vi2d and add to groupB PartitionCollectionMutable . VariableIndexPartitioned vip = result . makeVariableIndexPartitioned ( groupB , vi2d , npart ) ; vip . finish ( ) ; // set shared coordinates List < Coordinate > newCoords = new ArrayList <> ( ) ; for ( Integer groupIndex : vi2d . coordIndex ) { Coordinate coord2D = group2D . coords . get ( groupIndex ) ; if ( coord2D instanceof CoordinateRuntime ) continue ; // skip runtime; if ( coord2D instanceof CoordinateTime2D ) { newCoords . add ( map2DtoBest . get ( coord2D ) ) ; // add the best coordinate for that CoordinateTime2D } else { newCoords . add ( coord2D ) ; } } vip . coordIndex = sharer . reindex ( newCoords ) ; } } // loop over groups }
/* LOOK heres a place where one could "post process" and combine, instead of at coverage level.
this would benefit iosp, ie the netcdf API
private void makeTime2runtime(GribCollectionMutable.Dataset ds2D, boolean isComplete) throws IOException {

for (GribCollectionMutable.GroupGC group2D : ds2D.groups) {
for each time2D, add time2runtime
for (Coordinate coord : group2D.coords) {
if (coord instanceof CoordinateTime2D) {
((CoordinateTime2D) coord).makeTime2runtime(result.masterRuntime);
}
}
}
}
/ * LOOK heres a place where one could post process and combine instead of at coverage level . this would benefit iosp ie the netcdf API private void makeTime2runtime ( GribCollectionMutable . Dataset ds2D boolean isComplete ) throws IOException {