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