/usr/lib/gpsman/gdata.tcl is in gpsman 6.4.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | #
# This file is part of:
#
# gpsman --- GPS Manager: a manager for GPS receiver data
#
# Copyright (c) 1998-2011 Miguel Filgueiras migf@portugalmail.pt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.
#
# File: gdata.tcl
# Last change: 19 July 2011
#
## manipulation of geo-referenced data structures
# consisting of a list of pairs $coord1 $col, in increasing order of $coord1
# where $col is a list of pairs $coord2 $data, in increasing order of $coord2
# and $data a list of information for each individual at $coord1 $coord2
proc AddSeqToGData {gdata coord1 coord2 info} {
# add information to geo-referenced data structure
# sequential search
set ne [list $coord1 [list [list $coord2 [list $info]]]]
set i 0
foreach e $gdata {
if { [set le [lindex $e 0]] > $coord1 } {
break
} elseif { $le == $coord1 } {
set nee [list $coord2 [list $info]] ; set col [lindex $e 1]
set j 0
foreach ee $col {
if { [set lee [lindex $ee 0]] > $coord2 } {
break
} elseif { $lee == $coord2 } {
set nee [list $coord2 [linsert [lindex $ee 1] 0 $info]]
set col [lreplace $col $j $j $nee]
return [lreplace $gdata $i $i [list $coord1 $col]]
}
incr j
}
set col [linsert $col $j $nee]
return [lreplace $gdata $i $i [list $coord1 $col]]
}
incr i
}
return [linsert $gdata $i $ne]
}
proc AddToGData {gdata coord1 coord2 info} {
# add information to geo-referenced data structure
# binary search on top level list
set ne [list $coord1 [list [list $coord2 [list $info]]]]
if { [set b [llength $gdata]] == 0 } {
return [list $ne]
}
set a 0
while 1 {
set i [expr ($a+$b)/2]
set e [lindex $gdata $i]
if { [set le [lindex $e 0]] > $coord1 } {
if { $a == $i } {
break
}
set b $i
} elseif { $le == $coord1 } {
set nee [list $coord2 [list $info]] ; set col [lindex $e 1]
set j 0
foreach ee $col {
if { [set lee [lindex $ee 0]] > $coord2 } {
break
} elseif { $lee == $coord2 } {
set nee [list $coord2 [linsert [lindex $ee 1] 0 $info]]
set col [lreplace $col $j $j $nee]
return [lreplace $gdata $i $i [list $coord1 $col]]
}
incr j
}
set col [linsert $col $j $nee]
return [lreplace $gdata $i $i [list $coord1 $col]]
} elseif { $a == $i } {
incr a
break
} else { set a $i }
}
return [linsert $gdata $a $ne]
}
proc LookupGData {gdata coord1 coord2} {
# find information in geo-referenced data structure
# return "" if nothing found
# binary search on top level list
if { [set b [llength $gdata]] == 0 } {
return ""
}
set a 0
while 1 {
set i [expr ($a+$b)/2]
set e [lindex $gdata $i]
if { [set le [lindex $e 0]] > $coord1 } {
if { $a == $i } { break }
set b $i
} elseif { $le == $coord1 } {
foreach ee [lindex $e 1] {
if { [set lee [lindex $ee 0]] > $coord2 } {
return ""
} elseif { $lee == $coord2 } {
return [lindex $ee 1]
}
}
return ""
} elseif { $a == $i } { break } else { set a $i }
}
return ""
}
proc LookupQuadrGData {gdata coord1 coord2 dc1 dc2} {
# find information in geo-referenced data structure
# for each point with coordinates ($coord10,$coord20) if ($coord1,$coord2)
# belongs to the quadrangle centred on it and having as corners
# ($coord10-$dc1/2,$coord20-$dc2/2) ($coord10+$dc1/2,$coord20+$dc2/2)
# with $dc1 and $dc2 > 0
# return list of information for each point
# binary search on top level list
if { $dc1 <= 0 || $dc2 <= 0 || [set b [llength $gdata]] == 0 } {
return ""
}
set hdc1 [expr 0.5*$dc1] ; set hdc2 [expr 0.5*$dc2]
set a 0 ; set res ""
while 1 {
set i [expr ($a+$b)/2]
set e [lindex $gdata $i]
if { [set le [lindex $e 0]]-$hdc1 > $coord1 } {
if { $a == $i } { return $res }
set b $i
} elseif { $le+$hdc1 >= $coord1 } {
foreach ee [lindex $e 1] {
if { [set lee [lindex $ee 0]]-$hdc2 > $coord2 } {
break
} elseif { $lee+$hdc2 >= $coord2 } {
set res [concat $res [lindex $ee 1]]
}
}
break
} elseif { $a == $i } { break } else { set a $i }
}
for { set j [expr $i+1] } { $j != $b } { incr j } {
set e [lindex $gdata $j]
if { [set le [lindex $e 0]]-$hdc1 > $coord1 } { break }
if { $le+$hdc1 >= $coord1 } {
foreach ee [lindex $e 1] {
if { [set lee [lindex $ee 0]]-$hdc2 > $coord2 } {
break
} elseif { $lee+$hdc2 >= $coord2 } {
set res [concat $res [lindex $ee 1]]
}
}
}
}
incr a -1
for { set j [expr $i-1] } { $j != $a } { incr j -1 } {
set e [lindex $gdata $j]
if { [set le [lindex $e 0]]+$hdc1 < $coord1 } { break }
if { $le-$hdc1 <= $coord1 } {
foreach ee [lindex $e 1] {
if { [set lee [lindex $ee 0]]-$hdc2 > $coord2 } {
break
} elseif { $lee+$hdc2 >= $coord2 } {
set res [concat $res [lindex $ee 1]]
}
}
}
}
return $res
}
#### geo-referencing time-stamped information
proc GeoAdapt {type ix datum lts} {
# geo-reference time-stamped information in list $lts adapting it to
# item of given $type and index $ix
# if $type==TR, interpolate/extrapolate positions from time-stamps of TPs
# if $type==GR, take each WP in sequence from GR after sorting time-stamps
# $lts is a list of tuples whose first element is the time-stamp in
# seconds from $YEAR0, sorted by time-stamps
# $datum is the datum for the computed positions
# return "" on error, or list with tuples obtained from the tuples in $lst
# by inserting the latitude and longitude (decimal degrees, for $datum)
# and altitude (metre) at the beginning
global TRTPoints TRDatum DataIndex GRConts WPPosn WPDatum WPAlt
set glts ""
if { $type == "TR" } {
foreach v "la lo s alt" n "TPlatd TPlongd TPsecs TPalt" {
set ${v}ix $DataIndex($n)
set prev$v undef
}
if { $TRDatum($ix) != $datum } {
set tps [ChangeTPsDatum $TRTPoints($ix) $TRDatum($ix) $datum]
} else { set tps $TRTPoints($ix) }
set tp [lindex $tps 0] ; set tps [lreplace $tps 0 0]
foreach x "la lo s alt" {
set tpt$x [lindex $tp [set ${x}ix]]
}
set tptalt [lindex $tptalt 0]
foreach tuple $lts {
set secs [lindex $tuple 0]
while { $secs > $tpts && $tps != "" } {
set tp [lindex $tps 0] ; set tps [lreplace $tps 0 0]
foreach x "la lo s alt" {
set prev$x [set tpt$x]
set tpt$x [lindex $tp [set ${x}ix]]
}
set tptalt [lindex $tptalt 0]
}
# default to postion of current TP if in trouble
# this may imply several tuples to have the same position
set la $tptla ; set lo $tptlo ; set alt $tptalt
if { $secs != $tpts } {
if { $prevla != "undef" } {
# liner interpolation or extrapolation
if { ! [catch \
{set ratio [expr 1.0*($secs-$prevs)/($tpts-$prevs)]}]
} {
set la [expr $prevla+$ratio*($tptla-$prevla)]
set lo [expr $prevlo+$ratio*($tptlo-$prevlo)]
if { $tptalt == "" || $prevalt == "" } {
set alt ""
} else {
set alt [expr $prevalt+$ratio*($tptalt-$prevalt)]
}
}
} elseif { $secs < $tpts && $tps != "" } {
set tp2 [lindex $tps 0]
foreach x "la lo s alt" {
set tp2$x [lindex $tp2 [set ${x}ix]]
}
set tp2alt [lindex $tp2alt 0]
if { ! [catch \
{set ratio [expr 1.0*($secs-$tp2s)/($tpts-$tp2s)]}]
} {
set la [expr $tp2la+$ratio*($tptla-$tp2la)]
set lo [expr $tp2lo+$ratio*($tptlo-$tp2lo)]
if { $tptalt == "" || $tp2alt == "" } {
set alt ""
} else {
set alt [expr $tp2alt+$ratio*($tptalt-$tp2alt)]
}
}
}
}
lappend glts [linsert $tuple 0 $la $lo $alt]
}
} else {
# $type == "GR"
set wpns ""
foreach p $GRConts($ix) {
if { [lindex $p 0] == "WP" } {
set wpns [lindex $p 1]
break
}
}
if { $wpns == "" } {
GMMessage $MESS(allundef)
return ""
}
foreach tuple $lts {
set secs [lindex $tuple 0]
while { $wpns != "" && \
[set wpix [IndexNamed WP [lindex $wpns 0]]] == -1 } {
GMMessage [format $MESS(undefinedWP) [lindex $wpns 0]]
set wpns [lreplace $wpns 0 0]
}
if { $wpns == "" } {
# $la, ... are defined because $wpns was initially non-empty
# not enough WPs: use last one for the remaining tuples
lappend glts [linsert $tuple 0 $la $lo $alt]
continue
}
set la [lindex $WPPosn($wpix) 0] ; set lo [lindex $WPPosn($wpix) 1]
if { $WPDatum($wpix) != $datum } {
set p [ToDatum $la $lo $WPDatum($wpix) $datum]
set la [lindex $p 0] ; set lo [lindex $p 1]
}
set alt [lindex $WPAlt($wpix) 0]
lappend glts [linsert $tuple 0 $la $lo $alt]
set wpns [lreplace $wpns 0 0]
}
}
return $glts
}
|