Initial source code using libgps (http://gpsd.berlios.de/ and various script
[gps] / script-system-clock
1 #!/bin/sh
2
3 grep "^---" /tmp/mygps.txt | awk '{print $2}' | while read x; do
4     echo "x=${x} prev=${prev} last=${last} ..."
5     if [ "${prev}" == "" ]; then
6         last="${x}"
7         echo "${last}"
8     else
9         diff=$(echo "${x} - ${last}" | bc)
10         #echo " last=${last} x=${x} => diff=${diff}"
11         greater=$(echo "${diff} >= 1.0"|bc)
12         if [ "${greater}" -eq 1 ]; then
13             # we need to choose between ${prev} and ${x}
14             diff1=$(echo "1.0 - (${prev} - ${last})"|bc)
15             diff2=$(echo "(${x} - ${last}) - 1.0"|bc)
16             #echo "diff1=${diff1} diff2=${diff2}"
17             lower=$(echo "${diff1} < ${diff2}"|bc)
18             if [ "${lower}" -eq 1 ]; then
19                 echo "${prev} diff1=${diff1}"
20                 last="${prev}"
21             else
22                 echo "${x} diff2=${diff2}"
23                 last="${x}"
24             fi
25         fi
26     fi
27     prev="${x}"
28 done