#!/bin/tcsh -f
#(ie run the tshell on this but don't read the .cshrc or .tcshrc)

echo version = 1.03 of mk 2004 Oct  1
# 2004 Oct  1, 1.03: attack background
# 2004 Oct  1, 1.02: all bold, pwd sensitive, functional but big background
# 2004 Sep 30, 1.01: revise data, fix crop problem
#   See:
#   http://www.cit.gu.edu.au/~anthony/graphics/imagick6/cmdline/
#   http://www.cit.gu.edu.au/~anthony/graphics/imagick6/size/
#   -cro operates AFTER the image name.
# 2004 Jul 20, 1.00: origin 

if (`pwd` == '/ftp/pub/users-www/tds/USdebt/historic') then
   set place = '-historic'
else
   set place = ''
endif
set name = USdebt$place

rm -f warnings
xyplo
if (-f warnings) then
   cat warnings
endif

#mv xyout $name.ps
cat xyout |\
sed -e "s/1 setlinewidth/2 setlinewidth/" |\
sed -e "s/Times-Roman/Times-Bold/" |\
cat > $name.ps

echo convert $name.ps $name.gif

# convert $name.ps           $name.gif
# # identify gives this gif as 587x767+0+0
# convert $name.ps -crop 500x500+0+0 c.gif
# convert $name.ps -trim     t.gif

#diff $name.gif c.gif
#diff c.gif t.gif
#
#tomdate
#exit

# convert -crop 0x0 $name.ps $name.gif

HOLD:
# that failed to crop correctly!!
   set edge = 30

# from ps2jpg
#   set edge = 10
set megabytes = 300
# density = 600 is necessary for good images, 300 is awful
   set defaultdensity = 600
set density = $defaultdensity
set dxd = "$density"x"$density"
#set crop = "-crop 0x0+$edge+$edge"
#set crop = "-crop 0x0-$edge-$edge"
set crop = "-crop 500x500+0+0"
set crop = "-crop 500x500+0+0"

# 
set crop = "-shave 500x200+0+0"

@ geo = (600 / $density) * 24
echo geometry: $geo'%'
echo crop: "$crop"

# This fails to crop ok now because version 6 is different
# convert \
# -density $dxd -geometry $geo% \
# -cache $megabytes \
# $name.ps
# $crop \
# $name.gif

# simplicity???
# convert \
#$name.ps \
#$crop \
##-density $dxd -geometry $geo% \
## -cache $megabytes \
# $name.gif

# try this ... tiny!!
# convert \
# $name.ps \
# $crop \
# -density $dxd -geometry $geo% \
# -cache $megabytes \
# $name.gif

# try this ...
convert \
$name.ps \
$crop \
-background blue \
-negate \
$name.gif
# -trim \
# -density $dxd \
# geometry does not help \
#-geometry 200% \
#-geometry 500x500+0+0 \
# -cache $megabytes \

#echo "convert -density $dxd -geometry $geo% -cache $megabytes $name.ps $crop $name.gif"
#convert -density $dxd -geometry $geo% -cache $megabytes $name.ps $crop $name.gif

# <!--
# This works:
# $name.ps $name.gif
# These fail, convert has no way to make jpgs, png:
# $name.ps $name.jpeg
# $name.ps $name.jpg
# $name.ps $name.png
# -->

ps2pdf $name.ps

chmod a+r *
chmod a+rx .

echo DONE
date
beep

