#!/bin/sh
#
#  Take the output of tsim on stdin and generate an impedance chart in
#  postscript to stdout.
#

TMP=/tmp/zplot.$$

grep FREQ | sort -nu +1.0 > $TMP.in

opts='
    set data style lines
    set size 1.8,0.5
    set terminal pbm small
    set border
    set rmargin 3
    set lmargin 10
    set nokey
    set angles degrees
    set xlabel "Frequency - Hz"
    '

echo "$opts" '
    set logscale y
    set title "Input Impedance Magnitude"
    set ylabel "|Zin|"
    plot "'$TMP.in'" using ($2):(sqrt($3*$3+$4*$4))
    ' | gnuplot 2> $TMP.err  > $TMP.1.pbm

echo "$opts" '
    set ylabel "phase(Zin)"
    set title "Input Impedance Phase"
    plot "'$TMP.in'" using ($2):(atan2($4,$3))
    ' | gnuplot 2> $TMP.err  > $TMP.2.pbm

montage -geometry '1151x240+0+0~' -tile 1x2 \
         +frame +shadow +label \
        $TMP.1.pbm $TMP.2.pbm ps:-

rm -f $TMP.*

