code: private int pool( int row, int col, int prevNPool ) {
          int in;
          int jn;
          int npool = prevNPool;
          if (apool[col][row] <= 0) { /* not already part of a pool */
              if (dir[col][row] != -1) {/* check only dir since dir was initialized */
                  /* not on boundary */
                  apool[col][row] = pooln;/* apool assigned pool number */
                  npool = npool + 1;// the number of pixel in the pool
                  if (npool >= pstack) {
                      if (pstack < nCols * nRows) {
                          pstack = (int) (pstack + nCols * nRows * .1);
                          if (pstack > nCols * nRows) {
                              /* Pool stack too large */
                          }
  
                          ipool = realloc(ipool, pstack);
                          jpool = realloc(jpool, pstack);
                      }
  
                  }
  
                  ipool[npool] = row;
                  jpool[npool] = col;
  
                  for( int k = 1; k <= 8; k++ ) {
                      in = row + DIR_WITHFLOW_EXITING_INVERTED[k][1];
                      jn = col + DIR_WITHFLOW_EXITING_INVERTED[k][0];
                      /* test if neighbor drains towards cell excluding boundaries */
                      if (((dir[jn][in] > 0) && ((dir[jn][in] - k == 4) || (dir[jn][in] - k == -4))) || ((dir[jn][in] == 0)
                              && (pitIter.getSampleDouble(jn, in, 0) >= pitIter.getSampleDouble(col, row, 0)))) {
                          /* so that adjacent flats get included */
                          npool = pool(in, jn, npool);
                      }
                  }
  
              }
          }
          return npool;
      }
docs: function to compute pool recursively and at the same time determine the minimum elevation of
  the edge.