code: public static WritableRaster extractSubbasins( WritableRandomIter flowIter, RandomIter netIter,
              WritableRandomIter netNumberIter, int rows, int cols, IHMProgressMonitor pm ) {
  
          for( int r = 0; r < rows; r++ ) {
              for( int c = 0; c < cols; c++ ) {
                  if (!isNovalue(netIter.getSampleDouble(c, r, 0)))
                      flowIter.setSample(c, r, 0, FlowNode.OUTLET);
              }
          }
  
          WritableRaster subbasinWR = CoverageUtilities.createWritableRaster(cols, rows, Integer.class, null, null);
          WritableRandomIter subbasinIter = RandomIterFactory.createWritable(subbasinWR, null);
  
          markHillSlopeWithLinkValue(flowIter, netNumberIter, subbasinIter, cols, rows, pm);
  
          try {
              for( int r = 0; r < rows; r++ ) {
                  for( int c = 0; c < cols; c++ ) {
                      int netValue = netIter.getSample(c, r, 0);
                      int netNumberValue = netNumberIter.getSample(c, r, 0);
                      if (!isNovalue(netValue)) {
                          subbasinIter.setSample(c, r, 0, netNumberValue);
                      }
                      if (NumericsUtilities.dEq(netNumberValue, 0)) {
                          netNumberIter.setSample(c, r, 0, HMConstants.intNovalue);
                      }
                      int subbValue = subbasinIter.getSample(c, r, 0);
                      if (NumericsUtilities.dEq(subbValue, 0))
                          subbasinIter.setSample(c, r, 0, HMConstants.intNovalue);
                  }
              }
          } finally {
              subbasinIter.done();
          }
  
          return subbasinWR;
      }
docs: Extract the subbasins of a raster map.
  
  @param flowIter the map of flowdirections.
  @param netIter the network map.
  @param netNumberIter the netnumber map.
  @param rows rows of the region.
  @param cols columns of the region.
  @param pm
  @return the map of extracted subbasins.