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