author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sat, 06 Apr 2013 13:10:30 +0000 | |
changeset 10 | c835cd613f3e |
parent 8 | 7ad053ea1742 |
child 11 | 9c3b147b4372 |
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 |
|
10 | 4 |
# dlm: Wed Mar 27 14:45:02 2013 |
0 | 5 |
# (c) 2003 A.M. Thurnherr |
10 | 6 |
# uE-Info: 43 51 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 |
|
0 | 44 |
|
45 |
use strict; |
|
46 |
||
47 |
#====================================================================== |
|
48 |
# fake_BT_RANGE(dta ptr) |
|
49 |
#====================================================================== |
|
50 |
||
51 |
# During cruise NBP0204 it was found that one of Visbeck's RDIs consistently |
|
52 |
# returns zero as the bottom-track range, even thought the BT velocities |
|
53 |
# are good. This functions calculates the ranges if they are missing. |
|
54 |
||
55 |
sub cBTR($$$) |
|
56 |
{ |
|
57 |
my($d,$e,$b) = @_; |
|
58 |
my($maxamp) = -9e99; |
|
59 |
my($maxi); |
|
60 |
||
61 |
for (my($i)=0; $i<$d->{N_BINS}; $i++) { |
|
62 |
next unless ($d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b] > $maxamp); |
|
63 |
$maxamp = $d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b]; |
|
64 |
$maxi = $i; |
|
65 |
} |
|
66 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = |
|
67 |
$d->{DISTANCE_TO_BIN1_CENTER} + $maxi * $d->{BIN_LENGTH}; |
|
68 |
} |
|
69 |
||
70 |
sub ensure_BT_RANGE($) |
|
71 |
{ |
|
72 |
my($d) = @_; |
|
73 |
for (my($e)=0; $e<=$#{$d->{ENSEMBLE}}; $e++) { |
|
74 |
my($sum) = my($n) = 0; |
|
75 |
if (defined($d->{ENSEMBLE}[$e]->{BT_VELOCITY}[0])) { |
|
76 |
for (my($b)=0; $b<4; $b++) { |
|
77 |
cBTR($d,$e,$b) |
|
78 |
unless defined($d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]); |
|
79 |
$sum += $d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]; $n++; |
|
80 |
} |
|
81 |
} else { |
|
82 |
for (my($b)=0; $b<4; $b++) { |
|
83 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = undef; |
|
84 |
} |
|
85 |
} |
|
86 |
$d->{ENSEMBLE}[$e]->{BT_MEAN_RANGE} = $sum/$n if ($n == 4); |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
#====================================================================== |
|
91 |
# (seabed depth, stddev) = find_seabed(dta ptr, btm ensno, coord flag) |
|
92 |
#====================================================================== |
|
93 |
||
94 |
# NOTE FOR YOYOS: |
|
95 |
# - this routine only detects the BT around the depeest depth! |
|
96 |
# - this is on purpose, because it is used for [listBT] |
|
97 |
||
98 |
# This is a PAIN: |
|
99 |
# if the instrument is too close to the bottom, the BT_RANGE |
|
100 |
# readings are all out; the only solution is to have a sufficiently |
|
101 |
# large search width (around the max(depth) ensemble) so that |
|
102 |
# a part of the up (oops, I forgot to finish this comment one year |
|
103 |
# ago during A0304 and now I don't understand it any more :-) |
|
104 |
||
105 |
my($search_width) = 200; # # of ensembles around bottom to search |
|
106 |
my($mode_width) = 10; # max range of bottom around mode |
|
107 |
my($min_dist) = 20; # min dist to seabed for good data |
|
108 |
my($z_offset) = 10000; # shift z to ensure +ve array indices |
|
109 |
||
110 |
sub find_seabed($$$) |
|
111 |
{ |
|
112 |
my($d,$be,$beamCoords) = @_; |
|
113 |
my($i,$dd,$sd,$nd); |
|
114 |
my(@guesses); |
|
115 |
||
116 |
return undef unless ($be-$search_width >= 0 && |
|
117 |
$be+$search_width <= $#{$d->{ENSEMBLE}}); |
|
118 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
119 |
next unless (defined($d->{ENSEMBLE}[$i]->{DEPTH}) && |
|
120 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[0]) && |
|
121 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[1]) && |
|
122 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[2]) && |
|
123 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[3])); |
|
124 |
my(@BT) = $beamCoords |
|
125 |
? velInstrumentToEarth($d,$i, |
|
126 |
velBeamToInstrument($d, |
|
127 |
@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}})) |
|
128 |
: velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}); |
|
129 |
next unless (abs($BT[3]) < 0.05); |
|
130 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} = |
|
131 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[0]/4 + |
|
132 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[1]/4 + |
|
133 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[2]/4 + |
|
134 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[3]/4; |
|
135 |
next unless ($d->{ENSEMBLE}[$i]->{DEPTH_BT} >= $min_dist); |
|
136 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} *= -1 |
|
137 |
if ($d->{ENSEMBLE}[$i]->{XDUCER_FACING_UP}); |
|
138 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} += $d->{ENSEMBLE}[$i]->{DEPTH}; |
|
139 |
if ($d->{ENSEMBLE}[$i]->{DEPTH_BT} > $d->{ENSEMBLE}[$be]->{DEPTH}) { |
|
140 |
$guesses[int($d->{ENSEMBLE}[$i]->{DEPTH_BT})+$z_offset]++; |
|
141 |
$nd++; |
|
142 |
} else { |
|
143 |
undef($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
144 |
} |
|
145 |
} |
|
146 |
return undef unless ($nd>5); |
|
147 |
||
148 |
my($mode,$nmax); |
|
149 |
for ($i=0; $i<=$#guesses; $i++) { # find mode |
|
150 |
$nmax=$guesses[$i],$mode=$i-$z_offset |
|
151 |
if ($guesses[$i] > $nmax); |
|
152 |
} |
|
153 |
||
154 |
$nd = 0; |
|
155 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
156 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
157 |
if (abs($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$mode) <= $mode_width) { |
|
158 |
$dd += $d->{ENSEMBLE}[$i]->{DEPTH_BT}; |
|
159 |
$nd++; |
|
160 |
} else { |
|
161 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} = undef; |
|
162 |
} |
|
163 |
} |
|
164 |
return undef unless ($nd >= 2); |
|
165 |
||
166 |
$dd /= $nd; |
|
167 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
168 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT}); |
|
169 |
$sd += ($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$dd)**2; |
|
170 |
} |
|
171 |
||
172 |
return ($dd, sqrt($sd/($nd-1))); |
|
173 |
} |
|
174 |
||
175 |
#====================================================================== |
|
176 |
# c = soundSpeed($salin,$temp,$depth) |
|
177 |
#====================================================================== |
|
178 |
||
179 |
# Taken from the RDI BroadBand primer manual. The reference given there |
|
180 |
# is Urick (1983). |
|
181 |
||
182 |
sub soundSpeed($$$) |
|
183 |
{ |
|
184 |
my($salin,$temp,$depth) = @_; |
|
185 |
die("ERROR: soundSpeed($salin,$temp,$depth): non-numeric parameter\n") |
|
186 |
unless numberp($salin) && numberp($temp) && numberp($depth); |
|
187 |
return 1449.2 + 4.6*$temp -0.055*$temp**2 + 0.00029*$temp**3 + |
|
188 |
(1.34 - 0.01*$temp) * ($salin - 35) + 0.016*$depth; |
|
189 |
} |
|
190 |
||
191 |
#====================================================================== |
|
192 |
# fac = ssCorr($eRef,$salin,$temp,$depth) |
|
193 |
# $eRef : reference to current ensemble |
|
194 |
# $salin: * -> use instrument salinity |
|
195 |
# $temp : * -> use instrument temperature |
|
196 |
# $depth: * -> use instrument PRESSURE(!) |
|
197 |
#====================================================================== |
|
198 |
||
199 |
{ my($warned); |
|
200 |
sub ssCorr($$$$) |
|
201 |
{ |
|
202 |
my($eRef,$S,$T,$D) = @_; |
|
203 |
$S = $eRef->{SALINITY} if ($S eq '*'); |
|
204 |
$T = $eRef->{TEMPERATURE} if ($T eq '*'); |
|
205 |
if ($D eq '*') { |
|
206 |
print(STDERR "WARNING: soundspeed correction using instrument pressure instead of depth!\n") |
|
207 |
unless ($warned); |
|
208 |
$warned = 1; |
|
209 |
$D = $eRef->{PRESSURE}; |
|
210 |
} |
|
211 |
return soundSpeed($S,$T,$D) / $eRef->{SPEED_OF_SOUND}; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
#====================================================================== |
|
216 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz) = |
|
217 |
# mk_prof($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
|
218 |
#====================================================================== |
|
219 |
||
220 |
sub ref_lr_w($$$$$$) # calc ref-level vert vels |
|
221 |
{ |
|
222 |
my($dta,$ens,$rl_b0,$rl_b1,$min_corr,$max_e) = @_; |
|
223 |
my($i,@n,@bn,@v,@vel,@bv,@w); |
|
224 |
||
225 |
for ($i=$rl_b0; $i<=$rl_b1; $i++) { |
|
226 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
|
227 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr); |
|
228 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
|
229 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][1] < $min_corr); |
|
230 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
|
231 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $min_corr); |
|
232 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
|
233 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $min_corr); |
|
234 |
if ($dta->{BEAM_COORDINATES}) { |
|
235 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
|
236 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < 100); |
|
237 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
|
238 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < 100); |
|
239 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
|
240 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < 100); |
|
241 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
|
242 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
|
243 |
@v = velInstrumentToEarth($dta,$ens, |
|
244 |
velBeamToInstrument($dta, |
|
245 |
@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]})); |
|
246 |
} else { |
|
247 |
next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 || |
|
248 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 || |
|
249 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
|
250 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
|
251 |
@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}; |
|
252 |
# NB: no need to apply heading bias, as long as we only use w! |
|
253 |
} |
|
10 | 254 |
### next if (!defined($v[3]) || abs($v[3]) > $max_e); # disallow 3-beam solutions |
255 |
next if (defined($v[3]) && abs($v[3]) > $max_e); # allow 3-beam solutions |
|
0 | 256 |
|
257 |
if (defined($v[2])) { # valid w |
|
258 |
$vel[2] += $v[2]; $n[2]++; |
|
259 |
$vel[3] += $v[3], $n[3]++ if defined($v[3]); |
|
260 |
push(@w,$v[2]); # for stderr test |
|
261 |
} |
|
262 |
||
10 | 263 |
# The following code calculates beam-averaged ref-lr velocities. |
264 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
265 |
# |
|
266 |
# if ($dta->{BEAM_COORDINATES}) { |
|
267 |
# $bv[0] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0], $bn[0]++ |
|
268 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]); |
|
269 |
# $bv[1] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1], $bn[1]++ |
|
270 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]); |
|
271 |
# $bv[2] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2], $bn[2]++ |
|
272 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]); |
|
273 |
# $bv[3] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3], $bn[3]++ |
|
274 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]); |
|
275 |
# } |
|
0 | 276 |
} |
277 |
||
278 |
my($w) = $n[2] ? $vel[2]/$n[2] : undef; # w uncertainty |
|
279 |
my($sumsq) = 0; |
|
280 |
for ($i=0; $i<=$#w; $i++) { |
|
281 |
$sumsq += ($w-$w[$i])**2; |
|
282 |
} |
|
283 |
my($stderr) = $n[2]>=2 ? sqrt($sumsq)/($n[2]-1) : undef; |
|
284 |
# The following stderr test introduces a huge gap near the bottom of |
|
285 |
# the profiles. Without it, they seem more reasonable. |
|
286 |
# next if ($stderr > 0.05); |
|
287 |
||
288 |
if (defined($w)) { # valid w |
|
289 |
$dta->{ENSEMBLE}[$ens]->{W} = $w; |
|
290 |
$dta->{ENSEMBLE}[$ens]->{W_ERR} = $stderr; |
|
291 |
} |
|
10 | 292 |
# The following code calculates beam-averaged ref-lr velocities. |
293 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
294 |
# |
|
295 |
# if ($dta->{BEAM_COORDINATES}) { |
|
296 |
# $dta->{ENSEMBLE}[$ens]->{V1} = $bn[0]>=2 ? $bv[0]/$bn[0] : undef; |
|
297 |
# $dta->{ENSEMBLE}[$ens]->{V2} = $bn[1]>=2 ? $bv[1]/$bn[1] : undef; |
|
298 |
# $dta->{ENSEMBLE}[$ens]->{V3} = $bn[2]>=2 ? $bv[2]/$bn[2] : undef; |
|
299 |
# $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef; |
|
300 |
# } |
|
0 | 301 |
} |
302 |
||
303 |
||
304 |
sub mk_prof($$$$$$$$) # make profile |
|
305 |
{ |
|
306 |
my($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap) = @_; |
|
307 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz); |
|
8 | 308 |
my($rms_heave_accel_ssq,$rms_heave_accel_nsamp); |
0 | 309 |
|
310 |
for (my($z)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
|
311 |
checkEnsemble($dta,$e) if ($check); |
|
6 | 312 |
### The following line of code, which can only have an effect if check is disabled, |
313 |
### seems reasonable but has been found to make matters worse with one particular |
|
314 |
### data file from a BB150. |
|
315 |
### next if ($dta->{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
0 | 316 |
|
317 |
filterEnsemble($dta,$e) |
|
318 |
if (defined($filter) && |
|
319 |
$dta->{ENSEMBLE}[$e]->{PERCENT_GOOD}[0][0] > 0); |
|
320 |
ref_lr_w($dta,$e,$lr_b0,$lr_b1,$min_corr,$max_e); # ref. layer w |
|
321 |
||
322 |
if (defined($firstgood)) { |
|
323 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = # time since start |
|
324 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
325 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
|
326 |
} else { |
|
327 |
if (defined($dta->{ENSEMBLE}[$e]->{W})) { # start of prof. |
|
328 |
$firstgood = $lastgood = $e; |
|
329 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
330 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
331 |
} |
|
332 |
next; |
|
333 |
} |
|
334 |
||
335 |
#-------------------------------------------------- |
|
336 |
# within profile: both $firstgood and $lastgood set |
|
337 |
#-------------------------------------------------- |
|
338 |
||
339 |
if (!defined($dta->{ENSEMBLE}[$e]->{W})) { # gap |
|
340 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
341 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
342 |
next; |
|
343 |
} |
|
344 |
||
345 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
346 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens |
|
347 |
||
348 |
if ($dt > $max_gap) { |
|
5 | 349 |
if ($dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME} - |
350 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME} > 15*60) { |
|
351 |
printf(STDERR "WARNING: %.1f-s gap too long, profile ended at ensemble $lastgood\n",$dt); |
|
352 |
last; |
|
353 |
} |
|
354 |
printf(STDERR "WARNING: %.1f-s gap too long, profile restarted at ensemble $e\n",$dt); |
|
0 | 355 |
$firstgood = $lastgood = $e; |
356 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
357 |
$z = $zErr = $maxz = 0; |
|
358 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
359 |
$w_gap_time = 0; |
|
8 | 360 |
$rms_heave_accel_ssq = $rms_heave_accel_nsamp = 0; |
0 | 361 |
next; |
362 |
} |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
363 |
|
0 | 364 |
#----------------------------------- |
365 |
# The current ensemble has a valid w |
|
366 |
#----------------------------------- |
|
8 | 367 |
|
368 |
if ($dt < 5) { # no or short gap |
|
369 |
$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
|
370 |
$zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2; |
8 | 371 |
$rms_heave_accel_ssq += (($dta->{ENSEMBLE}[$e]->{W}-$dta->{ENSEMBLE}[$lastgood]->{W})/$dt)**2; |
372 |
$rms_heave_accel_nsamp++; |
|
3 | 373 |
} elsif ($dt > 15) { |
5 | 374 |
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
|
375 |
} |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
376 |
|
0 | 377 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $z; |
378 |
$dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = sqrt($zErr); |
|
379 |
||
380 |
$atbottom = $e, $maxz = $z if ($z > $maxz); |
|
381 |
||
382 |
$lastgood = $e; |
|
383 |
} |
|
384 |
||
385 |
filterEnsembleStats() if defined($filter); |
|
386 |
||
8 | 387 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz,sqrt($rms_heave_accel_ssq/$rms_heave_accel_nsamp)); |
0 | 388 |
} |
389 |
||
390 |
#---------------------------------------------------------------------- |
|
391 |
# (true|false) = numberp(var) |
|
392 |
#---------------------------------------------------------------------- |
|
393 |
||
394 |
sub numberp(@) |
|
395 |
{ return $_[0] =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/; } |
|
396 |
||
397 |
||
398 |
1; |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
399 |