#!/bin/bash # # UK map - showing UK city locations cleanup() { [ -n "${pstmpfile}" ] && [ -f "${pstmpfile}" ] && rm "${pstmpfile}" } die() { echo "$0: $@" cleanup exit 1 } # Convert GMT-generated positions into HTML map ps2hmap() { coords=$(echo "${plotps}" | egrep '^N.*C3$' | cut -d" " -f5-7) paste <(echo "${coords}") <(cut -d" " -f3 "${cfile}") | \ while read x y r city do #echo "${x} ${y} ${r}" psx=$((${x}+36)) psy=$((${a5height}-${y}-72)) cat < EOM done } trap "die caught signal" QUIT INT range='-10.5/3/50/59.5' projection='M13c' outfile='ukmap.png' mapname='ukmap' htmlfile='clickable.html' red='255/0/0' green='0/255/0' blue='0/0/255' a5height=595 [ -f .gmtdefaults ] && rm .gmtdefaults gmtset DOTS_PR_INCH = 72x72 gmtset X_ORIGIN = 36p gmtset Y_ORIGIN = 72p gmtset PAPER_MEDIA = a5 gmtset PAGE_ORIENTATION = portrait # parse options while getopts ':c:' option do case $option in c) colours="${OPTARG}"; continue;; *) die "Unknown option: -${option}" esac done shift $((${OPTIND} - 1)) # check options origifs=${IFS} IFS=',' i=0 for colour in ${colours} do echo $colour | egrep '^(red|green|blue)$' >/dev/null \ || die "Invalid colour ${colour}" clist[$i]="${colour}" i=$((${i}+1)) done [ ${#clist[*]} -eq ${#@} ] || die "Number of colours does not match number of files." IFS="${origifs}" exit # pstmpfile=$(mktemp) || die "Cannot make temporary postfix file." pscoast -R${range} -J${projection} -K -Df -W0.333p > "${pstmpfile}" \ || die "pscoast failed with error $?" cat > "${htmlfile}" < EOM for i in $(seq 1 ${#@}) do [ -f "${cfile}" ] || die "file \"${cfile}\" does not exist" plotps=$(psxy "${cfile}" -R${range} -J${projection} \ -H0 -O -K -Sc4p -W0.5p "-G${red}") \ || die "psxy failed with error $?" echo "${plotps}" >> "${pstmpfile}" \ || die "Cannot add postscript to ${pstmpfile}" ps2hmap >> "${htmlfile}" done cat >> "${htmlfile}" < EOM convert -density 72 "${pstmpfile}" "${outfile}" cleanup