#!/bin/sh

usage() {
	printf 'usage: %s [-f field] [-h] [-l label] [-t term] file..\n' "${0##*/}" 1>&2
}

field="2"
label="shear velocity [m/s]"
term="pdf"
while getopts 'f:hl:t:' arg; do
	case "${arg}" in
		f) field="${OPTARG}" ;;
		h) usage; exit 0 ;;
		l) label="${OPTARG}" ;;
		t) term="${OPTARG}" ;;
		*) usage; exit 1 ;;
	esac
done
shift $((OPTIND - 1))

for f in "$@"; do
	cut -f${field} "$f" | transpose
done | transpose | \
gnuplot -e "set term ${term};\
            set xlabel 'Output file [-]';\
            set ylabel 'i_z [-]';\
            set cblabel '${label}';\
			set autoscale xfix;\
			set autoscale yfix;\
            plot '-' matrix with image title ''"

