#!/usr/bin/awk -f # # roadbook2kml -- make KML template from roadbook.html # # usage: roadbook2kml < roadbook.html > roadbook.kml # # http://www.heikopurnhagen.net/software/ # # This program is available under the terms of the GNU General Public # License (GPL). All usual disclaimers apply! # # Heiko Purnhagen (mail@heikopurnhagen.net) # HP 20150927 BEGIN { if (ARGC==1) { print "usage: roadbook2kml < roadbook.html > roadbook.kml" > "/dev/stderr"; print "" > "/dev/stderr"; } asc = 0; dayasc = 0; day = 0; totasc = 0; tottime = 0; totdist = 0; # Gjuteribacken 17 oldlat = 59.360083; oldlon = 17.970083; } /^
\n\ \n\ \n\ Paths\n\ \n\ " title "\n\ \n\ 1\n\ "; printf "%.6f,%.6f,0\n",oldlon,oldlat; } getline; if ($1=="Total") { totstr = $0; exit; } daydate = gensub(" "," ","g",$1); getline; getline; dayroute = $0; split($0,maps,"t=h&q="); split(maps[2],llar,"+"); if (llar[3]=="S" || llar[3]=="N" ) { lat = llar[1]+llar[2]/60; lon = llar[4]+llar[5]/60; if (llar[3]=="S") { lat = -lat; } if (substr(llar[6],1,1)=="W") { lon = -lon; } } else { lat = oldlat; lon = oldlon; } getline; getline; dayspeed = 0+$1+$2+$3; if (asc) { getline; getline; dayasc = 0+$1+$2+$3; } getline; getline; split($1,hhmm,":"); daytime = 60*hhmm[1]+hhmm[2]; if (match($2,":")) { split($2,hhmm,":"); daytime = daytime+60*hhmm[1]+hhmm[2]; } if (match($3,":")) { split($3,hhmm,":"); daytime = daytime+60*hhmm[1]+hhmm[2]; } getline; getline; gsub("[()+]","",$1); daydist = 0+$1+$2+$3; day = day+1; totasc = totasc + dayasc; tottime = tottime + daytime; totdist = totdist + daydist; printf "%14s %10.6f %11.6f %4.1f %5.0f %3d:%02d %6.1f\n",daydate,lat,lon,dayspeed,dayasc,int(daytime/60),daytime%60,daydist > "/dev/stderr"; printf "%.6f,%.6f,0\n",lon,lat; oldlat = lat; oldlon = lon; } END { printf "DATE LAT LON km/h m hh:mm km\n" > "/dev/stderr"; printf "AVERAGE DAY %4.1f %5.0f %3d:%02d %6.1f\n",totdist/tottime*60,totasc/day,int(tottime/day/60),(tottime/day)%60,totdist/day > "/dev/stderr"; printf "TOTAL: %2d days %5.0f %3d:%02d %6.1f\n",day,totasc,int(tottime/60),tottime%60,totdist > "/dev/stderr"; print "ROADBOOK: " totstr > "/dev/stderr"; print " \n\ \n\ \n\ \n\ "; } #--