if [ -z "$1" ]
then
	echo "========================================================================"	
	echo "usage:"
	echo "        ./testmap.sh [map size] <jpg>"
	echo "example:"
	echo "         ./testmap.sh 16"
	echo "========================================================================"	
	exit
fi

if [ -n "$2" ]
then
	ext=jpg
else
	ext=png
fi

rm *x.html 2>/dev/null

mapsize=$1


ms=$1
total=0;
while [ $ms -gt 1 ]
do
	let total=total+ms*ms
	let ms=ms/2
done


dirname="_MAP_FOR_LAT_$1_LON_$2_$4x"

ms_original=$mapsize
let xs=x/mapsize*mapsize
let ys=y/mapsize*mapsize

zm=1
prevzoom=0

tilecount=1
while [ $mapsize -gt 1 ]
do

yc=0
	let zm=ms_original/mapsize
	echo "<BODY TOPMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0 LEFTMARGIN=0 RIGHMARGIN=0><TABLE BORDER=0 cellpadding=0 cellspacing=0>" >>${zm}x.html
while  [ $yc -lt $mapsize ]
do
	xc=0
	let y=ys+yc
	echo "<tr nowrap>" >>${zm}x.html
	while  [ $xc -lt $mapsize ]
	do
		let x=xs+xc
		let tilecount=tilecount+1
		let oldx=xc*2
		let oldy=yc*2
		printf "<TD><A HREF=\"./%sx.html#%03d%03d\" NAME=%03d%03d><IMG BORDER=0 SRC=%dx/%03d/%dx%03d%03d.$ext ></A></TD>\n" $prevzoom $oldy $oldx $yc $xc $zm $yc $zm $yc $xc >>${zm}x.html
		let xc=xc+1
	done
		echo "</tr>" >>${zm}x.html
		let yc=yc+1
done
	echo "</table>" >>${zm}x.html
prevzoom=$zm
let xs=xs/2
let ys=ys/2
let zoom=zoom+1
let mapsize=mapsize/2

done


