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