#!/bin/bash
#
# gpsfetchmap
# $Log: gpsfetchmap,v $
# Revision 1.13  2003/05/07 19:27:13  ganter
# replaced degree symbol with unicode string
# gpsdrive should now be unicode clean
#
# Revision 1.12  2003/04/30 23:05:52  sven
# fixed a syntax error in line 53..escaped ( and )
#
# Revision 1.11  2003/04/30 22:43:40  sven
# url change: mapblast -> vicinity
#
# Revision 1.10  2003/01/02 03:11:22  ganter
# changed copyright
#
# Revision 1.9  2002/09/28 13:11:13  sven
# never underestimate the power of tiredness. i fixed one and added another bug.
#
# Revision 1.8  2002/09/28 12:48:23  sven
# fixed a typo which made the script useless. i'm sorry.
#
# Revision 1.7  2002/09/18 20:47:54  sven
# fixed the mapblast url
#
# Revision 1.6  2002/04/07 19:55:54  ganter
# bugfix in gpsdrive.c and gpsfetchmap
#
# Revision 1.5  2002/04/07 14:45:11  ganter
# changed line
# while [ `echo "$lat > $endlat" | bc` = 1 ]
# to
# while [ `echo "$lat < $endlat" | bc` = 1 ]
#
#
# by Fritz Ganter, Manfred Caruso, Sven Fichtner
# 2001,2002
# Copyright (c) 2003 by Fritz Ganter
# Your are NOT allowed to modify this script.
# This is a non-free license

EXPEDIAFACT=1378.6
DIFF=0.0000028

if [ $# = 0 ]
then
   echo "ERROR: gpsfetchmap -h for help"
   exit
else
	case $1 in
	    --help | -h)
		echo "Usage: gpsfetchmap start-latitude start-longitude end-latitude end-longitude scale [mapserver]"
		echo "       mapserver = expedia (default) or mapblast"
		exit;;
	esac

	cd $HOME/.gpsdrive
	echo "Please make sure you have a working internet connection!"
	echo "Copyright \(c\) 2003 by Fritz Ganter"
	echo "Your are NOT allowed to modify this script."
	echo "This is a non-free license"
	scale=$5
	
	fileprefix="map_"
	lat=$1
	endlat=$3
	endlong=$4
	k=`echo "$DIFF * $scale" | bc`
	while [ `echo "$lat < $endlat" | bc` = 1 ]
	do
	  long=$2
	  while [ `echo "$long < $endlong" | bc` = 1 ]
	  do
	    filename=$fileprefix$scale-$lat-$long".gif"
	    case $6 in
	      mapblast)
	        wget -nd -O tmpmap.gif http://www.vicinity.com/gif?\&CT=$lat%3A$long%3A$scale\&IC=\&W=1280\&H=1024\&FAM=myblast\&LB=
	      ;;
	      
	      *)
		expediascale=`echo "$scale / $EXPEDIAFACT" | bc`
	        wget -nd -O tmpmap.gif http://msrvmaps.mappoint.net/isapi/MSMap.dll?ID=3XNsF.\&C=$lat,$long\&L=EUR0809\&CV=1\&A=$expediascale\&S=1280,1024\&O=0.000000,0.000000\&MS=0\&P=
		scale=`echo "$expediascale * $EXPEDIAFACT" | bc`
	      ;;
	    esac
	    echo $filename $lat $long $scale >x.txt
	    mv tmpmap.gif $filename
	    cat x.txt >>map_koord.txt
	    sleep 1
	    long=`echo "$long + $k" | bc`
	  done
	  lat=`echo "$lat + $k" | bc`
	done

fi
