#!/usr/bin/env Rscript
# Copyright (c) 2011-2012, Universite de Versailles St-Quentin-en-Yvelines
#
# This file is part of ASK.  ASK is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


# This script compares time series statistics extracted by different ASK runs
#


args <- commandArgs(trailingOnly = T)
if (length(args) < 2) {
   stop("Usage: compare-time-series output.png timeseries1 [timeseries2...])
}

require(lattice)

data = data.frame()

for (ts in args[-1]) {
    dt = read.table(ts, header=T)
    dt$population = ts
    data = rbind(data, dt)
}


colnames = names(dt)
colnames = colnames[colnames != "samples" & colnames != "population"]


png(args[1], width=1000, height=1000)
i = 1
for (cn in colnames) {
  form = formula(paste(cn, "~ samples"))
  pp = xyplot(form, data=data, groups=population,
    auto.key=list(space="right"), type = c("l","o"))
  print(pp, split=c(1,i,1,length(colnames)), more=TRUE)
  i = i + 1
}
