#!/bin/bash
resolution=72
pixwidth=$((resolution*50/10))
linerwidth=$((resolution*4))
liner=0
rm -f /tmp/$1.ps
cat << STOP > /tmp/$1.ps
%!
90 rotate
20 -600 translate
0 0 moveto
gsave
STOP
tifftopnm $1-b-autojoin.tif | ppmtopgm | \
  pnmscale -xysize $pixwidth  $pixwidth | \
  pnmtops -width 5 -height 5 -dpi 300 -noturn | \
  fgrep -v showpage >> /tmp/$1.ps
cat << STOP >> /tmp/$1.ps
grestore
357 0 moveto
[1 4] 0 setdash
0 setlinewidth
357 700 lineto
710 0 moveto
710 355 lineto
-10 5 moveto
710 5 lineto
-10 355 moveto
710 355 lineto
stroke
[] 0 setdash
gsave
355 0 translate
STOP
tifftopnm $1-a-autojoin.tif | ppmtopgm | \
  pnmscale -xysize $pixwidth  $pixwidth | \
  pnmtops -width 5 -height 5 -dpi 300 -noturn | \
  fgrep -v showpage >> /tmp/$1.ps
cat << STOP >> /tmp/$1.ps
grestore
statusdict begin
/manualfeed true def
/manualfeedtimeout 20 def
showpage
STOP
cat /tmp/$1.ps
rm -f /tmp/$1.ps
