#!/bin/sh
#
# shrinkplt - reduce resolution and size of large .plt file from analysis
#
# Usage:  shrinkplt [-t] [orig.plt] ... > smaller.plt
#
# where:  -t	specifies reducing resolution by a factor of 10, which reduces
#		plot size to about 1/4 to 1/5 of original
#		(by default it reduces resolution by a factor of 5, for a size
#		reduction to about 1/3 of original)
#
#	  orig.plt is the original Plot/File output of a high-resolution plot
#		from analysis, such as Raw W.F. ampl. vs cycle
#		(one or more plot files can be specified, and if no file is
#		specified, the script reads from its std input)
#
#	  smaller.plt is the reduced output file
#
# Copyright (c) 2018, Gilles Detillieux, Spinal Cord Research Centre,
# University of Manitoba.  All Rights Reserved.
#

topt=5
while :
do
	case "$1" in
	-\?|-help|--help)	sed -n '3,/^# Univ/s/^#/ /p' "$0"; exit ;;
	-t)	shift; topt=0 ;;
	-*)	set --; break ;;
	*)	break ;;
	esac
done

sed "/PD.*PD.*PD/{
		s/[1-4],/0,/g;s/[1-4];/0;/g
		s/[5-9],/$topt,/g;s/[5-9];/$topt;/g
	  }" ${@+"$@"} | replot -s
