author  A.M. Thurnherr <athurnherr@yahoo.com> 
Wed, 06 Dec 2017 12:42:48 0500  
changeset 41  d7ab920c1de6 
parent 39  3bddaa514ef5 
child 43  b63fa355644c 
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 

41  4 
# dlm: Mon Nov 27 07:13:25 2017 
0  5 
# (c) 2003 A.M. Thurnherr 
41  6 
# uEInfo: 58 62 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 
39  56 
# Oct 12, 2017:  documentation 
41  57 
# Nov 26, 2017:  BUG: velBeamtoBPEarth() did not respect missing values 
58 
# Nov 27, 2017:  BUG: numbersp() from [antslib.pl] was used 

0  59 

60 
use strict; 

61 
use POSIX; 

62 

63 
my($PI) = 3.14159265358979; 

64 

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

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

67 

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

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

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

70 
# 
0  71 

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

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

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

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

75 

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

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

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

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

79 

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

80 
$RDI_Coords::threeBeam_1 = 0; # stats from velBeamToInstrument 
0  81 
$RDI_Coords::threeBeam_2 = 0; 
82 
$RDI_Coords::threeBeam_3 = 0; 

83 
$RDI_Coords::threeBeam_4 = 0; 

84 
$RDI_Coords::fourBeam = 0; 

85 

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

87 

88 
{ # STATIC SCOPE 

89 
my(@B2I); 

90 

91 
sub velBeamToInstrument(@) 

92 
{ 

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

93 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
0  94 
return undef unless (defined($v1) + defined($v2) + 
95 
defined($v3) + defined($v4) 

96 
>= $RDI_Coords::minValidVels); 

97 

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

99 
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

100 
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

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

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

105 
[$b, $b, $b, $b ], 

106 
[$d, $d, $d, $d ]); 

107 
} 

108 

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

110 
$RDI_Coords::threeBeamFlag = 1; 

111 
$RDI_Coords::threeBeam_1++; 

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

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

114 
$RDI_Coords::threeBeamFlag = 1; 

115 
$RDI_Coords::threeBeam_2++; 

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

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

118 
$RDI_Coords::threeBeamFlag = 1; 

119 
$RDI_Coords::threeBeam_3++; 

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

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

122 
$RDI_Coords::threeBeamFlag = 1; 

123 
$RDI_Coords::threeBeam_4++; 

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

125 
} else { 

126 
$RDI_Coords::threeBeamFlag = 0; 

127 
$RDI_Coords::fourBeam++; 

128 
} 

129 

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

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

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

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

134 
} 

135 
} # STATIC SCOPE 

136 

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

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

138 
# 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

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

140 
#  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

141 
#  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

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

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

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

145 
# 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

146 
#  (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

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

148 
#  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

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

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

151 
# => 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

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

153 

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

156 

157 
sub velInstrumentToEarth(@) 

158 
{ 

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

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

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

163 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
0  164 

165 
unless (@I2E && 

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

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

167 
$roll == $ADCP>{ENSEMBLE}[$ens]>{ROLL}) { 
0  168 
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

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

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

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

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

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

174 
$roll = $ADCP>{ENSEMBLE}[$ens]>{ROLL}; 
0  175 
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

176 
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

177 
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

178 
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

179 
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

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

181 
my($sp,$cp) = (sin($rad_calc_pitch),cos($rad_calc_pitch)); 
0  182 
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

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

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

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

188 
) : ( 

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

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

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

192 
); 

193 
} 

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

194 
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

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

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

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) 
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset

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

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

201 
$v4); 
0  202 
} 
203 
} # STATIC SCOPE 

204 

32  205 

206 
sub velBeamToEarth(@) 

207 
{ 

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

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

209 
return velInstrumentToEarth($ADCP,$e,velBeamToInstrument($ADCP,$e,@v)); 
32  210 
} 
211 

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

212 

28  213 
# 
214 
# velEarthToInstrument() transforms earth to instrument coordinates 

215 
#  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

216 
#  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

217 
# 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

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

222 

223 
{ # STATIC SCOPE 

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

225 

226 
sub velEarthToInstrument(@) 

227 
{ 

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

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

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

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

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

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

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

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

236 
$roll = $ADCP>{ENSEMBLE}[$ens]>{ROLL}; 
28  237 
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

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

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

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

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

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

28  246 
} 
247 

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

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

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

252 
$ev) 

253 
: (undef,undef,undef,undef); 

254 

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

255 
} # velEarthToIntrument() 
28  256 
} # STATIC SCOPE 
257 

258 
# 

259 
# velInstrumentToBeam() transforms instrument to beam coordinates 

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

261 
#  does not implement binremapping 

39  262 
#  returns undef for 3beam solutions, as it is not known which 
28  263 
# beam was bad 
264 
# 

265 

266 
{ # STATIC SCOPE 

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

268 

269 
sub velInstrumentToBeam(@) 

270 
{ 

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

271 
my($ADCP,$ens,$x,$y,$z,$ev) = @_; 
28  272 
return undef unless (defined($x) + defined($y) + 
273 
defined($z) + defined($ev) == 4); 

274 

275 
unless (defined($a)) { 

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

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

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

278 
$c = $ADCP>{CONVEX_BEAM_PATTERN} ? 1 : 1; 
28  279 
$d = $a / sqrt(2); 
280 
} 

281 

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

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

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

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

286 

287 
} 

288 
} # STATIC SCOPE 

289 

31  290 
# 
291 
# velEarthToBeam() combines velEarthToInstrument and velInstrumentToBeam 

292 
# 

293 

294 
sub velEarthToBeam(@) 

295 
{ 

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

296 
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

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

298 
velEarthToInstrument($ADCP,$ens,$u,$v,$w,$ev)); 
31  299 
} 
300 

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

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

302 
# 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

303 
#  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

304 
# 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

305 
# 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

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

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

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

309 
# 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

310 
# 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

311 
# 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

312 
# 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

313 
# in case of w 
39  314 
#  the commentedout version above is a "bruteforce" 
315 
# implementation which should give the same result 

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

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

317 

39  318 
#sub velEarthToBPw(@) 
319 
#{ 

320 
# my(@bpv) = velBeamToBPEarth(&velEarthToBeam(@_)); 

321 
# return ($bpv[1],$bpv[3]); 

322 
#} 

323 

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

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

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

326 
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

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

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

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

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

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

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

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

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

335 

0  336 
#====================================================================== 
5  337 
# velBeamToBPEarth(@) calculates the vertical and horizontal vels 
0  338 
# 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

339 
# 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

340 
# solutions). 
0  341 
#====================================================================== 
342 

343 
{ # STATIC SCOPE 

344 
my($TwoCosBAngle,$TwoSinBAngle); 

345 

346 
sub velBeamToBPEarth(@) 

347 
{ 

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

348 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
0  349 
my($v12,$w12,$v34,$w34); 
350 

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

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

353 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  354 

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

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

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

359 
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

360 
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

361 
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

362 
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

363 
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

364 
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

365 
my($sp) = sin($rad_calc_pitch); my($cp) = cos($rad_calc_pitch); 
0  366 

367 
# Sign convention: 

368 
#  refer to Coord manual Fig. 3 

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

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

371 

41  372 
my($v12_ic,$w12_ic,$v34_ic,$w34_ic,$w_ic); 
373 

374 
if (numberp($b1) && numberp($b2)) { 

375 
$v12_ic = ($b1$b2)/$TwoSinBAngle; # instrument coords... 

376 
$w12_ic = ($b1+$b2)/$TwoCosBAngle; # consistent with RDI convention 

377 
} 

378 
if (numberp($b3) && numberp($b4)) { 

379 
$v34_ic = ($b4$b3)/$TwoSinBAngle; 

380 
$w34_ic = ($b3+$b4)/$TwoCosBAngle; 

381 
} 

0  382 

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

383 
if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_DOWN}) { # beampair Earth coords 
41  384 
if (numberp($w12_ic) && numberp($w34_ic)) { 
385 
$w_ic = ($w12_ic+$w34_ic) / 2; 

386 
$v12 = $v12_ic*$cr + $v34_ic*0 + $w_ic*$sr; # Lohrman et al. (1990) A1 

387 
$v34 = $v12_ic*$sp*$sr + $v34_ic*$cp  $w_ic*$sp*$cr; #  defined for z upward => DL 

388 
$w12 =$v12_ic*$cp*$sr + $v34_ic*$sp + $w12_ic*$cp*$cr; 

389 
$w34 =$v12_ic*$cp*$sr + $v34_ic*$sp + $w34_ic*$cp*$cr; 

390 
} elsif (numberp($w12_ic)) { 

391 
$v12 = $v12_ic*$cr + $w12_ic*$sr; 

392 
$w12 =$v12_ic*$cp*$sr + $w12_ic*$cp*$cr; 

393 
} elsif (numberp($w34_ic)) { 

394 
$v34 = $v34_ic*$cp  $w34_ic*$sp*$cr; 

395 
$w34 = $v34_ic*$sp + $w34_ic*$cp*$cr; 

396 
} 

397 
} else { 

398 
if (numberp($w12_ic) && numberp($w34_ic)) { 

399 
$w_ic = ($w12_ic+$w34_ic) / 2; 

400 
$v12 =$v12_ic*$cr + $v34_ic*0  $w_ic*$sr; #  as above with 1st & 3rd cols negated 

401 
$v34 =$v12_ic*$sp*$sr + $v34_ic*$cp + $w_ic*$sp*$cr; 

402 
$w12 = $v12_ic*$cp*$sr + $v34_ic*$sp  $w12_ic*$cp*$cr; 

403 
$w34 = $v12_ic*$cp*$sr + $v34_ic*$sp  $w34_ic*$cp*$cr; 

404 
} elsif (numberp($w12_ic)) { 

405 
$v12 =$v12_ic*$cr  $w12_ic*$sr; 

406 
$w12 = $v12_ic*$cp*$sr  $w12_ic*$cp*$cr; 

407 
} elsif (numberp($w34_ic)) { 

408 
$v34 = $v34_ic*$cp + $w34_ic*$sp*$cr; 

409 
$w34 = $v34_ic*$sp  $w34_ic*$cp*$cr; 

410 
} 

0  411 
} 
412 

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

414 
} 

415 
} 

416 

5  417 
#=================================================================== 
418 
# velBeamToBPInstrument(@) calculates the instrumentcoordinate vels 

419 
# 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

420 
#  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

421 
# coordinates (instr coords with w up) 
5  422 
#=================================================================== 
423 

424 
{ # STATIC SCOPE 

425 
my($TwoCosBAngle,$TwoSinBAngle); 

426 

427 
sub velBeamToBPInstrument(@) 

428 
{ 

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

429 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
5  430 
my($v12,$w12,$v34,$w34); 
431 

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

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

434 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  435 

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

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

438 
$TwoSinBAngle = 2 * sin(rad($ADCP>{BEAM_ANGLE})); 
5  439 
} 
440 

441 
# Sign convention: 

442 
#  refer to Coord manual Fig. 3 

443 
#  v12 is horizontal velocity from beam1 to beam2 

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

445 

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

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

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

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

449 
$w12 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  450 
} 
451 
if (defined($b3) && defined($b4)) { 

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

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

454 
$w34 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  455 
} 
456 

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

458 
} 

459 
} 

460 

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

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

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

465 
#====================================================================== 

466 

6  467 
sub velApplyHdgBias(@) 
468 
{ 

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

469 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
18  470 
return (undef,undef,undef,undef) 
471 
unless (defined($v1) && defined($v2) && 

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

472 
defined($ADCP>{ENSEMBLE}[$ens]>{HEADING})); 
0  473 

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

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

475 
my($ch) = cos(rad($ADCP>{HEADING_BIAS})); 
0  476 

6  477 
return ( $v1*$ch + $v2*$sh, 
478 
$v1*$sh + $v2*$ch, 

479 
$v3 , 

480 
$v4 ); 

481 
} 

0  482 

483 
# 

484 
# Pitch/Roll Functions 

485 
# 

486 

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

488 
{ 

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

14  494 
sub RDI_pitch($$) 
495 
{ 

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

18  497 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  498 
return deg(atan(tan(rad($gimbal_pitch))/cos(rad($roll)))); 
499 
} 

500 

501 
sub tilt_azimuth($$) 

502 
{ 

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

18  504 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  505 
return angle(deg(atan2(sin(rad($gimbal_pitch)),sin(rad($roll))))); 
506 
} 

507 

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

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

512 
# roll in y direction: 

513 
# x = sin(pitch) 

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

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

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

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

518 

519 
sub angle_from_vertical($$) 

520 
{ 

5  521 
my($RDI_pitch,$RDI_roll) = @_; 
18  522 
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); 
5  523 
my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); 
524 
return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); 

0  525 
} 
526 

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

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

528 
# 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

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

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

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

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

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

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

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

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

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

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

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

540 

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

541 
sub alongBeamDZ($$$) 
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 
my($ADCP,$ens,$beam) = @_; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

544 

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

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

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

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

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

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

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

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

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

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

554 
? &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

555 
: &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

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

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

558 
? &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

559 
: &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

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

561 
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

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

563 
} 
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 
# 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

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

568 
#  field can be VELOCITY, ECHO_AMPLITUDE, ... 
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 
# 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

571 
# 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

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

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

574 

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

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

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

577 
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

578 

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

579 
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

580 
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

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

582 

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

583 
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

584 
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

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

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

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

588 

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

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

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

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

592 
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

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

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

595 
} 
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 
sub binterp($$$$) 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

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

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

600 

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

601 
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

602 
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

603 

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

604 
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

605 
&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

606 
&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

607 
&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

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

609 

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

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

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

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

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

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

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

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

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

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

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

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

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

622 
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

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

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

625 

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

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

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

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

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

630 
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

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

632 
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

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

634 
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

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

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

637 

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

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

639 

0  640 
1; 