 /* This script takes a list of statistical data files containing tab-separated values,
  * and aggregates a specifed column so that it can be used for generating histograms.
+ *
+ * If a time, in seconds, is specified in as the third argument, only samples collected
+ * after that (simulation) time will be included. This is helpful to exclude impulse stages.
+ *
+ * The fourth argument specifies the name or number of the column with the time data. 
+ * Assumed to be the first column, if not provided.
  */
 
 import Foundation

/*** ***/


guard CommandLine.arguments.count == 3 else {
	print("usage: \(CommandLine.arguments[0]) [list of data files] [column name or number]")
	exit(EXIT_FAILURE)
}

var columnNumber: Int? = nil
var cliColName: String? = nil

	columnNumber = Int(cliColNum)-1
} else {
	cliColName = CommandLine.arguments[2]
}


// Load minimum sample time
var minTime: Double? = nil
if CommandLine.arguments.count > 3 {
	minTime = Double(CommandLine.arguments[3])
}

var timeColumnNumber: Int? = nil
var timeCliColName: String? = nil
if CommandLine.arguments.count > 4 {
	if let timeCliColNum = UInt(CommandLine.arguments[4]) {
		timeColumnNumber = Int(timeCliColNum)-1
	} else {
		timeCliColName = CommandLine.arguments[4]
	}
}

var statFiles: String
