+#' CLAWS: CLustering with wAvelets and Wer distanceS
+#'
+#' Cluster electricity power curves (or any series of similar nature) by applying a
+#' two stage procedure in parallel (see details).
+#' Input series must be sampled on the same time grid, no missing values.
+#'
+#' Summary of the function execution flow:
+#' \enumerate{
+#' \item Compute and serialize all contributions, obtained through discrete wavelet
+#' decomposition (see Antoniadis & al. [2013])
+#' \item Divide series into \code{ntasks} groups to process in parallel. In each task:
+#' \enumerate{
+#' \item iterate the first clustering algorithm on its aggregated outputs,
+#' on inputs of size \code{nb_items_clust1}
+#' \item optionally, if WER=="mix":
+#' a) compute the K1 synchrones curves,
+#' b) compute WER distances (K1xK1 matrix) between synchrones and
+#' c) apply the second clustering algorithm
+#' }
+#' \item Launch a final task on the aggregated outputs of all previous tasks:
+#' in the case WER=="end" this task takes indices in input, otherwise
+#' (medoid) curves
+#' }
+#' \cr
+#' The main argument -- \code{getSeries} -- has a quite misleading name, since it can be
+#' either a [big.]matrix, a CSV file, a connection or a user function to retrieve
+#' series; the name was chosen because all types of arguments are converted to a function.
+#' When \code{getSeries} is given as a function, it must take a single argument,
+#' 'indices', integer vector equal to the indices of the curves to retrieve;
+#' see SQLite example. The nature and role of other arguments should be clear.
+#' WARNING: the return value must be a matrix (in columns), or NULL if no matches.
+#' \cr
+#' Note: Since we don't make assumptions on initial data, there is a possibility that
+#' even when serialized, contributions or synchrones do not fit in RAM. For example,
+#' 30e6 series of length 100,000 would lead to a +4Go contribution matrix. Therefore,
+#' it's safer to place these in (binary) files; that's what we do.
+#'
+#' @param getSeries Access to the (time-)series, which can be of one of the three
+#' following types:
+#' \itemize{
+#' \item [big.]matrix: each column contains the (time-ordered) values of one time-serie
+#' \item connection: any R connection object providing lines as described above
+#' \item character: name of a CSV file containing series in rows (no header)
+#' \item function: a custom way to retrieve the curves; it has only one argument:
+#' the indices of the series to be retrieved. See SQLite example
+#' }
+#' @param K1 Number of clusters to be found after stage 1 (K1 << N [number of series])
+#' @param K2 Number of clusters to be found after stage 2 (K2 << K1)
+#' @param nb_series_per_chunk (Maximum) number of series to retrieve in one batch
+#' @param algoClust1 Clustering algorithm for stage 1. A function which takes (data, K)
+#' as argument where data is a matrix in columns and K the desired number of clusters,
+#' and outputs K medoids ranks. Default: PAM. In our method, this function is called
+#' on iterated medoids during stage 1
+#' @param algoClust2 Clustering algorithm for stage 2. A function which takes (dists, K)
+#' as argument where dists is a matrix of distances and K the desired number of clusters,
+#' and outputs K medoids ranks. Default: PAM. In our method, this function is called
+#' on a matrix of K1 x K1 (WER) distances computed between synchrones
+#' @param nb_items_clust1 (~Maximum) number of items in input of the clustering algorithm
+#' for stage 1. At worst, a clustering algorithm might be called with ~2*nb_items_clust1
+#' items; but this could only happen at the last few iterations.
+#' @param wav_filt Wavelet transform filter; see ?wavelets::wt.filter
+#' @param contrib_type Type of contribution: "relative", "logit" or "absolute" (any prefix)
+#' @param WER "end" to apply stage 2 after stage 1 has fully iterated, or "mix" to apply
+#' stage 2 at the end of each task
+#' @param nvoice Number of voices within each octave for CWT computations
+#' @param random TRUE (default) for random chunks repartition
+#' @param ntasks Number of tasks (parallel iterations to obtain K1 [if WER=="end"]
+#' or K2 [if WER=="mix"] medoids); default: 1.
+#' Note: ntasks << N (number of series), so that N is "roughly divisible" by ntasks
+#' @param ncores_tasks Number of parallel tasks (1 to disable: sequential tasks)
+#' @param ncores_clust Number of parallel clusterings in one task (4 should be a minimum)
+#' @param sep Separator in CSV input file (if any provided)
+#' @param nbytes Number of bytes to serialize a floating-point number; 4 or 8
+#' @param endian Endianness for (de)serialization ("little" or "big")
+#' @param verbose Level of verbosity (0/FALSE for nothing or 1/TRUE for all; devel stage)
+#' @param parll TRUE to fully parallelize; otherwise run sequentially (debug, comparison)
+#'
+#' @return A matrix of the final K2 medoids curves, in columns