#! /bin/bash
# require JR's module /usr/local/jog07
# require ghostscript command "gs" needed by epstopdf perl script
# TODO use table.txt to bind pages in the same order
# for f in "$(cat table.txt | awk '{printf("%s.jog\n",$1)}')"
EPSTOPDF=epstopdf
PDFTK=pdftk

function figpdf() {
  cd $1
  for f in *.jog
  do
    pfx="${f%.jog}"
    if ../bin/geps "$pfx"; then
      $EPSTOPDF "$pfx.eps"
      rm -f $pfx.eps
    fi
  done
  rm -f _BB
  $PDFTK *.pdf cat output ../$1.pdf
  # rm -f *.jog *.eps *.pdf
  cd -
  return 0
}

figpdf fig1
figpdf fig2
bash ./bin/plot2.sh > calib.jog
bash ./bin/geps calib.jog
$EPSTOPDF calib.eps
