author | A.M. Thurnherr <athurnherr@yahoo.com> |
Mon, 25 Nov 2013 17:27:35 +0000 | |
changeset 13 | b176da8559b3 |
parent 12 | 0f89b1523648 |
child 14 | 8c79b38a7086 |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# R D I _ U T I L S . P L |
|
3 |
# doc: Wed Feb 12 10:21:32 2003 |
|
12 | 4 |
# dlm: Thu Jun 20 15:26:47 2013 |
0 | 5 |
# (c) 2003 A.M. Thurnherr |
12 | 6 |
# uE-Info: 125 0 NIL 0 0 72 2 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# miscellaneous RDI-specific utilities |
|
10 |
||
11 |
# History: |
|
12 |
# Feb 12, 2003: - created |
|
13 |
# Feb 14, 2003: - added check for short (bad) data files |
|
14 |
# Feb 26, 2004: - added Earth-coordinate support |
|
15 |
# - added ensure_BT_RANGE() |
|
16 |
# Mar 17, 2004: - set bad BT ranges to undef in ensure_BT_RANGE |
|
17 |
# - calc mean/stddev in ensure_BT_RANGE |
|
18 |
# Mar 20, 2004: - BUG: find_seabed() could bomb when not enough |
|
19 |
# bottom guesses passed the mode_width test |
|
20 |
# Mar 30, 2004: - added &soundSpeed() |
|
21 |
# Nov 8, 2005: - WATER_DEPTH => Z_BT |
|
22 |
# Dec 1, 2005: - renamed to RDI_Utils.pl |
|
23 |
# - folded in mk_prof from [mkProfile] |
|
24 |
# Nov 30, 2007: - adapted ref_lr_w() to 3-beam solutions |
|
25 |
# Feb 1, 2008: - added comment |
|
26 |
# Feb 22, 2008: - added ssCorr() |
|
27 |
# Apr 9, 2008: - BUG: duplicate line of code (without effect) in find_seabed() |
|
28 |
# - BUG: seabed < max depth was possible |
|
29 |
# Jan 2010: - fiddled with seabed detection params (no conclusion) |
|
30 |
# May 23, 2010: - renamed Z to DEPTH |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
31 |
# Sep 27, 2010: - made sure coord flags are changed correctly when data |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
32 |
# are transferred to earth coords in mk_prof |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
33 |
# Sep 29, 2010: - BUG: previous change was wrong, as ref_lr_w does |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
34 |
# not overwrite velocities |
3 | 35 |
# Oct 20, 2010: - BUG: w is now not integrated any more across gaps longer than 5s |
36 |
# Dec 8, 2010: - changed missing w warning to happen only if gap is longer than 15s |
|
37 |
# Dec 10, 2010: - beautified gap warning |
|
5 | 38 |
# Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile |
6 | 39 |
# May 12, 2011: - added code to skip ensembles with built-in-test errors in mk_prof() |
40 |
# - immediately disabled this code becasue it does appear to make matters worse |
|
8 | 41 |
# Sep 21, 2011: - added calculation of RMS heave acceleration |
10 | 42 |
# Mar 27, 2013: - BUG: 3-beam solutions were not used in ref_lr_w |
43 |
# - disabled apparently unused code |
|
11 | 44 |
# Apr 12, 2013: - added $min_pctg as optional parameter to mk_prof |
12 | 45 |
# May 14, 2013: - added incident-velocity, w12 & w34 to mkProfile |
46 |
# Jun 5, 2013: - BUG: incident-flow warning was printed repeatedly |
|
47 |
# Jun 20, 2013: - BUG: warning had used &antsInfo() |
|
0 | 48 |
|
49 |
use strict; |
|
50 |
||
51 |
#====================================================================== |
|
52 |
# fake_BT_RANGE(dta ptr) |
|
53 |
#====================================================================== |
|
54 |
||
55 |
# During cruise NBP0204 it was found that one of Visbeck's RDIs consistently |
|
56 |
# returns zero as the bottom-track range, even thought the BT velocities |
|
57 |
# are good. This functions calculates the ranges if they are missing. |
|
58 |
||
59 |
sub cBTR($$$) |
|
60 |
{ |
|
61 |
my($d,$e,$b) = @_; |
|
62 |
my($maxamp) = -9e99; |
|
63 |
my($maxi); |
|
64 |
||
65 |
for (my($i)=0; $i<$d->{N_BINS}; $i++) { |
|
66 |
next unless ($d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b] > $maxamp); |
|
67 |
$maxamp = $d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b]; |
|
68 |
$maxi = $i; |
|
69 |
} |
|
70 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = |
|
71 |
$d->{DISTANCE_TO_BIN1_CENTER} + $maxi * $d->{BIN_LENGTH}; |
|
72 |
} |
|
73 |
||
74 |
sub ensure_BT_RANGE($) |
|
75 |
{ |
|
76 |
my($d) = @_; |
|
77 |
for (my($e)=0; $e<=$#{$d->{ENSEMBLE}}; $e++) { |
|
78 |
my($sum) = my($n) = 0; |
|
79 |
if (defined($d->{ENSEMBLE}[$e]->{BT_VELOCITY}[0])) { |
|
80 |
for (my($b)=0; $b<4; $b++) { |
|
81 |
cBTR($d,$e,$b) |
|
82 |
unless defined($d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]); |
|
83 |
$sum += $d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]; $n++; |
|
84 |
} |
|
85 |
} else { |
|
86 |
for (my($b)=0; $b<4; $b++) { |
|
87 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = undef; |
|
88 |
} |
|
89 |
} |
|
90 |
$d->{ENSEMBLE}[$e]->{BT_MEAN_RANGE} = $sum/$n if ($n == 4); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
#====================================================================== |
|
95 |
# (seabed depth, stddev) = find_seabed(dta ptr, btm ensno, coord flag) |
|
96 |
#====================================================================== |
|
97 |
||
98 |
# NOTE FOR YOYOS: |
|
99 |
# - this routine only detects the BT around the depeest depth! |
|
100 |
# - this is on purpose, because it is used for [listBT] |
|
101 |
||
102 |
# This is a PAIN: |
|
103 |
# if the instrument is too close to the bottom, the BT_RANGE |
|
104 |
# readings are all out; the only solution is to have a sufficiently |
|
105 |
# large search width (around the max(depth) ensemble) so that |
|
106 |
# a part of the up (oops, I forgot to finish this comment one year |
|
107 |
# ago during A0304 and now I don't understand it any more :-) |
|
108 |
||
109 |
my($search_width) = 200; # # of ensembles around bottom to search |
|
110 |
my($mode_width) = 10; # max range of bottom around mode |
|
111 |
my($min_dist) = 20; # min dist to seabed for good data |
|
112 |
my($z_offset) = 10000; # shift z to ensure +ve array indices |
|
113 |
||
114 |
sub find_seabed($$$) |
|
115 |
{ |
|
116 |
my($d,$be,$beamCoords) = @_; |
|
117 |
my($i,$dd,$sd,$nd); |
|
118 |
my(@guesses); |
|
119 |
||
120 |
return undef unless ($be-$search_width >= 0 && |
|
121 |
$be+$search_width <= $#{$d->{ENSEMBLE}}); |
|
122 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
123 |
next unless (defined($d->{ENSEMBLE}[$i]->{DEPTH}) && |
|
124 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[0]) && |
|
125 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[1]) && |
|
126 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[2]) && |
|
127 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[3])); |
|
128 |
my(@BT) = $beamCoords |
|
129 |
? velInstrumentToEarth($d,$i, |
|
130 |
velBeamToInstrument($d, |
|
131 |
@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}})) |
|
132 |
: velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}); |
|
133 |
next unless (abs($BT[3]) < 0.05); |
|
134 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} = |
|
135 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[0]/4 + |
|
136 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[1]/4 + |
|
137 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[2]/4 + |
|
138 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[3]/4; |
|
139 |
next unless ($d->{ENSEMBLE}[$i]->{DEPTH_BT} >= $min_dist); |
|
140 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} *= -1 |
|
141 |
if ($d->{ENSEMBLE}[$i]->{XDUCER_FACING_UP}); |
|
142 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} += $d->{ENSEMBLE}[$i]->{DEPTH}; |
|
143 |
if ($d->{ENSEMBLE}[$i]->{DEPTH_BT} > $d->{ENSEMBLE}[$be]->{DEPTH}) { |
|
144 |
$guesses[int($d->{ENSEMBLE}[$i]->{DEPTH_BT})+$z_offset]++; |
|
145 |
$nd++; |
|
146 |
} else { |
|
147 |
undef($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
148 |
} |
|
149 |
} |
|
150 |
return undef unless ($nd>5); |
|
151 |
||
152 |
my($mode,$nmax); |
|
153 |
for ($i=0; $i<=$#guesses; $i++) { # find mode |
|
154 |
$nmax=$guesses[$i],$mode=$i-$z_offset |
|
155 |
if ($guesses[$i] > $nmax); |
|
156 |
} |
|
157 |
||
158 |
$nd = 0; |
|
159 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
160 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
161 |
if (abs($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$mode) <= $mode_width) { |
|
162 |
$dd += $d->{ENSEMBLE}[$i]->{DEPTH_BT}; |
|
163 |
$nd++; |
|
164 |
} else { |
|
165 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} = undef; |
|
166 |
} |
|
167 |
} |
|
168 |
return undef unless ($nd >= 2); |
|
169 |
||
170 |
$dd /= $nd; |
|
171 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
172 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
173 |
$sd += ($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$dd)**2; |
|
174 |
} |
|
175 |
||
176 |
return ($dd, sqrt($sd/($nd-1))); |
|
177 |
} |
|
178 |
||
179 |
#====================================================================== |
|
180 |
# c = soundSpeed($salin,$temp,$depth) |
|
181 |
#====================================================================== |
|
182 |
||
183 |
# Taken from the RDI BroadBand primer manual. The reference given there |
|
184 |
# is Urick (1983). |
|
185 |
||
186 |
sub soundSpeed($$$) |
|
187 |
{ |
|
188 |
my($salin,$temp,$depth) = @_; |
|
189 |
die("ERROR: soundSpeed($salin,$temp,$depth): non-numeric parameter\n") |
|
190 |
unless numberp($salin) && numberp($temp) && numberp($depth); |
|
191 |
return 1449.2 + 4.6*$temp -0.055*$temp**2 + 0.00029*$temp**3 + |
|
192 |
(1.34 - 0.01*$temp) * ($salin - 35) + 0.016*$depth; |
|
193 |
} |
|
194 |
||
195 |
#====================================================================== |
|
196 |
# fac = ssCorr($eRef,$salin,$temp,$depth) |
|
197 |
# $eRef : reference to current ensemble |
|
198 |
# $salin: * -> use instrument salinity |
|
199 |
# $temp : * -> use instrument temperature |
|
200 |
# $depth: * -> use instrument PRESSURE(!) |
|
201 |
#====================================================================== |
|
202 |
||
203 |
{ my($warned); |
|
204 |
sub ssCorr($$$$) |
|
205 |
{ |
|
206 |
my($eRef,$S,$T,$D) = @_; |
|
207 |
$S = $eRef->{SALINITY} if ($S eq '*'); |
|
208 |
$T = $eRef->{TEMPERATURE} if ($T eq '*'); |
|
209 |
if ($D eq '*') { |
|
210 |
print(STDERR "WARNING: soundspeed correction using instrument pressure instead of depth!\n") |
|
211 |
unless ($warned); |
|
212 |
$warned = 1; |
|
213 |
$D = $eRef->{PRESSURE}; |
|
214 |
} |
|
215 |
return soundSpeed($S,$T,$D) / $eRef->{SPEED_OF_SOUND}; |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
#====================================================================== |
|
220 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz) = |
|
221 |
# mk_prof($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
|
222 |
#====================================================================== |
|
223 |
||
12 | 224 |
# calculate reference-layer vertical and incident velocities |
225 |
||
226 |
{ my($warned); # static scope |
|
227 |
||
228 |
sub ref_lr_w($$$$$$$) |
|
0 | 229 |
{ |
11 | 230 |
my($dta,$ens,$rl_b0,$rl_b1,$min_corr,$max_e,$min_pctg) = @_; |
12 | 231 |
my($i,@n,@bn,@v,@vi,@vel,@veli,@bv,@w); |
232 |
my($w,$e,$nvi,$vi12,$vi43,@vbp,@velbp,@nbp,$w12,$w34,@w12,@w34); |
|
0 | 233 |
|
234 |
for ($i=$rl_b0; $i<=$rl_b1; $i++) { |
|
235 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
|
236 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr); |
|
237 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
|
238 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][1] < $min_corr); |
|
239 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
|
240 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $min_corr); |
|
241 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
|
242 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $min_corr); |
|
243 |
if ($dta->{BEAM_COORDINATES}) { |
|
244 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
|
11 | 245 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < $min_pctg); |
0 | 246 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
11 | 247 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < $min_pctg); |
0 | 248 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
11 | 249 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < $min_pctg); |
0 | 250 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
11 | 251 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
12 | 252 |
@vi = velBeamToInstrument($dta,@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}); |
253 |
@v = velInstrumentToEarth($dta,$ens,@vi); |
|
254 |
@vbp = velBeamToBPEarth($dta,$ens,@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}); |
|
0 | 255 |
} else { |
256 |
next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 || |
|
257 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 || |
|
258 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
|
11 | 259 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
0 | 260 |
@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}; |
12 | 261 |
unless ($warned) { |
262 |
print(STDERR "WARNING: incident-flow & beam-pair velocities not yet implemented for earth coordinates"); |
|
263 |
$warned = 1; |
|
264 |
} |
|
0 | 265 |
} |
10 | 266 |
### next if (!defined($v[3]) || abs($v[3]) > $max_e); # disallow 3-beam solutions |
267 |
next if (defined($v[3]) && abs($v[3]) > $max_e); # allow 3-beam solutions |
|
0 | 268 |
|
12 | 269 |
if (defined($v[2])) { # valid velocity |
270 |
$vel[2] += $v[2]; $n[2]++; # vertical velocity |
|
271 |
$vel[3] += $v[3], $n[3]++ if defined($v[3]); # error velocity |
|
272 |
push(@w,$v[2]); # save for stderr calculation |
|
273 |
} |
|
274 |
||
275 |
if (defined($vbp[1])) { # beam-pair vertical velocities |
|
276 |
$velbp[0] += $vbp[1]; $nbp[0]++; |
|
277 |
push(@w12,$vbp[1]); |
|
278 |
} |
|
279 |
if (defined($vbp[3])) { |
|
280 |
$velbp[1] += $vbp[3]; $nbp[1]++; |
|
281 |
push(@w34,$vbp[1]); |
|
0 | 282 |
} |
283 |
||
12 | 284 |
if (defined($vi[0])) { # incident velocity |
285 |
$veli[0] += $vi[0]; |
|
286 |
$veli[1] += $vi[1]; |
|
287 |
$nvi++; |
|
288 |
} |
|
289 |
||
10 | 290 |
# The following code calculates beam-averaged ref-lr velocities. |
291 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
292 |
# |
|
293 |
# if ($dta->{BEAM_COORDINATES}) { |
|
294 |
# $bv[0] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0], $bn[0]++ |
|
295 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]); |
|
296 |
# $bv[1] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1], $bn[1]++ |
|
297 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]); |
|
298 |
# $bv[2] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2], $bn[2]++ |
|
299 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]); |
|
300 |
# $bv[3] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3], $bn[3]++ |
|
301 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]); |
|
302 |
# } |
|
12 | 303 |
} # loop over ref-lr bins |
304 |
||
305 |
$w = ($n[2] > 0) ? $vel[2]/$n[2] : undef; # calc means |
|
306 |
$e = ($n[3] > 0) ? $vel[3]/$n[3] : undef; |
|
307 |
if ($nvi > 0) { |
|
308 |
$vi12 = $veli[0] / $nvi; |
|
309 |
$vi43 = $veli[1] / $nvi; |
|
310 |
} else { |
|
311 |
$vi12 = $vi43 = undef; |
|
312 |
} |
|
313 |
$w12 = ($nbp[0] > 0) ? $velbp[0]/$nbp[0] : undef; |
|
314 |
$w34 = ($nbp[1] > 0) ? $velbp[1]/$nbp[1] : undef; |
|
315 |
||
316 |
if (@w12) { # w uncertainty |
|
317 |
my($sumsq) = 0; |
|
318 |
for ($i=0; $i<=$#w12; $i++) { |
|
319 |
$sumsq += ($w12-$w12[$i])**2; |
|
320 |
} |
|
321 |
$dta->{ENSEMBLE}[$ens]->{W12} = $w12; |
|
322 |
$dta->{ENSEMBLE}[$ens]->{W12_ERR} = sqrt($sumsq)/($nbp[0]-1) |
|
323 |
if ($nbp[0]>=2); |
|
0 | 324 |
} |
325 |
||
12 | 326 |
if (@w34) { # w uncertainty |
327 |
my($sumsq) = 0; |
|
328 |
for ($i=0; $i<=$#w34; $i++) { |
|
329 |
$sumsq += ($w34-$w34[$i])**2; |
|
330 |
} |
|
331 |
$dta->{ENSEMBLE}[$ens]->{W34} = $w34; |
|
332 |
$dta->{ENSEMBLE}[$ens]->{W34_ERR} = sqrt($sumsq)/($nbp[1]-1) |
|
333 |
if ($nbp[1]>=2); |
|
334 |
} |
|
335 |
||
336 |
my($sumsq) = 0; # w uncertainty |
|
0 | 337 |
for ($i=0; $i<=$#w; $i++) { |
338 |
$sumsq += ($w-$w[$i])**2; |
|
339 |
} |
|
340 |
my($stderr) = $n[2]>=2 ? sqrt($sumsq)/($n[2]-1) : undef; |
|
12 | 341 |
|
0 | 342 |
# The following stderr test introduces a huge gap near the bottom of |
343 |
# the profiles. Without it, they seem more reasonable. |
|
344 |
# next if ($stderr > 0.05); |
|
345 |
||
12 | 346 |
if (defined($w)) { # valid velocity |
0 | 347 |
$dta->{ENSEMBLE}[$ens]->{W} = $w; |
348 |
$dta->{ENSEMBLE}[$ens]->{W_ERR} = $stderr; |
|
349 |
} |
|
12 | 350 |
$dta->{ENSEMBLE}[$ens]->{ERR_VEL} = $e if (defined($e)); |
351 |
||
352 |
$dta->{ENSEMBLE}[$ens]->{W12} = $w12 if (defined($w12)); |
|
353 |
$dta->{ENSEMBLE}[$ens]->{W34} = $w34 if (defined($w34)); |
|
354 |
||
355 |
if (defined($vi12)) { |
|
356 |
$dta->{ENSEMBLE}[$ens]->{INCIDENT_VEL_T12} = $vi12; |
|
357 |
$dta->{ENSEMBLE}[$ens]->{INCIDENT_VEL_T43} = $vi43; |
|
358 |
} |
|
359 |
||
10 | 360 |
# The following code calculates beam-averaged ref-lr velocities. |
361 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
362 |
# |
|
363 |
# if ($dta->{BEAM_COORDINATES}) { |
|
364 |
# $dta->{ENSEMBLE}[$ens]->{V1} = $bn[0]>=2 ? $bv[0]/$bn[0] : undef; |
|
365 |
# $dta->{ENSEMBLE}[$ens]->{V2} = $bn[1]>=2 ? $bv[1]/$bn[1] : undef; |
|
366 |
# $dta->{ENSEMBLE}[$ens]->{V3} = $bn[2]>=2 ? $bv[2]/$bn[2] : undef; |
|
367 |
# $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef; |
|
368 |
# } |
|
12 | 369 |
|
0 | 370 |
} |
371 |
||
12 | 372 |
} # static scope |
373 |
||
0 | 374 |
|
11 | 375 |
sub mk_prof(...) # make profile |
0 | 376 |
{ |
11 | 377 |
my($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap,$min_pctg) = @_; |
0 | 378 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz); |
8 | 379 |
my($rms_heave_accel_ssq,$rms_heave_accel_nsamp); |
11 | 380 |
|
381 |
$min_pctg = 100 unless defined($min_pctg); |
|
0 | 382 |
|
383 |
for (my($z)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
|
384 |
checkEnsemble($dta,$e) if ($check); |
|
6 | 385 |
### The following line of code, which can only have an effect if check is disabled, |
386 |
### seems reasonable but has been found to make matters worse with one particular |
|
387 |
### data file from a BB150. |
|
388 |
### next if ($dta->{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
0 | 389 |
|
390 |
filterEnsemble($dta,$e) |
|
391 |
if (defined($filter) && |
|
392 |
$dta->{ENSEMBLE}[$e]->{PERCENT_GOOD}[0][0] > 0); |
|
11 | 393 |
ref_lr_w($dta,$e,$lr_b0,$lr_b1,$min_corr,$max_e,$min_pctg); # ref. layer w |
0 | 394 |
|
395 |
if (defined($firstgood)) { |
|
396 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = # time since start |
|
397 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
398 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
|
399 |
} else { |
|
400 |
if (defined($dta->{ENSEMBLE}[$e]->{W})) { # start of prof. |
|
401 |
$firstgood = $lastgood = $e; |
|
402 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
403 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
404 |
} |
|
405 |
next; |
|
406 |
} |
|
407 |
||
408 |
#-------------------------------------------------- |
|
409 |
# within profile: both $firstgood and $lastgood set |
|
410 |
#-------------------------------------------------- |
|
411 |
||
412 |
if (!defined($dta->{ENSEMBLE}[$e]->{W})) { # gap |
|
413 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
414 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
415 |
next; |
|
416 |
} |
|
417 |
||
418 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
419 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens |
|
420 |
||
421 |
if ($dt > $max_gap) { |
|
5 | 422 |
if ($dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME} - |
423 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME} > 15*60) { |
|
424 |
printf(STDERR "WARNING: %.1f-s gap too long, profile ended at ensemble $lastgood\n",$dt); |
|
425 |
last; |
|
426 |
} |
|
427 |
printf(STDERR "WARNING: %.1f-s gap too long, profile restarted at ensemble $e\n",$dt); |
|
0 | 428 |
$firstgood = $lastgood = $e; |
429 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
430 |
$z = $zErr = $maxz = 0; |
|
431 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
432 |
$w_gap_time = 0; |
|
8 | 433 |
$rms_heave_accel_ssq = $rms_heave_accel_nsamp = 0; |
0 | 434 |
next; |
435 |
} |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
436 |
|
0 | 437 |
#----------------------------------- |
438 |
# The current ensemble has a valid w |
|
439 |
#----------------------------------- |
|
8 | 440 |
|
441 |
if ($dt < 5) { # no or short gap |
|
442 |
$z += $dta->{ENSEMBLE}[$lastgood]->{W} * $dt; # integrate w to get depth |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
443 |
$zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2; |
8 | 444 |
$rms_heave_accel_ssq += (($dta->{ENSEMBLE}[$e]->{W}-$dta->{ENSEMBLE}[$lastgood]->{W})/$dt)**2; |
445 |
$rms_heave_accel_nsamp++; |
|
3 | 446 |
} elsif ($dt > 15) { |
5 | 447 |
printf(STDERR "WARNING: long-ish w gap (dt=%.1fs)\n",$dt); |
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
448 |
} |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
449 |
|
0 | 450 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $z; |
451 |
$dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = sqrt($zErr); |
|
452 |
||
453 |
$atbottom = $e, $maxz = $z if ($z > $maxz); |
|
454 |
||
455 |
$lastgood = $e; |
|
456 |
} |
|
457 |
||
458 |
filterEnsembleStats() if defined($filter); |
|
459 |
||
8 | 460 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz,sqrt($rms_heave_accel_ssq/$rms_heave_accel_nsamp)); |
0 | 461 |
} |
462 |
||
463 |
#---------------------------------------------------------------------- |
|
464 |
# (true|false) = numberp(var) |
|
465 |
#---------------------------------------------------------------------- |
|
466 |
||
467 |
sub numberp(@) |
|
468 |
{ return $_[0] =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/; } |
|
469 |
||
470 |
||
471 |
1; |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
472 |