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