#!/bin/sh
#
#	$Id: gmtlogo,v 1.1 2009/05/21 14:55:17 remko Exp $
#
# usage: gmtlogo dx dy scale [-Gbackground] [-Wboxpen] >> t.ps
#
#	Logo is 2" wide and 1" high and origin is lower left
#	It has not header or trailer
#

if [ $# -eq 0 ]; then
	echo "gmtlogo - Adding a GMT graphics logo overlay to an illustration" >&2
	echo " " >&2
	echo "The logo is 2\" wide and 1\" high with lower left corner at present origin" >&2
	echo "but may be translated and scaled using the settings below." >&2
	echo " " >&2
	echo "usage: gmtlogo dx dy scale [-Gfill] [-W[pen]] >> plot.ps" >&2
	echo "		dx, dy shifts logo relative to plot origin" >&2
	echo "		scale sets the logo height in inches" >&2
	echo "		Optional -G, -W draws underlying [filled] [outlined] box" >&2
	exit -1
fi

export GMT_TMPDIR=`mktemp -d ${TMPDIR:-/tmp}/gmt.XXXXXX`
gmtset FRAME_PEN 0.5p GRID_PEN_PRIMARY thinnest
echo "% Start of GMT Graphics logo"
echo "% Generated by $*"
echo "gsave"
scl1=$3
scl2=`gmtmath -Q $3 1.55 MUL =`
scl3=`gmtmath -Q $3 2.47 MUL =`
if [ $# -gt 3 ]; then
	psxy -R0/2/0/1 -Jx${scl1}i -O -K -X$1 -Y$2 -L $4 $5 << EOF
	0	0
	2	0
	2	1
	0	1
EOF
else
	psxy -R0/2/0/1 -Jx${scl1}i -O -K -X$1 -Y$2 /dev/null
fi
# This scaling is to stretch the font a bit
echo "gsave 1 2 scale"
f=`gmtmath -Q $3 7.5 MUL =`
echo "1 0.027 $f 0 17 BC Generic Mapping Tools Graphics" | pstext -R -J -O -K -N
echo "grestore"
# Undone font scaling
dx=`gmtmath -Q $3 0.225 MUL =`
dy=`gmtmath -Q $3 0.220 MUL =`
psclip /dev/null -R-180/180/-90/90 -JI0/${scl2}i -N -O -K -X${dx}i -Y${dy}i
pscoast -R -J -S150/245/255 -G20/160/45 -A2500 -Dc -O -K
psclip -R -J -B0g30/0g15 -C -O -K
dx=`gmtmath -Q $3 0.483 MUL =`
dy=`gmtmath -Q $3 0.230 MUL =`
pen=`gmtmath -Q $3 0.250 MUL =`
cat << EOF | psxy -R167/527/-90/90 -JI-13/${scl3}i -O -K -m -L -G255/70/0 -W${pen}p -X-${dx}i -Y-${dy}i
> G
-59.5 -41.8
-59.5 2.2
-105 2.2
-105 -7.7
-72.8 -7.7
-72.94 -11
-73.64 -16.5
-75.88 -22
-77 -23.43
-81.06 -27.5
-84 -29.7
-91 -32.78
-98 -34.1
-105 -34.87
-112 -34.3
-119 -33
-122.5 -31.8
-126 -30.25
-129.5 -27.5
-133 -24.64
-135.8 -22
-137.55 -19.4
-138.46 -16.5
-139.5 -11
-140 -5.5
-140.14 0
-139.86 5.5
-138.88 11
-136.36 16.5
-133 20.9
-126 27.28
-119 30.36
-112 32.12
-105 32.89
-98 32.12
-94.5 31.13
-91 30.14
-84.35 27.39
-82.12 25.9
-80.12 24.1
-78.12 21.9
-77 19.8
-76.55 17.52
-76.3 15.18
-61.6 15.18
-62 18.75
-63 21.89
-64.75 24.83
-66.6 27.5
-70 30.58
-73.36 33
-77 35.65
-84 38.72
-91 41.03
-98 41.8
-105 42.13
-112 41.8
-119 41.14
-126 39.6
-133 35.97
-137.2 33
-143.78 27.5
-147 24.2
-151.2 16.5
-153.02 11
-154.28 5.5
-154.98 0
-154.63 -5.5
-154 -11
-152.32 -16.5
-150.36 -22
-147 -26.95
-141.4 -33
-133 -38.5
-126 -41.58
-119 -43.01
-112 -44
-105 -44.33
-98 -43.78
-91 -42.35
-84 -40.37
-80.78 -38.5
-77 -35.75
-73.5 -33
-71.96 -30.8
-68.04 -41.8
> M
-37.8 -41.8
-23.8 -41.8
-23.8 27.39
5.04 -41.8
19.46 -41.8
49 27.39
49 -41.8
62.58 -41.8
62.58 40.48
42 40.48
12.46 -29.7
-17.22 40.48
-37.8 40.48
> T
124.46 -41.8
124.46 30.47
160.02 30.47
160.02 40.48
74.34 40.48
74.34 30.47
110.32 30.47
110.32 -41.8
EOF
echo "grestore"
echo "% End of GMT Graphics logo"
rm -rf $GMT_TMPDIR
unset GMT_TMPDIR
exit 0
