This file is indexed.

/usr/lib/gpsman/acccomp.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#
# 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: acccomp.tcl
#  Last change:  19 July 2011
#

# Replacement procedures for more accurate and more slow computations of
#   distances and bearings

# This file to be consulted after compute.tcl

## Formulae for distances and bearings taken from the program "inverse"
#     available from ftp://www.ngs.noaa.gov/pub/pcsoft/for_inv.3d/
#  They correspond to the modified Rainsford's Method with Helmert's
#     elliptical terms, and are effective in any azimuth and at any
#     distance short of antipodal, none of the points can be a pole
#  If one of the points is a pole, or the points are nearly antipodal
#     the Law of Cosines for Spherical Trigonometry, kindly supplied by
#     Luisa Bastos (Universidade do Porto) and Gil Goncalves (Universidade
#     de Coimbra), will be applied
##

proc ComputeDist {p1 p2 datum} {
    # distance between positions $p1 and $p2 with same datum
    # formulae from "inverse" program (see above)

    set lad1 [lindex $p1 0] ; set lod1 [lindex $p1 1]
    set lad2 [lindex $p2 0] ; set lod2 [lindex $p2 1]
    if { $lad1==$lad2 && $lod1==$lod2 } { return 0 }
    set la1 [expr $lad1*0.01745329251994329576]
    set lo1 [expr $lod1*0.01745329251994329576]
    set la2 [expr $lad2*0.01745329251994329576]
    set lo2 [expr $lod2*0.01745329251994329576]
    set dt [EllipsdData $datum]
    set a [lindex $dt 0] ; set f [lindex $dt 1]
    if { [expr abs(cos($la1))]<1.e-20 || [expr abs(cos($la2))]<1.e-20 || \
	 ( $lad1+$lad2 < 1e-4 && abs(abs($lod1-$lod2)-180) < 1e-4 ) } {
	# use Law of Cosines for Spherical Trigonometry
	set x [expr cos($lo1-$lo2)*cos($la1)*cos($la2)+sin($la1)*sin($la2)]
	if { $x >= 1 } { return 0 }
	return [expr 1e-3*$a*acos($x)]
    }
    set eps 5e-12
    set r [expr 1-$f]
    set tu1 [expr $r*tan($la1)] ; set tu2 [expr $r*tan($la2)]
    set cu1 [expr 1.0/sqrt($tu1*$tu1+1.0)]
    set su1 [expr $cu1*$tu1]
    set cu2 [expr 1.0/sqrt($tu2*$tu2+1.0)]
    set s [expr $cu1*$cu2]
    set baz [expr $s*$tu2] ; set faz [expr $baz*$tu1]
    set x [expr $lo2-$lo1] ; set d [expr $x+1]
    while { abs($d-$x) > $eps } {
	set sx [expr sin($x)] ; set cx [expr cos($x)]
	set tu1 [expr $cu2*$sx] ; set tu2 [expr $baz-$su1*$cu2*$cx]
	set sy [expr sqrt($tu1*$tu1+$tu2*$tu2)]
	set cy [expr $s*$cx+$faz] ; set y [expr atan2($sy,$cy)]
	set sa [expr $s*$sx/$sy] ; set c2a [expr -$sa*$sa+1.0]
	set cz [expr $faz+$faz]
	if { $cz > 0 } { set cz [expr -$cz/$c2a+$cy] }
	set e [expr $cz*$cz*2-1.0]
	set c [expr ((-3*$c2a+4.0)*$f+4.0)*$c2a*$f/16]
	set d $x
	set x [expr (($e*$cy*$c+$cz)*$sy*$c+$y)*$sa]
	set x [expr (1-$c)*$x*$f+$lo2-$lo1]
    }
    set faz [expr atan2($tu1,$tu2)]
    set baz [expr atan2($cu1*$sx,$baz*$cx-$su1*$cu2)+3.14159265358979323846]
    set x [expr sqrt((1.0/$r/$r-1)*$c2a+1)+1] ; set x [expr ($x-2.0)/$x]
    set c [expr 1-$x] ; set c [expr ($x*$x/4.0+1)/$c]
    set d [expr (0.375*$x*$x-1)*$x]
    set x [expr $e*$cy]
    set s [expr 1-$e-$e]
    set s [expr (((($sy*$sy*4-3)*$s*$cz*$d/6.0-$x)*$d/4.0+$cz)*$sy*$d+$y) \
	        *$c*$a*$r*1e-3]
    return $s
}

proc ComputeBear {p1 p2 datum} {
    # bearing from positions $p1 and $p2 with same datum
    # formulae from "inverse" program (see above)

    set lad1 [lindex $p1 0] ; set lod1 [lindex $p1 1]
    set lad2 [lindex $p2 0] ; set lod2 [lindex $p2 1]
    if { $lad1==$lad2 && $lod1==$lod2 } { return 0 }
    set la1 [expr $lad1*0.01745329251994329576]
    set lo1 [expr $lod1*0.01745329251994329576]
    set la2 [expr $lad2*0.01745329251994329576]
    set lo2 [expr $lod2*0.01745329251994329576]
    if { [expr abs(cos($la1))]<1.e-20 || [expr abs(cos($la2))]<1.e-20 } {
	# use Law of Cosines for Spherical Trigonometry
	# bearing
	set da [expr $la2-$la1] ; set do [expr $lo2-$lo1]
	if { [expr abs($da)] < 1e-20 } {
	    if { [expr abs($do)] < 1e-20 } {
		set b 0
	    } elseif { $do < 0 } {
		set b 270
	    } else { set b 90 }
	} elseif { [expr abs($do)] < 1e-20 } {
	    if { $da < 0 } {
		set b 180
	    } else { set b 0 }
	} else {
	    set b [expr round(atan2(sin($do), \
		                    tan($la2)*cos($la1)-sin($la1)*cos($do)) \
				    *57.29577951308232087684)]
	    if { $b < 0 } {
		if { $do < 0 } { incr b 360 } else { incr b 180 }
	    } elseif { $do < 0 } { incr b 180 }
	}
	return $b
    }
    set dt [EllipsdData $datum]
    set a [lindex $dt 0] ; set f [lindex $dt 1]
    set eps 5e-12
    set r [expr 1-$f]
    set tu1 [expr $r*tan($la1)] ; set tu2 [expr $r*tan($la2)]
    set cu1 [expr 1.0/sqrt($tu1*$tu1+1.0)]
    set su1 [expr $cu1*$tu1]
    set cu2 [expr 1.0/sqrt($tu2*$tu2+1.0)]
    set s [expr $cu1*$cu2]
    set baz [expr $s*$tu2] ; set faz [expr $baz*$tu1]
    set x [expr $lo2-$lo1] ; set d [expr $x+1]
    while { abs($d-$x) > $eps } {
	set sx [expr sin($x)] ; set cx [expr cos($x)]
	set tu1 [expr $cu2*$sx] ; set tu2 [expr $baz-$su1*$cu2*$cx]
	set sy [expr sqrt($tu1*$tu1+$tu2*$tu2)]
	set cy [expr $s*$cx+$faz] ; set y [expr atan2($sy,$cy)]
	set sa [expr $s*$sx/$sy] ; set c2a [expr -$sa*$sa+1.0]
	set cz [expr $faz+$faz]
	if { $cz > 0 } { set cz [expr -$cz/$c2a+$cy] }
	set e [expr $cz*$cz*2-1.0]
	set c [expr ((-3*$c2a+4.0)*$f+4.0)*$c2a*$f/16]
	set d $x
	set x [expr (($e*$cy*$c+$cz)*$sy*$c+$y)*$sa]
	set x [expr (1-$c)*$x*$f+$lo2-$lo1]
    }
    set faz [expr atan2($tu1,$tu2)]
    set b [expr round($faz*57.29577951308232087684)]
    if { $b < 0 } { incr b 360 }
    return $b
}

proc ComputeDistBear {p1 p2 datum} {
    # distance between and bearing from positions $p1 and $p2 with same datum
    # formulae from "inverse" program (see above)

    set lad1 [lindex $p1 0] ; set lod1 [lindex $p1 1]
    set lad2 [lindex $p2 0] ; set lod2 [lindex $p2 1]
    if { $lad1==$lad2 && $lod1==$lod2 } { return "0 0" }
    set la1 [expr $lad1*0.01745329251994329576]
    set lo1 [expr $lod1*0.01745329251994329576]
    set la2 [expr $lad2*0.01745329251994329576]
    set lo2 [expr $lod2*0.01745329251994329576]
    set dt [EllipsdData $datum]
    set a [lindex $dt 0] ; set f [lindex $dt 1]
    if { [expr abs(cos($la1))]<1.e-20 || [expr abs(cos($la2))]<1.e-20 } {
	# use Law of Cosines for Spherical Trigonometry
	# bearing
	set da [expr $la2-$la1] ; set do [expr $lo2-$lo1]
	if { [expr abs($da)] < 1e-20 } {
	    if { [expr abs($do)] < 1e-20 } {
		set b 0
	    } elseif { $do < 0 } {
		set b 270
	    } else { set b 90 }
	} elseif { [expr abs($do)] < 1e-20 } {
	    if { $da < 0 } {
		set b 180
	    } else { set b 0 }
	} else {
	    set b [expr round(atan2(sin($do), \
		                    tan($la2)*cos($la1)-sin($la1)*cos($do)) \
				    *57.29577951308232087684)]
	    if { $b < 0 } {
		if { $do < 0 } { incr b 360 } else { incr b 180 }
	    } elseif { $do < 0 } { incr b 180 }
	}
	return [list [expr 1e-3*$a*acos(cos($lo1-$lo2)*cos($la1)*cos($la2)+ \
		sin($la1)*sin($la2))] $b]
    }
    set eps 5e-12
    set r [expr 1-$f]
    set tu1 [expr $r*tan($la1)] ; set tu2 [expr $r*tan($la2)]
    set cu1 [expr 1.0/sqrt($tu1*$tu1+1.0)]
    set su1 [expr $cu1*$tu1]
    set cu2 [expr 1.0/sqrt($tu2*$tu2+1.0)]
    set s [expr $cu1*$cu2]
    set baz [expr $s*$tu2] ; set faz [expr $baz*$tu1]
    set x [expr $lo2-$lo1] ; set d [expr $x+1]
    while { abs($d-$x) > $eps } {
	set sx [expr sin($x)] ; set cx [expr cos($x)]
	set tu1 [expr $cu2*$sx] ; set tu2 [expr $baz-$su1*$cu2*$cx]
	set sy [expr sqrt($tu1*$tu1+$tu2*$tu2)]
	set cy [expr $s*$cx+$faz] ; set y [expr atan2($sy,$cy)]
	set sa [expr $s*$sx/$sy] ; set c2a [expr -$sa*$sa+1.0]
	set cz [expr $faz+$faz]
	if { $cz > 0 } { set cz [expr -$cz/$c2a+$cy] }
	set e [expr $cz*$cz*2-1.0]
	set c [expr ((-3*$c2a+4.0)*$f+4.0)*$c2a*$f/16]
	set d $x
	set x [expr (($e*$cy*$c+$cz)*$sy*$c+$y)*$sa]
	set x [expr (1-$c)*$x*$f+$lo2-$lo1]
    }
    set faz [expr atan2($tu1,$tu2)]
    set baz [expr atan2($cu1*$sx,$baz*$cx-$su1*$cu2)+3.14159265358979323846]
    set x [expr sqrt((1.0/$r/$r-1)*$c2a+1)+1] ; set x [expr ($x-2.0)/$x]
    set c [expr 1-$x] ; set c [expr ($x*$x/4.0+1)/$c]
    set d [expr (0.375*$x*$x-1)*$x]
    set x [expr $e*$cy]
    set s [expr 1-$e-$e]
    set s [expr (((($sy*$sy*4-3)*$s*$cz*$d/6.0-$x)*$d/4.0+$cz)*$sy*$d+$y) \
	        *$c*$a*$r*1e-3]
    set b [expr round($faz*57.29577951308232087684)]
    if { $b < 0 } { incr b 360 }
    return [list $s $b]
}

proc ComputeDistFD {p1 p2} {
    # compute distance between positions $p1 and $p2 assuming datum
    #  parameters where set by calling SetDatumData
    global DatumA DatumF
            # formulae from "inverse" program (see above)

    set lad1 [lindex $p1 0] ; set lod1 [lindex $p1 1]
    set lad2 [lindex $p2 0] ; set lod2 [lindex $p2 1]
    if { $lad1==$lad2 && $lod1==$lod2 } { return 0 }
    set la1 [expr $lad1*0.01745329251994329576]
    set lo1 [expr $lod1*0.01745329251994329576]
    set la2 [expr $lad2*0.01745329251994329576]
    set lo2 [expr $lod2*0.01745329251994329576]
    if { [expr abs(cos($la1))]<1.e-20 || [expr abs(cos($la2))]<1.e-20 } {
	# use Law of Cosines for Spherical Trigonometry
	set x [expr cos($lo1-$lo2)*cos($la1)*cos($la2)+sin($la1)*sin($la2)]
	if { $x >= 1 } { return 0 }
	return [expr 1e-3*$DatumA*acos($x)]
    }
    set eps 5e-12
    set r [expr 1-$DatumF]
    set tu1 [expr $r*tan($la1)] ; set tu2 [expr $r*tan($la2)]
    set cu1 [expr 1.0/sqrt($tu1*$tu1+1.0)]
    set su1 [expr $cu1*$tu1]
    set cu2 [expr 1.0/sqrt($tu2*$tu2+1.0)]
    set s [expr $cu1*$cu2]
    set baz [expr $s*$tu2] ; set faz [expr $baz*$tu1]
    set x [expr $lo2-$lo1] ; set d [expr $x+1]
    while { abs($d-$x) > $eps } {
	set sx [expr sin($x)] ; set cx [expr cos($x)]
	set tu1 [expr $cu2*$sx] ; set tu2 [expr $baz-$su1*$cu2*$cx]
	set sy [expr sqrt($tu1*$tu1+$tu2*$tu2)]
	set cy [expr $s*$cx+$faz] ; set y [expr atan2($sy,$cy)]
	set sa [expr $s*$sx/$sy] ; set c2a [expr -$sa*$sa+1.0]
	set cz [expr $faz+$faz]
	if { $cz > 0 } { set cz [expr -$cz/$c2a+$cy] }
	set e [expr $cz*$cz*2-1.0]
	set c [expr ((-3*$c2a+4.0)*$DatumF+4.0)*$c2a*$DatumF/16]
	set d $x
	set x [expr (($e*$cy*$c+$cz)*$sy*$c+$y)*$sa]
	set x [expr (1-$c)*$x*$DatumF+$lo2-$lo1]
    }
    set faz [expr atan2($tu1,$tu2)]
    set baz [expr atan2($cu1*$sx,$baz*$cx-$su1*$cu2)+3.14159265358979323846]
    set x [expr sqrt((1.0/$r/$r-1)*$c2a+1)+1] ; set x [expr ($x-2.0)/$x]
    set c [expr 1-$x] ; set c [expr ($x*$x/4.0+1)/$c]
    set d [expr (0.375*$x*$x-1)*$x]
    set x [expr $e*$cy]
    set s [expr 1-$e-$e]
    set s [expr (((($sy*$sy*4-3)*$s*$cz*$d/6.0-$x)*$d/4.0+$cz)*$sy*$d+$y) \
	        *$c*$DatumA*$r*1e-3]
    return $s
}

proc ComputeDistBearFD {p1 p2} {
    # compute distance between and bearing from positions $p1 and $p2
    #  assuming datum parameters where set by calling SetDatumData
    global DatumA DatumF
            # formulae from "inverse" program (see above)

    set lad1 [lindex $p1 0] ; set lod1 [lindex $p1 1]
    set lad2 [lindex $p2 0] ; set lod2 [lindex $p2 1]
    if { $lad1==$lad2 && $lod1==$lod2 } { return "0 0" }
    set la1 [expr $lad1*0.01745329251994329576]
    set lo1 [expr $lod1*0.01745329251994329576]
    set la2 [expr $lad2*0.01745329251994329576]
    set lo2 [expr $lod2*0.01745329251994329576]
    if { [expr abs(cos($la1))]<1.e-20 || [expr abs(cos($la2))]<1.e-20 } {
	# use Law of Cosines for Spherical Trigonometry
	# bearing
	set da [expr $la2-$la1] ; set do [expr $lo2-$lo1]
	if { [expr abs($da)] < 1e-20 } {
	    if { [expr abs($do)] < 1e-20 } {
		set b 0
	    } elseif { $do < 0 } {
		set b 270
	    } else { set b 90 }
	} elseif { [expr abs($do)] < 1e-20 } {
	    if { $da < 0 } {
		set b 180
	    } else { set b 0 }
	} else {
	    set b [expr round(atan2(sin($do), \
		                    tan($la2)*cos($la1)-sin($la1)*cos($do)) \
				    *57.29577951308232087684)]
	    if { $b < 0 } {
		if { $do < 0 } { incr b 360 } else { incr b 180 }
	    } elseif { $do < 0 } { incr b 180 }
	}
	return [list [expr 1e-3*$DatumA*acos(cos($lo1-$lo2)*cos($la1)* \
		cos($la2)+sin($la1)*sin($la2))] $b]
    }
    set eps 5e-12
    set r [expr 1-$DatumF]
    set tu1 [expr $r*tan($la1)] ; set tu2 [expr $r*tan($la2)]
    set cu1 [expr 1.0/sqrt($tu1*$tu1+1.0)]
    set su1 [expr $cu1*$tu1]
    set cu2 [expr 1.0/sqrt($tu2*$tu2+1.0)]
    set s [expr $cu1*$cu2]
    set baz [expr $s*$tu2] ; set faz [expr $baz*$tu1]
    set x [expr $lo2-$lo1] ; set d [expr $x+1]
    while { abs($d-$x) > $eps } {
	set sx [expr sin($x)] ; set cx [expr cos($x)]
	set tu1 [expr $cu2*$sx] ; set tu2 [expr $baz-$su1*$cu2*$cx]
	set sy [expr sqrt($tu1*$tu1+$tu2*$tu2)]
	set cy [expr $s*$cx+$faz] ; set y [expr atan2($sy,$cy)]
	set sa [expr $s*$sx/$sy] ; set c2a [expr -$sa*$sa+1.0]
	set cz [expr $faz+$faz]
	if { $cz > 0 } { set cz [expr -$cz/$c2a+$cy] }
	set e [expr $cz*$cz*2-1.0]
	set c [expr ((-3*$c2a+4.0)*$DatumF+4.0)*$c2a*$DatumF/16]
	set d $x
	set x [expr (($e*$cy*$c+$cz)*$sy*$c+$y)*$sa]
	set x [expr (1-$c)*$x*$DatumF+$lo2-$lo1]
    }
    set faz [expr atan2($tu1,$tu2)]
    set baz [expr atan2($cu1*$sx,$baz*$cx-$su1*$cu2)+3.14159265358979323846]
    set x [expr sqrt((1.0/$r/$r-1)*$c2a+1)+1] ; set x [expr ($x-2.0)/$x]
    set c [expr 1-$x] ; set c [expr ($x*$x/4.0+1)/$c]
    set d [expr (0.375*$x*$x-1)*$x]
    set x [expr $e*$cy]
    set s [expr 1-$e-$e]
    set s [expr (((($sy*$sy*4-3)*$s*$cz*$d/6.0-$x)*$d/4.0+$cz)*$sy*$d+$y) \
	        *$c*$DatumA*$r*1e-3]
    set b [expr round($faz*57.29577951308232087684)]
    if { $b < 0 } { incr b 360 }
    return [list $s $b]
}