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