#! /bin/bash
# Last edited on 2009-12-05 16:26:53 by stolfi

# Plots reformatted raw data around a counter's glitch.
# Assumes that input is "{TIME} {SZ}"
# Also plots two shifted exponentials.

A1="$1"; shift
K1="$1"; shift
R1="$1"; shift
A2="$1"; shift
K2="$1"; shift
R2="$1"; shift
datafile="$1"; shift

echo "${0##*/} datafile = ${datafile}" 1>&2 

epsfile="/tmp/$$.eps"

gnuplot <<EOF
set term postscript eps color solid "TimesRoman" 24
set size 0.75,1.0
set output "${epsfile}"
set key left samplen 1.0

set xzeroaxis
set xtics 10
set mxtics 10
set grid xtics

set yrange [0:]
set ytics format "%6.0f"

sper=28
year(i)=(column(i)/365.25 + 2001)
plot \
  "${datafile}" using 1:((${A1}) + (${K1})*exp((${R1})*column(1)/sper)) notitle with lines lt rgb '#ee4411', \
  "${datafile}" using 1:((${A2}) + (${K2})*exp((${R2})*column(1)/sper)) notitle with lines lt rgb '#ee4411', \
  "${datafile}" using 1:(column(5)) notitle with points pt 7 ps 1.0 lt rgb '#1144ee'
quit
EOF

cat ${epsfile}
gv ${epsfile}
rm -f ${epsfile}
