author  A.M. Thurnherr <athurnherr@yahoo.com> 
Sun, 21 Oct 2018 19:52:56 0400  
changeset 43  b63fa355644c 
parent 41  d7ab920c1de6 
child 54  21cf468fa8e0 
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 

43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

4 
# dlm: Wed Mar 28 12:30:12 2018 
0  5 
# (c) 2003 A.M. Thurnherr 
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

6 
# uEInfo: 109 22 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 

43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

59 
# Mar 28, 2018:  added &loadInstrumentTransformation() 
0  60 

61 
use strict; 

62 
use POSIX; 

63 

64 
my($PI) = 3.14159265358979; 

65 

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

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

68 

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

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

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

71 
# 
0  72 

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

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

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

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

76 

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

77 
# 
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

78 
# beam to earth transformation 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

79 
#  loadInstrumentTransformation(filename) loads a file that contains the 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

80 
# output from the PS3 command, which includes the instrument transformation 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

81 
# matrix as follows: 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

82 
# Instrument Transformation Matrix (Down): Q14: 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

83 
# 1.4689 1.4682 0.0030 0.0035 24067 24055 49 58 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

84 
# 0.0036 0.0029 1.4664 1.4673 59 48 24025 24041 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

85 
# 0.2658 0.2661 0.2661 0.2657 4355 4359 4359 4354 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

86 
# 1.0373 1.0382 1.0385 1.0373 16995 17010 17015 16995 
35
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

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

88 

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

89 
$RDI_Coords::threeBeam_1 = 0; # stats from velBeamToInstrument 
0  90 
$RDI_Coords::threeBeam_2 = 0; 
91 
$RDI_Coords::threeBeam_3 = 0; 

92 
$RDI_Coords::threeBeam_4 = 0; 

93 
$RDI_Coords::fourBeam = 0; 

94 

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

96 

97 
{ # STATIC SCOPE 

98 
my(@B2I); 

99 

43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

100 
sub loadInstrumentTransformation($) 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

101 
{ 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

102 
die("loadInstrumentTransformation(): B2I matrix already defined\n") 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

103 
if (@B2I); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

104 
open(ITF,$_[0])  die("$_[0]: $!\n"); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

105 
my($row) = 0; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

106 
while (<ITF>) { 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

107 
if ($row == 0) { 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

108 
next unless m{^Instrument Transformation Matrix \(Down\):}; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

109 
$row = 1; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

110 
} elsif ($row <= 4) { 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

111 
my(@vals) = split; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

112 
die("$_[0]: cannot decode row #$row of Instrument Transformation Matrix\n") 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

113 
unless (@vals == 8); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

114 
for (my($i)=0; $i<4; $i++) { 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

115 
die("$_[0]: cannot decode row #$row of Instrument Transformation Matrix\n") 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

116 
unless numberp($vals[$i]); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

117 
$B2I[$row1][$i] = $vals[$i]; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

118 
} 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

119 
$row++; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

120 
} else { 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

121 
last; 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

122 
} 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

123 
} 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

124 
die("$_[0]: cannot decode Instrument Transformation Matrix (row = $row)\n") 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

125 
unless ($row == 5); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

126 
close(ITF); 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

127 
} 
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

128 

0  129 
sub velBeamToInstrument(@) 
130 
{ 

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

131 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
0  132 
return undef unless (defined($v1) + defined($v2) + 
133 
defined($v3) + defined($v4) 

134 
>= $RDI_Coords::minValidVels); 

135 

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

137 
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

138 
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

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

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

143 
[$b, $b, $b, $b ], 

144 
[$d, $d, $d, $d ]); 

145 
} 

146 

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

148 
$RDI_Coords::threeBeamFlag = 1; 

149 
$RDI_Coords::threeBeam_1++; 

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

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

152 
$RDI_Coords::threeBeamFlag = 1; 

153 
$RDI_Coords::threeBeam_2++; 

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

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

156 
$RDI_Coords::threeBeamFlag = 1; 

157 
$RDI_Coords::threeBeam_3++; 

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

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

160 
$RDI_Coords::threeBeamFlag = 1; 

161 
$RDI_Coords::threeBeam_4++; 

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

163 
} else { 

164 
$RDI_Coords::threeBeamFlag = 0; 

165 
$RDI_Coords::fourBeam++; 

166 
} 

167 

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

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

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

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

172 
} 

173 
} # STATIC SCOPE 

174 

43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

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

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

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

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

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

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

181 
# beta = gimball_pitch 
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

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

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

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

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

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

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

188 
# => 1cm/s error for 1m/s winch speed! 
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset

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

190 

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

193 

194 
sub velInstrumentToEarth(@) 

195 
{ 

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

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

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

200 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
0  201 

202 
unless (@I2E && 

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

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

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

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

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

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

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

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

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

213 
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

214 
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

215 
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

216 
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

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

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

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

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

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

225 
) : ( 

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

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

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

229 
); 

230 
} 

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

231 
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

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

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

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

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

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

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

238 
$v4); 
0  239 
} 
240 
} # STATIC SCOPE 

241 

32  242 

243 
sub velBeamToEarth(@) 

244 
{ 

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

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

246 
return velInstrumentToEarth($ADCP,$e,velBeamToInstrument($ADCP,$e,@v)); 
32  247 
} 
248 

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

249 

28  250 
# 
251 
# velEarthToInstrument() transforms earth to instrument coordinates 

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

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

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

255 
# the (unnecessary) derivation 
32  256 
#  code was verified for both down and uplookers 
28  257 
#  missing heading data (IMP) causes undef beam velocities 
258 
# 

259 

260 
{ # STATIC SCOPE 

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

262 

263 
sub velEarthToInstrument(@) 

264 
{ 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

28  283 
} 
284 

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

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

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

289 
$ev) 

290 
: (undef,undef,undef,undef); 

291 

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

292 
} # velEarthToIntrument() 
28  293 
} # STATIC SCOPE 
294 

295 
# 

296 
# velInstrumentToBeam() transforms instrument to beam coordinates 

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

298 
#  does not implement binremapping 

39  299 
#  returns undef for 3beam solutions, as it is not known which 
28  300 
# beam was bad 
301 
# 

302 

303 
{ # STATIC SCOPE 

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

305 

306 
sub velInstrumentToBeam(@) 

307 
{ 

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

308 
my($ADCP,$ens,$x,$y,$z,$ev) = @_; 
28  309 
return undef unless (defined($x) + defined($y) + 
310 
defined($z) + defined($ev) == 4); 

311 

312 
unless (defined($a)) { 

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

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

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

315 
$c = $ADCP>{CONVEX_BEAM_PATTERN} ? 1 : 1; 
28  316 
$d = $a / sqrt(2); 
317 
} 

318 

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

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

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

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

323 

324 
} 

325 
} # STATIC SCOPE 

326 

31  327 
# 
328 
# velEarthToBeam() combines velEarthToInstrument and velInstrumentToBeam 

329 
# 

330 

331 
sub velEarthToBeam(@) 

332 
{ 

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

333 
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

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

335 
velEarthToInstrument($ADCP,$ens,$u,$v,$w,$ev)); 
31  336 
} 
337 

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

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

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

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

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

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

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

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

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

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

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

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

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

350 
# in case of w 
39  351 
#  the commentedout version above is a "bruteforce" 
352 
# 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

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

354 

39  355 
#sub velEarthToBPw(@) 
356 
#{ 

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

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

359 
#} 

360 

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

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

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

363 
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

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

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

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

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

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

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

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

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

372 

0  373 
#====================================================================== 
5  374 
# velBeamToBPEarth(@) calculates the vertical and horizontal vels 
0  375 
# 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

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

377 
# solutions). 
0  378 
#====================================================================== 
379 

380 
{ # STATIC SCOPE 

381 
my($TwoCosBAngle,$TwoSinBAngle); 

382 

383 
sub velBeamToBPEarth(@) 

384 
{ 

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

385 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
0  386 
my($v12,$w12,$v34,$w34); 
387 

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

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

390 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  391 

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

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

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

396 
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

397 
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

398 
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

399 
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

400 
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

401 
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

402 
my($sp) = sin($rad_calc_pitch); my($cp) = cos($rad_calc_pitch); 
0  403 

404 
# Sign convention: 

405 
#  refer to Coord manual Fig. 3 

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

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

408 

41  409 
my($v12_ic,$w12_ic,$v34_ic,$w34_ic,$w_ic); 
410 

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

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

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

414 
} 

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

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

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

418 
} 

0  419 

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

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

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

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

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

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

427 
} elsif (numberp($w12_ic)) { 

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

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

430 
} elsif (numberp($w34_ic)) { 

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

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

433 
} 

434 
} else { 

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

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

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

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

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

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

441 
} elsif (numberp($w12_ic)) { 

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

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

444 
} elsif (numberp($w34_ic)) { 

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

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

447 
} 

0  448 
} 
449 

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

451 
} 

452 
} 

453 

5  454 
#=================================================================== 
455 
# velBeamToBPInstrument(@) calculates the instrumentcoordinate vels 

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

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

458 
# coordinates (instr coords with w up) 
5  459 
#=================================================================== 
460 

461 
{ # STATIC SCOPE 

462 
my($TwoCosBAngle,$TwoSinBAngle); 

463 

464 
sub velBeamToBPInstrument(@) 

465 
{ 

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

466 
my($ADCP,$ens,$b1,$b2,$b3,$b4) = @_; 
5  467 
my($v12,$w12,$v34,$w34); 
468 

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

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

471 
defined($ADCP>{ENSEMBLE}[$ens]>{ROLL})); 
18  472 

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

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

475 
$TwoSinBAngle = 2 * sin(rad($ADCP>{BEAM_ANGLE})); 
5  476 
} 
477 

478 
# Sign convention: 

479 
#  refer to Coord manual Fig. 3 

480 
#  v12 is horizontal velocity from beam1 to beam2 

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

482 

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

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

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

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

486 
$w12 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  487 
} 
488 
if (defined($b3) && defined($b4)) { 

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

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

491 
$w34 *= 1 if ($ADCP>{ENSEMBLE}[$ens]>{XDUCER_FACING_UP}); 
5  492 
} 
493 

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

495 
} 

496 
} 

497 

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

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

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

502 
#====================================================================== 

503 

6  504 
sub velApplyHdgBias(@) 
505 
{ 

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

506 
my($ADCP,$ens,$v1,$v2,$v3,$v4) = @_; 
18  507 
return (undef,undef,undef,undef) 
508 
unless (defined($v1) && defined($v2) && 

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

509 
defined($ADCP>{ENSEMBLE}[$ens]>{HEADING})); 
0  510 

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

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

512 
my($ch) = cos(rad($ADCP>{HEADING_BIAS})); 
0  513 

6  514 
return ( $v1*$ch + $v2*$sh, 
515 
$v1*$sh + $v2*$ch, 

516 
$v3 , 

517 
$v4 ); 

518 
} 

0  519 

520 
# 

521 
# Pitch/Roll Functions 

522 
# 

523 

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

525 
{ 

5  526 
my($RDI_pitch,$RDI_roll) = @_; 
18  527 
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); 
5  528 
return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)))); 
0  529 
} 
530 

14  531 
sub RDI_pitch($$) 
532 
{ 

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

18  534 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  535 
return deg(atan(tan(rad($gimbal_pitch))/cos(rad($roll)))); 
536 
} 

537 

538 
sub tilt_azimuth($$) 

539 
{ 

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

18  541 
return 'nan' unless defined($gimbal_pitch) && defined($roll); 
14  542 
return angle(deg(atan2(sin(rad($gimbal_pitch)),sin(rad($roll))))); 
543 
} 

544 

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

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

549 
# roll in y direction: 

550 
# x = sin(pitch) 

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

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

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

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

555 

556 
sub angle_from_vertical($$) 

557 
{ 

5  558 
my($RDI_pitch,$RDI_roll) = @_; 
18  559 
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); 
5  560 
my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); 
561 
return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); 

0  562 
} 
563 

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

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

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

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

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

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

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

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

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

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

575 
# b3 = phi + pitch b4 = phi  pitch 
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 

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

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

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

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

581 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

598 
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

599 
$ADCP>{BIN_LENGTH}*cos(rad($tilt))); 
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 

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

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

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

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

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

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

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

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

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

614 
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

615 

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

616 
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

617 
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

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

619 

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

620 
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

621 
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

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

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

624 
return undef unless defined($y1); 
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 
my($dz1) = $dz2bin1 + $floor_bin * $bin_dz; 
7c394a2d1fc9
before implementing 2nd order coord trans
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset

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

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

629 
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

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

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

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

633 

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

634 
sub binterp($$$$) 
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 
my($ADCP,$ens,$target_bin,$ADCP_field) = @_; 
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 
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

639 
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

640 

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

641 
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

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

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

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

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

646 

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

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

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

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

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

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

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

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

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

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

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

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

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

659 
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

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

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

662 

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

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

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

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

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

667 
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

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

669 
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

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

671 
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

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

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

674 

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

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

676 

0  677 
1; 