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