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