#!/bin/sh
# HP20040125 20050901 20070709 20070710 20090523 20090614 20090810 20100129
#
# append-rot-date-gps-off -8 `( cd 139canon ; ls *.jpg )` > 139.list

hrsoff="";
for h in $*
do
  if [ -z "$hrsoff" ]; then
    hrsoff=$h
  else
    echo -n $h" "
    orientation=`jhead $h | grep Orientation`
    if [ -z "$orientation" ]; then
      echo -n "0 "
    else
      echo $orientation | awk '{printf "%d ",0+$4}'
    fi
    datetime=`jhead $h | grep Date/Time`
    isodatetime=`echo $datetime | awk '{printf "%s-%s-%s %s",substr($3,1,4),substr($3,6,2),substr($3,9,2),$4}'`
    datetimedisp=`date +%s -d "$isodatetime" | awk -v hrsoff="$hrsoff" '{printf "%s",strftime("%a %F %T",3600*hrsoff+$1)}'`
    echo -n $datetimedisp
    gpspos=`exiftool -S -GPSPosition -c "%03d° %06.3f'" -GPSAltitude -GPSDateTime $h`
    if [ -n "$gpspos" ]; then
      gpslink=`echo $gpspos | sed "s@GPSPosition: @http://maps.google.com/maps?t=h\&amp;q=@;s@ GPSAltitude.*@@;s@ GPSDateTime.*@@;s@°@@g;s@'@@g;s/ /+/g"`
      gpsadt=`echo $gpspos | grep GPSAltitude | grep GPSDateTime`
      if [ -n "$gpsadt" ]; then
        gpsdisp=`echo $gpspos | sed 's@GPSPosition: @@;s@ GPSAltitude: @, @;s@ metres@ m@;s@ GPSDateTime: @, @;s@:@-@;s@:@-@;s@ \(.\):@ 0\1:@;s@:\(.\):@:0\1:@;s@:\(.\)$@:0\1@'`" UTC"
      else
        gpsdisp=`echo $gpspos | sed 's@GPSPosition: @@;s@GPSAltitude.*@@;s@GPSDateTime.*@@'`
      fi
      cmnt=`echo $datetimedisp" GPS: "$gpsdisp | sed 's/ /+/g'`
      echo -n " <a href=\""$gpslink"+("$h"+"$cmnt")\" target=\"_blank\">GPS</a>: "$gpsdisp
    fi
    echo
  fi
done
