#! /bin/bash
# Last edited on 2009-12-13 09:26:47 by stolfi

# Plots reformatted new editor count raw data ("rer" format).
# Assumes that the first input file has the format 
# "{TIME} {YEAR} {MONTH} {DAY} {TOTEDS} {NEWEDS} {ACTEDS5} {ACTEDS100}"
# Assumes that the second input file has the format
# "{TIME} {YEAR} {MONTH} {DAY} {SZ} {SU}  {DZ} {DU}"

pha="$1"; shift  # Which region of file to plot.
edtfile="$1"; shift  # File with editor data.
artfile="$1"; shift  # File with article data.

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

epsfile="/tmp/$$.eps"

if [[ ${pha} -eq 0 ]]; then
  xrange="set xrange [2000.8:2010.8]"
  yrange="set yrange [-10:+17010]"
  narmag="/7"
elif [[ ${pha} -eq 1 ]]; then
  xrange="set xrange [2000.8:2004.8]"
  yrange="set yrange [-10:+4010]"
  narmag="/24"
elif [[ ${pha} -eq 2 ]]; then
  xrange="set xrange [2005.3:2010.7]"
  yrange="set yrange [-10:+17010]"
  narmag="/4.5"
else
  echo "invalid pha = [${pha}]" 1>&2
  exit 1
fi

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

${xrange}
set grid xtics
set mxtics 12
set xtics 1.0 format "        %4.0f"
set xzeroaxis

${yrange}
set ytics format "%7.0f"
set grid ytics

year(i)=(column(i)/365.25 + 2001)
plot \
  "${edtfile}" using (year(1)):(column(6)) title "E0'(t) (ed/mo)" with linespoints pt 7 ps 0.50 lc rgb '#ee00ee', \
  "${artfile}" using (year(1)):(column(7)${narmag}) title "N'(t)${narmag} (art/mo)" with linespoints pt 6 ps 0.75 lc rgb '#ee4422'
quit
EOF

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