#!/bin/sh

mkdir -p withgps;
while read filename north east angle; do
	if [ ! -e "$filename" -o -z "$north" ]; then
		echo "Skipping $filename";
		continue;
	fi;
	if [ "$angle" == "X" ]; then
		angle="";
	else
		angle="-GPSImgDirection=$angle";
	fi;
	echo "Processing $filename...";
	exiftool \
		-o "withgps/$filename" \
		-GPSLatitudeRef=N -GPSLatitude="$north" \
		-GPSLongitudeRef=E -GPSLongitude="$east" \
		-GPSTrackRef=T -GPSImgDirectionRef=T $angle \
		-GPSProcessingMethod=MANUAL \
		"$filename";
	touch -r "$filename" "withgps/$filename";
done <"COORDS.txt";
