author  A.M. Thurnherr <athurnherr@yahoo.com> 
Fri, 05 Aug 2016 10:10:28 0400  
changeset 36  515b06dae59c 
parent 35  7c394a2d1fc9 
child 39  3bddaa514ef5 
permissions  rwrr 
0  1 
#====================================================================== 
2 
# R D I _ C O O R D S . P L 

3 
# doc: Sun Jan 19 17:57:53 2003 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

4 
# dlm: Sun Jul 31 13:54:26 2016 
0  5 
# (c) 2003 A.M. Thurnherr 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

6 
# uEInfo: 568 0 NIL 0 0 72 10 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 nonzero 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 3beam 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 
# perensemble 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 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

47 
# May 25, 2016:  continued 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

48 
# May 26, 2016:  made it work 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

49 
# May 30, 2016:  begin implementing 2nd order attitude transformations 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

50 
# Jun 6, 2016:  toEarth transformation in beamToBPEarth was but crude approximation; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

51 
# updated with transformation taken from Lohrman et al. (JAOT 1990) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

52 
#  BUG: v34 sign was inconsistent with RDI coord manual 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

53 
# Jun 8, 2016:  added $ens as arg to velInstrumentToBeam() for consistency 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

54 
# Jul 7, 2016:  added velEarthToBPw() with algorithm debugged and verified 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

55 
# by Paul Wanis from TRDI 
0  56 

57 
use strict; 

58 
use POSIX; 

59 

60 
my($PI) = 3.14159265358979; 

61 

62 
sub rad(@) { return $_[0]/180 * $PI; } 

63 
sub deg(@) { return $_[0]/$PI * 180; } 

64 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

65 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

66 
# Tweakables 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

67 
# 
0  68 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

69 
$RDI_Coords::minValidVels = 3; # 3beam solutions ok (velBeamToInstrument) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

70 
$RDI_Coords::binMapping = 'linterp'; # 'linterp' or 'none' (earthVels, BPearthVels) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

71 
$RDI_Coords::beamTransformation = 'LHR90'; # set to 'RDI' to use 1st order transformations from RDI manual 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

72 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

73 
# 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

74 
# beam to earth transformation 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

75 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

76 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

77 
$RDI_Coords::threeBeam_1 = 0; # stats from velBeamToInstrument 
0  78 
$RDI_Coords::threeBeam_2 = 0; 
79 
$RDI_Coords::threeBeam_3 = 0; 

80 
$RDI_Coords::threeBeam_4 = 0; 

81 
$RDI_Coords::fourBeam = 0; 

82 

83 
$RDI_Coords::threeBeamFlag = 0; # flag last transformation 

84 

85 
{ # STATIC SCOPE 

86 
my(@B2I); 

87 

88 
sub velBeamToInstrument(@) 

89 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

90 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
0  91 
return undef unless (defined($v1) + defined($v2) + 
92 
defined($v3) + defined($v4) 

93 
>= $RDI_Coords::minValidVels); 

94 

8  95 
unless (@B2I) { 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

96 
my($a) = 1 / (2 * sin(rad($ADCP>{BEAM_ANGLE}))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

97 
my($b) = 1 / (4 * cos(rad($ADCP>{BEAM_ANGLE}))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

98 
my($c) = $ADCP>{CONVEX_BEAM_PATTERN} ? 1 : 1; 
0  99 
my($d) = $a / sqrt(2); 
100 
@B2I = ([$c*$a, $c*$a, 0, 0 ], 

101 
[0, 0, $c*$a, $c*$a], 

102 
[$b, $b, $b, $b ], 

103 
[$d, $d, $d, $d ]); 

104 
} 

105 

106 
if (!defined($v1)) { # 3beam solutions 

107 
$RDI_Coords::threeBeamFlag = 1; 

108 
$RDI_Coords::threeBeam_1++; 

109 
$v1 = ($v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][0]; 

110 
} elsif (!defined($v2)) { 

111 
$RDI_Coords::threeBeamFlag = 1; 

112 
$RDI_Coords::threeBeam_2++; 

113 
$v2 = ($v1*$B2I[3][0]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][1]; 

114 
} elsif (!defined($v3)) { 

115 
$RDI_Coords::threeBeamFlag = 1; 

116 
$RDI_Coords::threeBeam_3++; 

117 
$v3 = ($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v4*$B2I[3][3])/$B2I[3][2]; 

118 
} elsif (!defined($v4)) { 

119 
$RDI_Coords::threeBeamFlag = 1; 

120 
$RDI_Coords::threeBeam_4++; 

121 
$v4 = ($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2])/$B2I[3][3]; 

122 
} else { 

123 
$RDI_Coords::threeBeamFlag = 0; 

124 
$RDI_Coords::fourBeam++; 

125 
} 

126 

127 
return ($v1*$B2I[0][0]+$v2*$B2I[0][1], 

128 
$v3*$B2I[1][2]+$v4*$B2I[1][3], 

129 
$v1*$B2I[2][0]+$v2*$B2I[2][1]+$v3*$B2I[2][2]+$v4*$B2I[2][3], 

130 
$v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3]); 

131 
} 

132 
} # STATIC SCOPE 

133 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

134 
# 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

135 
# velInstrumentToEarth(\%ADCP,ens,v1,v2,v3,v4) => (u,v,w,e) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

136 
#  $RDI_Coords::beamTransformation = 'LHR90' 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

137 
#  from Lohrmann, Hackett & Roet (J. Tech., 1990) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

138 
#  eq A1 maps to RDI matrix M (sec 5.6) with 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

139 
# alpha = roll 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

140 
# beta = gimball_pitch 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

141 
# psi = calculation_pitch 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

142 
# psi = asin{sin(beta) cos(alpha) / sqrt[1 sin(alpha)^2 sin(beta)^2]} 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

143 
#  (I only checked for 0 heading, but this is sufficient) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

144 
#  $RDI_Coords::beamTransformation = 'RDI' 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

145 
#  default prior to LADCP_w V1.3 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

146 
#  from RDI manual 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

147 
#  99% accurate for p/r<8deg 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

148 
# => 1cm/s error for 1m/s winch speed! 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

149 
# 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

150 

0  151 
{ # STATIC SCOPE 
152 
my($hdg,$pitch,$roll,@I2E); 

153 

154 
sub velInstrumentToEarth(@) 

155 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

156 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
0  157 
return undef unless (defined($v1) && defined($v2) && 
18  158 
defined($v3) && defined($v4) && 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

159 
defined($ADCP>{ENSEMBLE}[$ens]>{PITCH}) && 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

160 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
0  161 

162 
unless (@I2E && 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

163 
$pitch == $ADCP>{ENSEMBLE}[$ens]>{PITCH} && 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

164 
$roll == $ADCP>{ENSEMBLE}[$ens]>{ROLL}) { 
0  165 
printf(STDERR "$0: warning HEADING_ALIGNMENT == %g ignored\n", 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

166 
$ADCP>{HEADING_ALIGNMENT}) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

167 
if ($ADCP>{HEADING_ALIGNMENT}); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

168 
$hdg = $ADCP>{ENSEMBLE}[$ens]>{HEADING}  $ADCP>{HEADING_BIAS} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

169 
if defined($ADCP>{ENSEMBLE}[$ens]>{HEADING}); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

170 
$pitch = $ADCP>{ENSEMBLE}[$ens]>{PITCH}; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

171 
$roll = $ADCP>{ENSEMBLE}[$ens]>{ROLL}; 
0  172 
my($rad_gimbal_pitch) = atan(tan(rad($pitch)) * cos(rad($roll))); 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

173 
my($rad_calc_pitch) = ($RDI_Coords::beamTransformation eq 'RDI') ? $rad_gimbal_pitch : 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

174 
asin(sin($rad_gimbal_pitch)*cos(rad($roll)) / 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

175 
sqrt(1sin(rad($roll))**2*sin($rad_gimbal_pitch)**2)); 
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset

176 
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

177 
if defined($hdg); 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

178 
my($sp,$cp) = (sin($rad_calc_pitch),cos($rad_calc_pitch)); 
0  179 
my($sr,$cr) = (sin(rad($roll)), cos(rad($roll))); 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

180 
@I2E = $ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP} 
0  181 
? ( 
182 
[$ch*$cr$sh*$sp*$sr, $sh*$cp,$ch*$sr+$sh*$sp*$cr], 

183 
[$ch*$sp*$sr+$sh*$cr, $ch*$cp, $sh*$sr+$ch*$sp*$cr], 

184 
[+$cp*$sr, $sp, $cp*$cr, ], 

185 
) : ( 

186 
[$ch*$cr+$sh*$sp*$sr, $sh*$cp, $ch*$sr$sh*$sp*$cr], 

187 
[$ch*$sp*$sr$sh*$cr, $ch*$cp,$sh*$sr$ch*$sp*$cr], 

188 
[$cp*$sr, $sp, $cp*$cr, ], 

189 
); 

190 
} 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

191 
return defined($ADCP>{ENSEMBLE}[$ens]>{HEADING}) 
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset

192 
? ($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

193 
$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

194 
$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

195 
$v4) 
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset

196 
: (undef,undef, 
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset

197 
$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

198 
$v4); 
0  199 
} 
200 
} # STATIC SCOPE 

201 

32  202 

203 
sub velBeamToEarth(@) 

204 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

205 
my($ADCP,$e,@v) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

206 
return velInstrumentToEarth($ADCP,$e,velBeamToInstrument($ADCP,$e,@v)); 
32  207 
} 
208 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

209 

28  210 
# 
211 
# velEarthToInstrument() transforms earth to instrument coordinates 

212 
#  based on manually inverted rotation matrix M (Sec 5.6 in coordtrans manual) 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

213 
#  Paul Wanis from TRDI pointed out that M is orthonormal, which 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

214 
# implies that M^1 = M' (where M' is the transpose), confirming 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

215 
# the (unnecessary) derivation 
32  216 
#  code was verified for both down and uplookers 
28  217 
#  missing heading data (IMP) causes undef beam velocities 
218 
# 

219 

220 
{ # STATIC SCOPE 

221 
my($hdg,$pitch,$roll,@E2I); 

222 

223 
sub velEarthToInstrument(@) 

224 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

225 
my($ADCP,$ens,$u,$v,$w,$ev) = @_; 
28  226 

32  227 
unless (@E2I && 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

228 
$pitch == $ADCP>{ENSEMBLE}[$ens]>{PITCH} && 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

229 
$roll == $ADCP>{ENSEMBLE}[$ens]>{ROLL}) { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

230 
$hdg = $ADCP>{ENSEMBLE}[$ens]>{HEADING}  $ADCP>{HEADING_BIAS} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

231 
if defined($ADCP>{ENSEMBLE}[$ens]>{HEADING}); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

232 
$pitch = $ADCP>{ENSEMBLE}[$ens]>{PITCH}; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

233 
$roll = $ADCP>{ENSEMBLE}[$ens]>{ROLL}; 
28  234 
my($rad_gimbal_pitch) = atan(tan(rad($pitch)) * cos(rad($roll))); 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

235 
my($useRoll) = ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}) ? $roll+180 : $roll; 
28  236 
my($sh,$ch) = (sin(rad($hdg)),cos(rad($hdg))) 
237 
if defined($hdg); 

238 
my($sp,$cp) = (sin($rad_gimbal_pitch),cos($rad_gimbal_pitch)); 

32  239 
my($sr,$cr) = (sin(rad($useRoll)), cos(rad($useRoll))); 
240 
@E2I = ([$ch*$cr+$sh*$sp*$sr, $ch*$sp*$sr$sh*$cr, $cp*$sr], # M^1 = R^1 * P^1 * R^1 

241 
[$sh*$cp, $ch*$cp, $sp ], 

242 
[$ch*$sr$sh*$sp*$cr, $sh*$sr$ch*$sp*$cr, $cp*$cr]); 

28  243 
} 
244 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

245 
return defined($ADCP>{ENSEMBLE}[$ens]>{HEADING}) 
28  246 
? ($u*$E2I[0][0]+$v*$E2I[0][1]+$w*$E2I[0][2], 
247 
$u*$E2I[1][0]+$v*$E2I[1][1]+$w*$E2I[1][2], 

248 
$u*$E2I[2][0]+$v*$E2I[2][1]+$w*$E2I[2][2], 

249 
$ev) 

250 
: (undef,undef,undef,undef); 

251 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

252 
} # velEarthToIntrument() 
28  253 
} # STATIC SCOPE 
254 

255 
# 

256 
# velInstrumentToBeam() transforms instrument to beam coordinates 

257 
#  based on manually solved eq system in sec 5.3 of coord manual 

258 
#  does not implement binremapping 

259 
#  does not work for 3beam solutions, as it is not known which 

260 
# beam was bad 

261 
# 

262 

263 
{ # STATIC SCOPE 

264 
my($a,$b,$c,$d); 

265 

266 
sub velInstrumentToBeam(@) 

267 
{ 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

268 
my($ADCP,$ens,$x,$y,$z,$ev) = @_; 
28  269 
return undef unless (defined($x) + defined($y) + 
270 
defined($z) + defined($ev) == 4); 

271 

272 
unless (defined($a)) { 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

273 
$a = 1 / (2 * sin(rad($ADCP>{BEAM_ANGLE}))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

274 
$b = 1 / (4 * cos(rad($ADCP>{BEAM_ANGLE}))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

275 
$c = $ADCP>{CONVEX_BEAM_PATTERN} ? 1 : 1; 
28  276 
$d = $a / sqrt(2); 
277 
} 

278 

279 
return ( $x/(2*$a*$c) + $z/(4*$b) + $ev/(4*$d), 

280 
$x/(2*$a*$c) + $z/(4*$b) + $ev/(4*$d), 

281 
$y/(2*$a*$c) + $z/(4*$b)  $ev/(4*$d), 

282 
$y/(2*$a*$c) + $z/(4*$b)  $ev/(4*$d)); 

283 

284 
} 

285 
} # STATIC SCOPE 

286 

31  287 
# 
288 
# velEarthToBeam() combines velEarthToInstrument and velInstrumentToBeam 

289 
# 

290 

291 
sub velEarthToBeam(@) 

292 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

293 
my($ADCP,$ens,$u,$v,$w,$ev) = @_; 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

294 
return velInstrumentToBeam($ADCP,$ens, 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

295 
velEarthToInstrument($ADCP,$ens,$u,$v,$w,$ev)); 
31  296 
} 
297 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

298 
# 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

299 
# velEarthToBPw() returns w12 and w34 for beamcoordinate data 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

300 
#  I am grateful for Paul Wanis from TRDI who corrected a 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

301 
# bug in my transformation (fixed in V1.3). [The bug did not 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

302 
# affect the final w profiles significantly, because w12 and w34 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

303 
# are used only as diagnostics.] 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

304 
#  algorithm: 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

305 
# 1) rotate into instrument coordinates 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

306 
# 2) w12 = w + e*tan(beam_angle)/sqrt(2) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

307 
# w34 = w  e*tan(beam_angle)/sqrt(2) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

308 
# 3) rotate into horizontal coords (earth coords w/o 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

309 
# considering heading, i.e. same as earth coords 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

310 
# in case of w 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

311 
# 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

312 

515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

313 
sub velEarthToBPw(@) 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

314 
{ 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

315 
my($ADCP,$ens,$u,$v,$w,$ev) = @_; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

316 
my(@iv) = velEarthToInstrument(@_); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

317 
my(@iv12) = my(@iv34) = @iv; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

318 
$iv12[2] += $iv[3] * tan(rad($ADCP>{BEAM_ANGLE}))/sqrt(2); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

319 
$iv34[2] = $iv[3] * tan(rad($ADCP>{BEAM_ANGLE}))/sqrt(2); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

320 
my(@ev12) = velInstrumentToEarth($ADCP,$ens,@iv12); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

321 
my(@ev34) = velInstrumentToEarth($ADCP,$ens,@iv34); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

322 
return ($ev12[2],$ev34[2]); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

323 
} 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

324 

0  325 
#====================================================================== 
5  326 
# velBeamToBPEarth(@) calculates the vertical and horizontal vels 
0  327 
# from the two beam pairs separately. Note that (w1+w2)/2 is 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

328 
# identical to the w estimated according to RDI (ignoring 3beam 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

329 
# solutions). 
0  330 
#====================================================================== 
331 

332 
{ # STATIC SCOPE 

333 
my($TwoCosBAngle,$TwoSinBAngle); 

334 

335 
sub velBeamToBPEarth(@) 

336 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

337 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
0  338 
my($v12,$w12,$v34,$w34); 
339 

18  340 
return (undef,undef,undef,undef) 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

341 
unless (defined($ADCP>{ENSEMBLE}[$ens]>{PITCH}) && 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

342 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  343 

0  344 
unless (defined($TwoCosBAngle)) { 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

345 
$TwoCosBAngle = 2 * cos(rad($ADCP>{BEAM_ANGLE})); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

346 
$TwoSinBAngle = 2 * sin(rad($ADCP>{BEAM_ANGLE})); 
0  347 
} 
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

348 
my($rad_roll) = rad($ADCP>{ENSEMBLE}[$ens]>{ROLL}); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

349 
my($sr) = sin($rad_roll); my($cr) = cos($rad_roll); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

350 
my($rad_gimbal_pitch) = atan(tan(rad($ADCP>{ENSEMBLE}[$ens]>{PITCH})) * $cr); # gimbal pitch 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

351 
my($rad_calc_pitch) = ($RDI_Coords::beamTransformation eq 'RDI') ? $rad_gimbal_pitch : 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

352 
asin(sin($rad_gimbal_pitch)*cos($rad_roll) / 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

353 
sqrt(1sin($rad_roll)**2*sin($rad_gimbal_pitch)**2)); 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

354 
my($sp) = sin($rad_calc_pitch); my($cp) = cos($rad_calc_pitch); 
0  355 

356 
# Sign convention: 

357 
#  refer to Coord manual Fig. 3 

358 
#  v12 is horizontal velocity from beam1 to beam2, i.e. westward for upwardlooking ADCP 

359 
# with beam 3 pointing north (heading = 0) 

360 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

361 
my($v12_ic) = ($b1$b2)/$TwoSinBAngle; # instrument coords 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

362 
my($v34_ic) = ($b4$b3)/$TwoSinBAngle; # consistent with RDI Coords 
0  363 
my($w12_ic) = ($b1+$b2)/$TwoCosBAngle; 
364 
my($w34_ic) = ($b3+$b4)/$TwoCosBAngle; 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

365 
my($w_ic) = ($w12_ic+$w34_ic) / 2; 
0  366 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

367 
if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_DOWN}) { # beampair Earth coords 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

368 
$v12 = $v12_ic*$cr + $v34_ic*0 + $w_ic*$sr; # Lohrman et al. (1990) A1 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

369 
$v34 = $v12_ic*$sp*$sr + $v34_ic*$cp  $w_ic*$sp*$cr; #  defined for z upward => DL 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

370 
$w12 =$v12_ic*$cp*$sr + $v34_ic*$sp + $w12_ic*$cp*$cr; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

371 
$w34 =$v12_ic*$cp*$sr + $v34_ic*$sp + $w34_ic*$cp*$cr; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

372 
} else { # RDI Coord trans manual 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

373 
$v12 =$v12_ic*$cr + $v34_ic*0  $w_ic*$sr; #  as above with 1st & 3rd cols negated 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

374 
$v34 =$v12_ic*$sp*$sr + $v34_ic*$cp + $w_ic*$sp*$cr; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

375 
$w12 = $v12_ic*$cp*$sr + $v34_ic*$sp  $w12_ic*$cp*$cr; 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

376 
$w34 = $v12_ic*$cp*$sr + $v34_ic*$sp  $w34_ic*$cp*$cr; 
0  377 
} 
378 

13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset

379 
$v12=$w12=undef unless (defined($b1) && defined($b2)); 
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset

380 
$v34=$w34=undef unless (defined($b3) && defined($b4)); 
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset

381 

0  382 
return ($v12,$w12,$v34,$w34); 
383 
} 

384 
} 

385 

5  386 
#=================================================================== 
387 
# velBeamToBPInstrument(@) calculates the instrumentcoordinate vels 

388 
# from the two beam pairs separately. 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

389 
#  in spite of the function name, the output is in ship 
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

390 
# coordinates (instr coords with w up) 
5  391 
#=================================================================== 
392 

393 
{ # STATIC SCOPE 

394 
my($TwoCosBAngle,$TwoSinBAngle); 

395 

396 
sub velBeamToBPInstrument(@) 

397 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

398 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
5  399 
my($v12,$w12,$v34,$w34); 
400 

18  401 
return (undef,undef,undef,undef) 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

402 
unless (defined($ADCP>{ENSEMBLE}[$ens]>{PITCH}) && 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

403 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  404 

5  405 
unless (defined($TwoCosBAngle)) { 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

406 
$TwoCosBAngle = 2 * cos(rad($ADCP>{BEAM_ANGLE})); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

407 
$TwoSinBAngle = 2 * sin(rad($ADCP>{BEAM_ANGLE})); 
5  408 
} 
409 

410 
# Sign convention: 

411 
#  refer to Coord manual Fig. 3 

412 
#  v12 is horizontal velocity from beam1 to beam2 

413 
#  w is +ve upward, regardless of instrument orientation 

414 

415 
if (defined($b1) && defined($b2)) { 

416 
$v12 = ($b1$b2)/$TwoSinBAngle; 

417 
$w12 = ($b1+$b2)/$TwoCosBAngle; 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

418 
$w12 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  419 
} 
420 
if (defined($b3) && defined($b4)) { 

36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
35
diff
changeset

421 
$v34 = ($b4$b3)/$TwoSinBAngle; 
5  422 
$w34 = ($b3+$b4)/$TwoCosBAngle; 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

423 
$w34 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  424 
} 
425 

426 
return ($v12,$w12,$v34,$w34); 

427 
} 

428 
} 

429 

0  430 
#====================================================================== 
431 
# velApplyHdgBias() applies the heading bias, which is used to correct 

432 
# for magnetic declination for data recorded in Earthcoordinates ONLY. 

433 
# Bias correction for beamcoordinate data is done in velInstrumentToEarth() 

434 
#====================================================================== 

435 

6  436 
sub velApplyHdgBias(@) 
437 
{ 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

438 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
18  439 
return (undef,undef,undef,undef) 
440 
unless (defined($v1) && defined($v2) && 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

441 
defined($ADCP>{ENSEMBLE}[$ens]>{HEADING})); 
0  442 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

443 
my($sh) = sin(rad($ADCP>{HEADING_BIAS})); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

444 
my($ch) = cos(rad($ADCP>{HEADING_BIAS})); 
0  445 

6  446 
return ( $v1*$ch + $v2*$sh, 
447 
$v1*$sh + $v2*$ch, 

448 
$v3 , 

449 
$v4 ); 

450 
} 

0  451 

452 
# 

453 
# Pitch/Roll Functions 

454 
# 

455 

456 
sub gimbal_pitch($$) # RDI coord trans manual 

457 
{ 

5  458 
my($RDI_pitch,$RDI_roll) = @_; 
18  459 
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); 
5  460 
return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)))); 
0  461 
} 
462 

14  463 
sub RDI_pitch($$) 
464 
{ 

465 
my($gimbal_pitch,$roll) = @_; 

18  466 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  467 
return deg(atan(tan(rad($gimbal_pitch))/cos(rad($roll)))); 
468 
} 

469 

470 
sub tilt_azimuth($$) 

471 
{ 

472 
my($gimbal_pitch,$roll) = @_; 

18  473 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  474 
return angle(deg(atan2(sin(rad($gimbal_pitch)),sin(rad($roll))))); 
475 
} 

476 

18  477 
#  angle from vertical is home grown 
0  478 
#  angle between two unit vectors given by acos(v1 dot v2) 
479 
#  vertical unit vector v1 = (0 0 1) => dot product = zcomponent of v2 

480 
#  when vertical unit vector is pitched in x direction, followed by 

481 
# roll in y direction: 

482 
# x = sin(pitch) 

483 
# y = cos(pitch) * sin(roll) 

484 
# z = cos(pitch) * cos(roll) 

485 
# has been checked with sqrt(x^2+y^2+z^2) == 1 

486 
#  for small angles, this is very similar to sqrt(pitch^2+roll^2) 

487 

488 
sub angle_from_vertical($$) 

489 
{ 

5  490 
my($RDI_pitch,$RDI_roll) = @_; 
18  491 
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); 
5  492 
my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); 
493 
return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); 

0  494 
} 
495 

35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

496 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

497 
# alongBeamDZ(ADCP_dta,ens,beam) => (dz_to_bin1_center,bin_dz) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

498 
#  calculate vertical distances: 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

499 
#  between transducer and bin1 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

500 
#  between adjacent bins 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

501 
#  no soundspeed correction 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

502 
#  for UL (Fig. 3 Coord Manual): 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

503 
# b1 = phi + roll b2 = phi  roll 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

504 
# b3 = phi  pitch b4 = phi + pitch 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

505 
#  for DL: 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

506 
# b1 = phi + roll b2 = phi  roll 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

507 
# b3 = phi + pitch b4 = phi  pitch 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

508 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

509 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

510 
sub alongBeamDZ($$$) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

511 
{ 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

512 
my($ADCP,$ens,$beam) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

513 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

514 
my($tilt); # determine tilt of given beam 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

515 
my($pitch) = $ADCP>{ENSEMBLE}[$ens]>{PITCH}; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

516 
my($roll) = $ADCP>{ENSEMBLE}[$ens]>{ROLL}; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

517 
if ($beam == 0) { # beam 1 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

518 
$tilt = &angle_from_vertical($pitch,$ADCP>{BEAM_ANGLE}+$roll); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

519 
} elsif ($beam == 1) { # beam 2 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

520 
$tilt = &angle_from_vertical($pitch,$ADCP>{BEAM_ANGLE}$roll); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

521 
} elsif ($beam == 2) { # beam 3 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

522 
$tilt = $ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

523 
? &angle_from_vertical($ADCP>{BEAM_ANGLE}$pitch,$roll) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

524 
: &angle_from_vertical($ADCP>{BEAM_ANGLE}+$pitch,$roll); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

525 
} else { # beam 4 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

526 
$tilt = $ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

527 
? &angle_from_vertical($ADCP>{BEAM_ANGLE}+$pitch,$roll) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

528 
: &angle_from_vertical($ADCP>{BEAM_ANGLE}$pitch,$roll); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

529 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

530 
return ($ADCP>{DISTANCE_TO_BIN1_CENTER}*cos(rad($tilt)), 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

531 
$ADCP>{BIN_LENGTH}*cos(rad($tilt))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

532 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

533 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

534 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

535 
# binterp(ADCP_dta,ens,bin,ADCP_field) => @interpolated_vals 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

536 
#  interpolate beam velocities to nominal bin center 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

537 
#  field can be VELOCITY, ECHO_AMPLITUDE, ... 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

538 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

539 
# earthVels(ADCP_dta,ens,bin) => (u,v,w,err_vel) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

540 
# BPEarthVels(ADCP_dta,ens,bin) => (v12,w12,v34,w34) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

541 
#  new interface (V1.7) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

542 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

543 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

544 
sub binterp1($$$$$) # interpolate along a single beam 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

545 
{ 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

546 
my($ADCP,$ens,$target_dz,$ADCP_field,$beam) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

547 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

548 
my($dz2bin1,$bin_dz) = &alongBeamDZ($ADCP,$ens,$beam); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

549 
my($floor_bin) = int(($target_dz$dz2bin1) / $bin_dz); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

550 
$floor_bin if ($floor_bin == $ADCP>{N_BINS}1); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

551 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

552 
my($y1) = $ADCP>{ENSEMBLE}[$ens]>{$ADCP_field}[$floor_bin][$beam]; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

553 
my($y2) = $ADCP>{ENSEMBLE}[$ens]>{$ADCP_field}[$floor_bin+1][$beam]; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

554 
$y2 = $y1 unless defined($y2); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

555 
$y1 = $y2 unless defined($y1); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

556 
return undef unless defined($y1); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

557 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

558 
my($dz1) = $dz2bin1 + $floor_bin * $bin_dz; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

559 
my($dz2) = $dz1 + $bin_dz; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

560 
my($ifac) = ($target_dz  $dz1) / ($dz2  $dz1); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

561 
die("assertion failed\nifac = $ifac (target_dz = $target_dz, dz1 = $dz1, dz2 = $dz2)") 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

562 
unless ($ifac>= 0.5 && $ifac<=2); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

563 
return $y1 + $ifac*($y2$y1); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

564 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

565 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

566 
sub binterp($$$$) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

567 
{ 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

568 
my($ADCP,$ens,$target_bin,$ADCP_field) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

569 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

570 
my($crt) = cos(rad($ADCP>{ENSEMBLE}[$ens]>{TILT})); # calc center depth of target bin 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

571 
my($target_dz) = ($ADCP>{DISTANCE_TO_BIN1_CENTER} + $target_bin*$ADCP>{BIN_LENGTH}) * $crt; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

572 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

573 
return (&binterp1($ADCP,$ens,$target_dz,$ADCP_field,0), # interpolate all four beams 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

574 
&binterp1($ADCP,$ens,$target_dz,$ADCP_field,1), 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

575 
&binterp1($ADCP,$ens,$target_dz,$ADCP_field,2), 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

576 
&binterp1($ADCP,$ens,$target_dz,$ADCP_field,3)); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

577 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

578 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

579 
sub earthVels($$$) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

580 
{ 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

581 
my($ADCP,$ens,$bin) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

582 
if ($RDI_Coords::binMapping eq 'linterp') { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

583 
return velInstrumentToEarth($ADCP,$ens, 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

584 
velBeamToInstrument($ADCP,$ens, 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

585 
binterp($ADCP,$ens,$bin,'VELOCITY'))); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

586 
} elsif ($RDI_Coords::binMapping eq 'none') { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

587 
return velInstrumentToEarth($ADCP,$ens, 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

588 
velBeamToInstrument($ADCP,$ens, 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

589 
@{$ADCP>{ENSEMBLE}[$ens]>{VELOCITY}[$bin]})); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

590 
} else { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

591 
die("earthVels(): unknown bin mapping '$RDI_Coords::binMapping '\n"); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

592 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

593 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

594 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

595 
sub BPEarthVels($$$) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

596 
{ 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

597 
my($ADCP,$ens,$bin) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

598 
if ($RDI_Coords::binMapping eq 'linterp') { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

599 
return velBeamToBPEarth($ADCP,$ens,binterp($ADCP,$ens,$bin,'VELOCITY')); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

600 
} elsif ($RDI_Coords::binMapping eq 'none') { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

601 
return velBeamToBPEarth($ADCP,$ens,@{$ADCP>{ENSEMBLE}[$ens]>{VELOCITY}[$bin]}); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

602 
} else { 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

603 
die("BPEarthVels(): unknown bin mapping '$RDI_Coords::binMapping '\n"); 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

604 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

605 
} 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

606 

7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

607 
# 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

608 

0  609 
1; 