#!/bin/bash

# accepts two params:
# $1 - input original LOG from simulation
# $2 - output file with the data prepared for gnuplotting

if [ $# -lt 2 ]; then
	echo "missing input params, syntax: $0 LOGfile DATAfile"
	echo "  where LOGfile is the original log produced from MitoPacq"
	echo "  where DATAfile will contain plotting data for GNUplot"
	exit 1
fi

grep -E 'Generating frame|STARTING|new cell created' $1 \
	| sed 's!^sch.*no\. !!' \
	| sed 's!, only.*$!!' \
	| sed 's!^ .*ID=\(.*\), STARTING \(.*\) at timePoint=\(.*\)$!\3 \2 \1!' \
	| sed 's!^cell.h.*=0$!!' | sed 's!^cell.h.*ID=\(.*\) and timePoint=\(.*\)$!\1 \2!' \
	| ./reformatSchedulingPlot "$2" > "$2"


# after the last sed cmd, it produces quadruples (with many whitespaces):
# scheduler timePoint, cell timePoint, cell phase, cell ID
# if the phase is Cytokinesis, one more quadruple follows, actually it is
# two pairs: IDs and new (common) timePoints of both daughters
