#!/bin/sh

# stop annoying error messages from ImageMagick
cp /usr/opt/doc/ImageMagick/magic.mgk .

# remove old print file if it exists
if test -s final.ps
then
rm final.ps
fi

#Capture and prepare the Zoom window
#*****Explanation by line:*****
#1. Grab a screen capture of the Zoom window
#2. Crop the graph out of the screen capture
#3. Change the 32 bit white color to almost pure black
#4. Change the 16 bit white color to almost pure black
#5. Change pure black to pure white
#6. Change the 32 bit grey grid lines to lighter gray
#7. Change the 16 bit grey grid lines to lighter grey
#8. Add the current date stamp to the image
#9. Add the current username to the image
#10 Input file name and output file name
/usr/local/bin/import -window Zoom zoom.tiff
/usr/local/bin/convert -gravity northwest -chop 135x40+0+0 \
-fill "rgb(4,0,0)" -opaque "rgb(255,255,255)" \
-fill "rgb(4,0,0)" -opaque "rgb(255,251,255)" \
-fill "rgb(255,255,255)" -opaque "rgb(0,0,0)" \
-fill "rgb(230,230,230)" -opaque "rgb(89,89,89)" \
-fill "rgb(230,230,230)" -opaque "rgb(90,89,90)" \
-fill black -font CourierNew -draw "text 20,0 '`/usr/xpg4/bin/date`'" \
-draw "text 250,0 '`/usr/ucb/whoami`'" \
zoom.tiff zoom2.tiff

#Capture and prepare the Control window
#*****Explanation by line:*****
#1. Grab a screen capture of the Control window
#2. Crop the station IDs out of the screen capture (This is set for 8 digit station numbers. For 15 digit use 180x350+3+30)
#3. Change the 32 bit white color to almost pure black
#4. Change the 16 bit white color to almost pure black
#5. Change pure black to pure white
#6. Change the 32 bit primary grey to white
#7. Change the 32 bit secondary grey to white
#8. Change the 16 bit primary grey to white
#9. Change the 16 bit secondary grey to white
#10 Input file name and output file name
/usr/local/bin/import -window Control control.tiff
/usr/local/bin/convert -gravity northeast -crop 127x350+3+30 \
-fill "rgb(4,0,0)" -opaque "rgb(255,255,255)" \
-fill "rgb(4,0,0)" -opaque "rgb(255,251,255)" \
-fill "rgb(255,255,255)" -opaque "rgb(0,0,0)" \
-fill white -opaque "rgb(192,192,192)" \
-fill white -opaque "rgb(174,178,195)" \
-fill white -opaque "rgb(189,186,189)" \
-fill white -opaque "rgb(173,178,198)" \
control.tiff control2.tiff

#Combine the prepared Zoom and Control windows into one image
/usr/local/bin/convert -fill white +append zoom2.tiff control2.tiff final.tiff

#Make final adjustments to the image
#*****Explanation by line:*****
#1. If the image is larger than the dimensions given then resize the image to those dimensions 
#2. Rotate the image 90deg
#3. Add a blank border to the image to keep the printed image inside printer margins
#4. Input file name and output file name
/usr/local/bin/convert -geometry "720x516>"  \
-rotate "-90>" \
-bordercolor white -border 40X40 \
final.tiff final.ps

# print graph
if [ "$*" = "" ]; then
#
# SET DEFAULT HYDRA PRINTER ON NEXT LINE (ex: hpc)
#
set hpc
fi

lp -d$* final.ps

# Clean up temporary files

rm magic.mgk zoom.tiff zoom2.tiff control.tiff control2.tiff final.tiff