+#' @title Cluster power curves with PAM in parallel
+#'
+#' @description Groups electricity power curves (or any series of similar nature) by applying PAM
+#' algorithm in parallel to chunks of size \code{nb_series_per_chunk}
+#'
+#' @param data Access to the data, which can be of one of the three following types:
+#' \itemize{
+#' \item data.frame: each line contains its ID in the first cell, and all values after
+#' \item connection: any R connection object (e.g. a file) providing lines as described above
+#' \item function: a custom way to retrieve the curves; it has two arguments: the start index
+#' (start) and number of curves (n); see example in package vignette.
+#' }
+#' @param K Number of clusters
+#' @param nb_series_per_chunk (Maximum) number of series in each group
+#' @param min_series_per_chunk Minimum number of series in each group
+#' @param writeTmp Function to write temporary wavelets coefficients (+ identifiers);
+#' see defaults in defaults.R
+#' @param readTmp Function to read temporary wavelets coefficients (see defaults.R)
+#' @param wf Wavelet transform filter; see ?wt.filter. Default: haar
+#' @param WER "end" to apply stage 2 after stage 1 has iterated and finished, or "mix"
+#' to apply it after every stage 1
+#' @param ncores number of parallel processes; if NULL, use parallel::detectCores()
+#'
+#' @return A data.frame of the final medoids curves (identifiers + values)
+epclust = function(data, K, nb_series_per_chunk, min_series_per_chunk=10*K,
+ writeTmp=defaultWriteTmp, readTmp=defaultReadTmp, wf="haar", WER="end", ncores=NULL)
+{
+ #TODO: setRefClass(...) to avoid copy data:
+ #http://stackoverflow.com/questions/2603184/r-pass-by-reference