author | A.M. Thurnherr <athurnherr@yahoo.com> |
Wed, 25 May 2016 12:23:02 -0400 | |
changeset 34 | 3b4bcd55e1ea |
parent 32 | 7155adf61d77 |
child 35 | 7c394a2d1fc9 |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# R D I _ C O O R D S . P L |
|
3 |
# doc: Sun Jan 19 17:57:53 2003 |
|
34 | 4 |
# dlm: Thu May 19 10:18:44 2016 |
0 | 5 |
# (c) 2003 A.M. Thurnherr |
34 | 6 |
# uE-Info: 167 0 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# RDI Workhorse Coordinate Transformations |
|
10 |
||
11 |
# HISTORY: |
|
12 |
# Jan 19, 2003: - written |
|
13 |
# Jan 21, 2003: - made it obey HEADING_BIAS (magnetic declination) |
|
14 |
# Jan 22, 3003: - corrected magnetic declination |
|
15 |
# Feb 16, 2003: - use pitch correction from RDI manual |
|
16 |
# Oct 11, 2003: - BUG: return value of atan() had been interpreted |
|
17 |
# as degrees instead of radians |
|
18 |
# Feb 27, 2004: - added velApplyHdgBias() |
|
19 |
# - changed non-zero HEADING_ALIGNMENT from error to warning |
|
20 |
# Sep 16, 2005: - added deg() for [mkprofile] |
|
21 |
# Aug 26, 2006: - BUG: incorrect transformation for uplookers |
|
22 |
# Nov 30, 2007: - optimized &velInstrumentToEarth(), velBeamToInstrument() |
|
23 |
# - added support for 3-beam solutions |
|
24 |
# Feb 12, 2008: - added threeBeamFlag |
|
25 |
# Mar 18, 2009: - added &gimbal_pitch(), &angle_from_vertical() |
|
26 |
# May 19, 2009: - added &velBeamToVertical() |
|
27 |
# May 23, 2009: - debugged & renamed to &velBeamToBPEarth |
|
28 |
# May 23, 2010: - changed prototypes of rad() & deg() to conform to ANTS |
|
5 | 29 |
# Dec 20, 2010: - cosmetics |
6 | 30 |
# Dec 23, 2010: - added &velBeamToBPInstrument |
31 |
# Jan 22, 2011: - made velApplyHdgBias calculate sin/cos every time to allow |
|
32 |
# per-ensemble corrections |
|
8 | 33 |
# Jan 15, 2012: - replaced defined(@...) by (@...) to get rid of warning |
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
34 |
# Aug 7, 2013: - BUG: &velBeamToBPInstrument did not return any val unless |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
35 |
# all beam velocities are defined |
14 | 36 |
# Nov 27, 2013: - added &RDI_pitch(), &tilt_azimuth() |
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
37 |
# Mar 4, 2014: - added support for ensembles with missing PITCH/ROLL/HEADING |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
38 |
# May 29, 2014: - BUG: vertical velocity can be calculated even without |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
39 |
# heading |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
40 |
# - removed some old debug statements |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
41 |
# - removed unused code from &velBeamToBPInstrument |
28 | 42 |
# Jan 5, 2016: - added &velEarthToInstrument(@), &velInstrumentToBeam(@) |
31 | 43 |
# Jan 9, 2016: - added &velEarthToBeam(), &velBeamToEarth() |
32 | 44 |
# Feb 29, 2016: - debugged & verified velEarthToInstrument(), velInstrumentToBeam() |
45 |
# - added velBeamToEarth() |
|
34 | 46 |
# May 19, 2016: - begin implemeting bin interpolation |
0 | 47 |
|
48 |
use strict; |
|
49 |
use POSIX; |
|
50 |
||
51 |
my($PI) = 3.14159265358979; |
|
52 |
||
53 |
sub rad(@) { return $_[0]/180 * $PI; } |
|
54 |
sub deg(@) { return $_[0]/$PI * 180; } |
|
55 |
||
56 |
$RDI_Coords::minValidVels = 3; # 3-beam solutions ok |
|
57 |
||
58 |
$RDI_Coords::threeBeam_1 = 0; # stats |
|
59 |
$RDI_Coords::threeBeam_2 = 0; |
|
60 |
$RDI_Coords::threeBeam_3 = 0; |
|
61 |
$RDI_Coords::threeBeam_4 = 0; |
|
62 |
$RDI_Coords::fourBeam = 0; |
|
63 |
||
64 |
$RDI_Coords::threeBeamFlag = 0; # flag last transformation |
|
65 |
||
66 |
{ # STATIC SCOPE |
|
67 |
my(@B2I); |
|
68 |
||
69 |
sub velBeamToInstrument(@) |
|
70 |
{ |
|
34 | 71 |
my($dta,$ens,$v1,$v2,$v3,$v4) = @_; |
0 | 72 |
return undef unless (defined($v1) + defined($v2) + |
73 |
defined($v3) + defined($v4) |
|
74 |
>= $RDI_Coords::minValidVels); |
|
75 |
||
8 | 76 |
unless (@B2I) { |
0 | 77 |
my($a) = 1 / (2 * sin(rad($dta->{BEAM_ANGLE}))); |
78 |
my($b) = 1 / (4 * cos(rad($dta->{BEAM_ANGLE}))); |
|
79 |
my($c) = $dta->{CONVEX_BEAM_PATTERN} ? 1 : -1; |
|
80 |
my($d) = $a / sqrt(2); |
|
81 |
@B2I = ([$c*$a, -$c*$a, 0, 0 ], |
|
82 |
[0, 0, -$c*$a, $c*$a], |
|
83 |
[$b, $b, $b, $b ], |
|
84 |
[$d, $d, -$d, -$d ]); |
|
85 |
} |
|
86 |
||
87 |
if (!defined($v1)) { # 3-beam solutions |
|
88 |
$RDI_Coords::threeBeamFlag = 1; |
|
89 |
$RDI_Coords::threeBeam_1++; |
|
90 |
$v1 = -($v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][0]; |
|
91 |
} elsif (!defined($v2)) { |
|
92 |
$RDI_Coords::threeBeamFlag = 1; |
|
93 |
$RDI_Coords::threeBeam_2++; |
|
94 |
$v2 = -($v1*$B2I[3][0]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][1]; |
|
95 |
} elsif (!defined($v3)) { |
|
96 |
$RDI_Coords::threeBeamFlag = 1; |
|
97 |
$RDI_Coords::threeBeam_3++; |
|
98 |
$v3 = -($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v4*$B2I[3][3])/$B2I[3][2]; |
|
99 |
} elsif (!defined($v4)) { |
|
100 |
$RDI_Coords::threeBeamFlag = 1; |
|
101 |
$RDI_Coords::threeBeam_4++; |
|
102 |
$v4 = -($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2])/$B2I[3][3]; |
|
103 |
} else { |
|
104 |
$RDI_Coords::threeBeamFlag = 0; |
|
105 |
$RDI_Coords::fourBeam++; |
|
106 |
} |
|
107 |
||
108 |
return ($v1*$B2I[0][0]+$v2*$B2I[0][1], |
|
109 |
$v3*$B2I[1][2]+$v4*$B2I[1][3], |
|
110 |
$v1*$B2I[2][0]+$v2*$B2I[2][1]+$v3*$B2I[2][2]+$v4*$B2I[2][3], |
|
111 |
$v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3]); |
|
112 |
} |
|
113 |
} # STATIC SCOPE |
|
114 |
||
115 |
{ # STATIC SCOPE |
|
116 |
my($hdg,$pitch,$roll,@I2E); |
|
117 |
||
118 |
sub velInstrumentToEarth(@) |
|
119 |
{ |
|
120 |
my($dta,$ens,$v1,$v2,$v3,$v4) = @_; |
|
121 |
return undef unless (defined($v1) && defined($v2) && |
|
18 | 122 |
defined($v3) && defined($v4) && |
123 |
defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
124 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
0 | 125 |
|
126 |
unless (@I2E && |
|
127 |
$pitch == $dta->{ENSEMBLE}[$ens]->{PITCH} && |
|
128 |
$roll == $dta->{ENSEMBLE}[$ens]->{ROLL}) { |
|
129 |
printf(STDERR "$0: warning HEADING_ALIGNMENT == %g ignored\n", |
|
130 |
$dta->{HEADING_ALIGNMENT}) |
|
131 |
if ($dta->{HEADING_ALIGNMENT}); |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
132 |
$hdg = $dta->{ENSEMBLE}[$ens]->{HEADING} - $dta->{HEADING_BIAS} |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
133 |
if defined($dta->{ENSEMBLE}[$ens]->{HEADING}); |
0 | 134 |
$pitch = $dta->{ENSEMBLE}[$ens]->{PITCH}; |
135 |
$roll = $dta->{ENSEMBLE}[$ens]->{ROLL}; |
|
136 |
my($rad_gimbal_pitch) = atan(tan(rad($pitch)) * cos(rad($roll))); |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
137 |
my($sh,$ch) = (sin(rad($hdg)),cos(rad($hdg))) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
138 |
if defined($hdg); |
0 | 139 |
my($sp,$cp) = (sin($rad_gimbal_pitch),cos($rad_gimbal_pitch)); |
140 |
my($sr,$cr) = (sin(rad($roll)), cos(rad($roll))); |
|
141 |
@I2E = $dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} |
|
142 |
? ( |
|
143 |
[-$ch*$cr-$sh*$sp*$sr, $sh*$cp,-$ch*$sr+$sh*$sp*$cr], |
|
144 |
[-$ch*$sp*$sr+$sh*$cr, $ch*$cp, $sh*$sr+$ch*$sp*$cr], |
|
145 |
[+$cp*$sr, $sp, -$cp*$cr, ], |
|
146 |
) : ( |
|
147 |
[$ch*$cr+$sh*$sp*$sr, $sh*$cp, $ch*$sr-$sh*$sp*$cr], |
|
148 |
[$ch*$sp*$sr-$sh*$cr, $ch*$cp,-$sh*$sr-$ch*$sp*$cr], |
|
149 |
[-$cp*$sr, $sp, $cp*$cr, ], |
|
150 |
); |
|
151 |
} |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
152 |
return defined($dta->{ENSEMBLE}[$ens]->{HEADING}) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
153 |
? ($v1*$I2E[0][0]+$v2*$I2E[0][1]+$v3*$I2E[0][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
154 |
$v1*$I2E[1][0]+$v2*$I2E[1][1]+$v3*$I2E[1][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
155 |
$v1*$I2E[2][0]+$v2*$I2E[2][1]+$v3*$I2E[2][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
156 |
$v4) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
157 |
: (undef,undef, |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
158 |
$v1*$I2E[2][0]+$v2*$I2E[2][1]+$v3*$I2E[2][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
159 |
$v4); |
0 | 160 |
} |
161 |
} # STATIC SCOPE |
|
162 |
||
32 | 163 |
|
164 |
sub velBeamToEarth(@) |
|
165 |
{ |
|
166 |
my($dtaR,$e,@v) = @_; |
|
34 | 167 |
return velInstrumentToEarth($dtaR,$e,velBeamToInstrument($dtaR,$e,@v)); |
32 | 168 |
} |
169 |
||
28 | 170 |
#---------------------------------------------------------------------- |
171 |
# velEarthToInstrument() transforms earth to instrument coordinates |
|
172 |
# - based on manually inverted rotation matrix M (Sec 5.6 in coord-trans manual) |
|
32 | 173 |
# - code was verified for both down- and uplookers |
28 | 174 |
# - missing heading data (IMP) causes undef beam velocities |
175 |
#---------------------------------------------------------------------- |
|
176 |
||
177 |
{ # STATIC SCOPE |
|
178 |
my($hdg,$pitch,$roll,@E2I); |
|
179 |
||
180 |
sub velEarthToInstrument(@) |
|
181 |
{ |
|
182 |
my($dta,$ens,$u,$v,$w,$ev) = @_; |
|
183 |
||
32 | 184 |
unless (@E2I && |
185 |
$pitch == $dta->{ENSEMBLE}[$ens]->{PITCH} && |
|
186 |
$roll == $dta->{ENSEMBLE}[$ens]->{ROLL}) { |
|
31 | 187 |
$hdg = $dta->{ENSEMBLE}[$ens]->{HEADING} - $dta->{HEADING_BIAS} |
188 |
if defined($dta->{ENSEMBLE}[$ens]->{HEADING}); |
|
28 | 189 |
$pitch = $dta->{ENSEMBLE}[$ens]->{PITCH}; |
190 |
$roll = $dta->{ENSEMBLE}[$ens]->{ROLL}; |
|
191 |
my($rad_gimbal_pitch) = atan(tan(rad($pitch)) * cos(rad($roll))); |
|
32 | 192 |
my($useRoll) = ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) ? $roll+180 : $roll; |
28 | 193 |
my($sh,$ch) = (sin(rad($hdg)),cos(rad($hdg))) |
194 |
if defined($hdg); |
|
195 |
my($sp,$cp) = (sin($rad_gimbal_pitch),cos($rad_gimbal_pitch)); |
|
32 | 196 |
my($sr,$cr) = (sin(rad($useRoll)), cos(rad($useRoll))); |
197 |
@E2I = ([$ch*$cr+$sh*$sp*$sr, $ch*$sp*$sr-$sh*$cr, -$cp*$sr], # M^-1 = R^-1 * P^-1 * R^-1 |
|
198 |
[$sh*$cp, $ch*$cp, $sp ], |
|
199 |
[$ch*$sr-$sh*$sp*$cr, -$sh*$sr-$ch*$sp*$cr, $cp*$cr]); |
|
28 | 200 |
} |
201 |
||
202 |
return defined($dta->{ENSEMBLE}[$ens]->{HEADING}) |
|
203 |
? ($u*$E2I[0][0]+$v*$E2I[0][1]+$w*$E2I[0][2], |
|
204 |
$u*$E2I[1][0]+$v*$E2I[1][1]+$w*$E2I[1][2], |
|
205 |
$u*$E2I[2][0]+$v*$E2I[2][1]+$w*$E2I[2][2], |
|
206 |
$ev) |
|
207 |
: (undef,undef,undef,undef); |
|
208 |
||
209 |
} |
|
210 |
} # STATIC SCOPE |
|
211 |
||
212 |
#---------------------------------------------------------------------- |
|
213 |
# velInstrumentToBeam() transforms instrument to beam coordinates |
|
214 |
# - based on manually solved eq system in sec 5.3 of coord manual |
|
215 |
# - does not implement bin-remapping |
|
216 |
# - does not work for 3-beam solutions, as it is not known which |
|
217 |
# beam was bad |
|
218 |
#---------------------------------------------------------------------- |
|
219 |
||
220 |
{ # STATIC SCOPE |
|
221 |
my($a,$b,$c,$d); |
|
222 |
||
223 |
sub velInstrumentToBeam(@) |
|
224 |
{ |
|
225 |
my($dta,$x,$y,$z,$ev) = @_; |
|
226 |
return undef unless (defined($x) + defined($y) + |
|
227 |
defined($z) + defined($ev) == 4); |
|
228 |
||
229 |
unless (defined($a)) { |
|
230 |
$a = 1 / (2 * sin(rad($dta->{BEAM_ANGLE}))); |
|
231 |
$b = 1 / (4 * cos(rad($dta->{BEAM_ANGLE}))); |
|
232 |
$c = $dta->{CONVEX_BEAM_PATTERN} ? 1 : -1; |
|
233 |
$d = $a / sqrt(2); |
|
234 |
} |
|
235 |
||
236 |
return ( $x/(2*$a*$c) + $z/(4*$b) + $ev/(4*$d), |
|
237 |
-$x/(2*$a*$c) + $z/(4*$b) + $ev/(4*$d), |
|
238 |
-$y/(2*$a*$c) + $z/(4*$b) - $ev/(4*$d), |
|
239 |
$y/(2*$a*$c) + $z/(4*$b) - $ev/(4*$d)); |
|
240 |
||
241 |
} |
|
242 |
} # STATIC SCOPE |
|
243 |
||
31 | 244 |
#---------------------------------------------------------------------- |
245 |
# velEarthToBeam() combines velEarthToInstrument and velInstrumentToBeam |
|
246 |
#---------------------------------------------------------------------- |
|
247 |
||
248 |
sub velEarthToBeam(@) |
|
249 |
{ |
|
250 |
my($dta,$ens,$u,$v,$w,$ev) = @_; |
|
251 |
return velInstrumentToBeam($dta, |
|
252 |
velEarthToInstrument($dta,$ens,$u,$v,$w,$ev)); |
|
253 |
} |
|
254 |
||
0 | 255 |
#====================================================================== |
5 | 256 |
# velBeamToBPEarth(@) calculates the vertical- and horizontal vels |
0 | 257 |
# from the two beam pairs separately. Note that (w1+w2)/2 is |
258 |
# identical to the w estimated according to RDI without 3-beam |
|
259 |
# solutions. |
|
260 |
#====================================================================== |
|
261 |
||
262 |
{ # STATIC SCOPE |
|
263 |
my($TwoCosBAngle,$TwoSinBAngle); |
|
264 |
||
265 |
sub velBeamToBPEarth(@) |
|
266 |
{ |
|
267 |
my($dta,$ens,$b1,$b2,$b3,$b4) = @_; |
|
268 |
my($v12,$w12,$v34,$w34); |
|
269 |
||
18 | 270 |
return (undef,undef,undef,undef) |
271 |
unless (defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
272 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
18 | 273 |
|
0 | 274 |
unless (defined($TwoCosBAngle)) { |
275 |
$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE})); |
|
276 |
$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE})); |
|
277 |
} |
|
278 |
my($roll) = rad($dta->{ENSEMBLE}[$ens]->{ROLL}); |
|
279 |
my($sr) = sin($roll); my($cr) = cos($roll); |
|
280 |
my($pitch) = atan(tan(rad($dta->{ENSEMBLE}[$ens]->{PITCH})) * $cr); # gimbal pitch |
|
281 |
my($sp) = sin($pitch); my($cp) = cos($pitch); |
|
282 |
||
283 |
# Sign convention: |
|
284 |
# - refer to Coord manual Fig. 3 |
|
285 |
# - v12 is horizontal velocity from beam1 to beam2, i.e. westward for upward-looking ADCP |
|
286 |
# with beam 3 pointing north (heading = 0) |
|
287 |
# - w is +ve upward, regardless of instrument orientation |
|
288 |
||
289 |
my($v12_ic) = ($b1-$b2)/$TwoSinBAngle; # instrument coords with w vertical up |
|
290 |
my($w12_ic) = ($b1+$b2)/$TwoCosBAngle; |
|
291 |
$w12_ic *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
292 |
my($v34_ic) = ($b3-$b4)/$TwoSinBAngle; |
|
293 |
my($w34_ic) = ($b3+$b4)/$TwoCosBAngle; |
|
294 |
$w34_ic *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
295 |
||
296 |
if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { # beampair Earth coords |
|
297 |
$w12 = $w12_ic*$cr + $v12_ic*$sr - $v34_ic*$sp; |
|
298 |
$v12 = $v12_ic*$cr - $w12_ic*$sr + $w34_ic*$sp; |
|
299 |
$w34 = $w34_ic*$cp - $v34_ic*$sp + $v12_ic*$sr; |
|
300 |
$v34 = $v34_ic*$cp + $w34_ic*$sp - $w12_ic*$sr; |
|
301 |
} else { |
|
302 |
$w12 = $w12_ic*$cr - $v12_ic*$sr - $v34_ic*$sp; |
|
303 |
$v12 = $v12_ic*$cr + $w12_ic*$sr + $w34_ic*$sp; |
|
304 |
$w34 = $w34_ic*$cp - $v34_ic*$sp - $v12_ic*$sr; |
|
305 |
$v34 = $v34_ic*$cp + $w34_ic*$sp + $w12_ic*$sr; |
|
306 |
} |
|
307 |
||
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
308 |
$v12=$w12=undef unless (defined($b1) && defined($b2)); |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
309 |
$v34=$w34=undef unless (defined($b3) && defined($b4)); |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
310 |
|
0 | 311 |
return ($v12,$w12,$v34,$w34); |
312 |
} |
|
313 |
} |
|
314 |
||
5 | 315 |
#=================================================================== |
316 |
# velBeamToBPInstrument(@) calculates the instrument-coordinate vels |
|
317 |
# from the two beam pairs separately. |
|
318 |
#=================================================================== |
|
319 |
||
320 |
{ # STATIC SCOPE |
|
321 |
my($TwoCosBAngle,$TwoSinBAngle); |
|
322 |
||
323 |
sub velBeamToBPInstrument(@) |
|
324 |
{ |
|
325 |
my($dta,$ens,$b1,$b2,$b3,$b4) = @_; |
|
326 |
my($v12,$w12,$v34,$w34); |
|
327 |
||
18 | 328 |
return (undef,undef,undef,undef) |
329 |
unless (defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
330 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
18 | 331 |
|
5 | 332 |
unless (defined($TwoCosBAngle)) { |
333 |
$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE})); |
|
334 |
$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE})); |
|
335 |
} |
|
336 |
||
337 |
# Sign convention: |
|
338 |
# - refer to Coord manual Fig. 3 |
|
339 |
# - v12 is horizontal velocity from beam1 to beam2 |
|
340 |
# - w is +ve upward, regardless of instrument orientation |
|
341 |
||
342 |
if (defined($b1) && defined($b2)) { |
|
343 |
$v12 = ($b1-$b2)/$TwoSinBAngle; |
|
344 |
$w12 = ($b1+$b2)/$TwoCosBAngle; |
|
345 |
$w12 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
346 |
} |
|
347 |
if (defined($b3) && defined($b4)) { |
|
348 |
$v34 = ($b3-$b4)/$TwoSinBAngle; |
|
349 |
$w34 = ($b3+$b4)/$TwoCosBAngle; |
|
350 |
$w34 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
351 |
} |
|
352 |
||
353 |
return ($v12,$w12,$v34,$w34); |
|
354 |
} |
|
355 |
} |
|
356 |
||
0 | 357 |
#====================================================================== |
358 |
# velApplyHdgBias() applies the heading bias, which is used to correct |
|
359 |
# for magnetic declination for data recorded in Earth-coordinates ONLY. |
|
360 |
# Bias correction for beam-coordinate data is done in velInstrumentToEarth() |
|
361 |
#====================================================================== |
|
362 |
||
6 | 363 |
sub velApplyHdgBias(@) |
364 |
{ |
|
365 |
my($dta,$ens,$v1,$v2,$v3,$v4) = @_; |
|
18 | 366 |
return (undef,undef,undef,undef) |
367 |
unless (defined($v1) && defined($v2) && |
|
368 |
defined($dta->{ENSEMBLE}[$ens]->{HEADING})); |
|
0 | 369 |
|
6 | 370 |
my($sh) = sin(rad(-$dta->{HEADING_BIAS})); |
371 |
my($ch) = cos(rad(-$dta->{HEADING_BIAS})); |
|
0 | 372 |
|
6 | 373 |
return ( $v1*$ch + $v2*$sh, |
374 |
-$v1*$sh + $v2*$ch, |
|
375 |
$v3 , |
|
376 |
$v4 ); |
|
377 |
} |
|
0 | 378 |
|
379 |
#---------------------------------------------------------------------- |
|
380 |
# Pitch/Roll Functions |
|
381 |
#---------------------------------------------------------------------- |
|
382 |
||
383 |
sub gimbal_pitch($$) # RDI coord trans manual |
|
384 |
{ |
|
5 | 385 |
my($RDI_pitch,$RDI_roll) = @_; |
18 | 386 |
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); |
5 | 387 |
return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)))); |
0 | 388 |
} |
389 |
||
14 | 390 |
sub RDI_pitch($$) |
391 |
{ |
|
392 |
my($gimbal_pitch,$roll) = @_; |
|
18 | 393 |
return 'nan' unless defined($gimbal_pitch) && defined($roll); |
14 | 394 |
return deg(atan(tan(rad($gimbal_pitch))/cos(rad($roll)))); |
395 |
} |
|
396 |
||
397 |
sub tilt_azimuth($$) |
|
398 |
{ |
|
399 |
my($gimbal_pitch,$roll) = @_; |
|
18 | 400 |
return 'nan' unless defined($gimbal_pitch) && defined($roll); |
14 | 401 |
return angle(deg(atan2(sin(rad($gimbal_pitch)),sin(rad($roll))))); |
402 |
} |
|
403 |
||
18 | 404 |
# - angle from vertical is home grown |
0 | 405 |
# - angle between two unit vectors given by acos(v1 dot v2) |
406 |
# - vertical unit vector v1 = (0 0 1) => dot product = z-component of v2 |
|
407 |
# - when vertical unit vector is pitched in x direction, followed by |
|
408 |
# roll in y direction: |
|
409 |
# x = sin(pitch) |
|
410 |
# y = cos(pitch) * sin(roll) |
|
411 |
# z = cos(pitch) * cos(roll) |
|
412 |
# has been checked with sqrt(x^2+y^2+z^2) == 1 |
|
413 |
# - for small angles, this is very similar to sqrt(pitch^2+roll^2) |
|
414 |
||
415 |
sub angle_from_vertical($$) |
|
416 |
{ |
|
5 | 417 |
my($RDI_pitch,$RDI_roll) = @_; |
18 | 418 |
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); |
5 | 419 |
my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); |
420 |
return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); |
|
0 | 421 |
} |
422 |
||
423 |
1; |