1 #====================================================================== |
1 #====================================================================== |
2 # R D I _ U T I L S . P L |
2 # R D I _ U T I L S . P L |
3 # doc: Wed Feb 12 10:21:32 2003 |
3 # doc: Wed Feb 12 10:21:32 2003 |
4 # dlm: Wed Mar 27 14:45:02 2013 |
4 # dlm: Fri Apr 12 09:22:10 2013 |
5 # (c) 2003 A.M. Thurnherr |
5 # (c) 2003 A.M. Thurnherr |
6 # uE-Info: 43 51 NIL 0 0 72 2 2 4 NIL ofnI |
6 # uE-Info: 44 68 NIL 0 0 72 2 2 4 NIL ofnI |
7 #====================================================================== |
7 #====================================================================== |
8 |
8 |
9 # miscellaneous RDI-specific utilities |
9 # miscellaneous RDI-specific utilities |
10 |
10 |
11 # History: |
11 # History: |
39 # May 12, 2011: - added code to skip ensembles with built-in-test errors in mk_prof() |
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 |
40 # - immediately disabled this code becasue it does appear to make matters worse |
41 # Sep 21, 2011: - added calculation of RMS heave acceleration |
41 # Sep 21, 2011: - added calculation of RMS heave acceleration |
42 # Mar 27, 2013: - BUG: 3-beam solutions were not used in ref_lr_w |
42 # Mar 27, 2013: - BUG: 3-beam solutions were not used in ref_lr_w |
43 # - disabled apparently unused code |
43 # - disabled apparently unused code |
|
44 # Apr 12, 2013: - added $min_pctg as optional parameter to mk_prof |
44 |
45 |
45 use strict; |
46 use strict; |
46 |
47 |
47 #====================================================================== |
48 #====================================================================== |
48 # fake_BT_RANGE(dta ptr) |
49 # fake_BT_RANGE(dta ptr) |
215 #====================================================================== |
216 #====================================================================== |
216 # ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz) = |
217 # ($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 # mk_prof($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
218 #====================================================================== |
219 #====================================================================== |
219 |
220 |
220 sub ref_lr_w($$$$$$) # calc ref-level vert vels |
221 sub ref_lr_w($$$$$$$) # calc ref-level vert vels |
221 { |
222 { |
222 my($dta,$ens,$rl_b0,$rl_b1,$min_corr,$max_e) = @_; |
223 my($dta,$ens,$rl_b0,$rl_b1,$min_corr,$max_e,$min_pctg) = @_; |
223 my($i,@n,@bn,@v,@vel,@bv,@w); |
224 my($i,@n,@bn,@v,@vel,@bv,@w); |
224 |
225 |
225 for ($i=$rl_b0; $i<=$rl_b1; $i++) { |
226 for ($i=$rl_b0; $i<=$rl_b1; $i++) { |
226 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
227 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
227 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr); |
228 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr); |
231 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $min_corr); |
232 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $min_corr); |
232 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
233 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
233 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $min_corr); |
234 if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $min_corr); |
234 if ($dta->{BEAM_COORDINATES}) { |
235 if ($dta->{BEAM_COORDINATES}) { |
235 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
236 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
236 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < 100); |
237 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < $min_pctg); |
237 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
238 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
238 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < 100); |
239 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < $min_pctg); |
239 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
240 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
240 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < 100); |
241 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < $min_pctg); |
241 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
242 undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
242 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
243 if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
243 @v = velInstrumentToEarth($dta,$ens, |
244 @v = velInstrumentToEarth($dta,$ens, |
244 velBeamToInstrument($dta, |
245 velBeamToInstrument($dta, |
245 @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]})); |
246 @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]})); |
246 } else { |
247 } else { |
247 next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 || |
248 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][1] > 0 || |
249 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
250 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
250 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
251 $dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
251 @v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}; |
252 @v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}; |
252 # NB: no need to apply heading bias, as long as we only use w! |
253 # NB: no need to apply heading bias, as long as we only use w! |
253 } |
254 } |
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); # disallow 3-beam solutions |
255 next if (defined($v[3]) && abs($v[3]) > $max_e); # allow 3-beam solutions |
256 next if (defined($v[3]) && abs($v[3]) > $max_e); # allow 3-beam solutions |
299 # $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef; |
300 # $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef; |
300 # } |
301 # } |
301 } |
302 } |
302 |
303 |
303 |
304 |
304 sub mk_prof($$$$$$$$) # make profile |
305 sub mk_prof(...) # make profile |
305 { |
306 { |
306 my($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap) = @_; |
307 my($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap,$min_pctg) = @_; |
307 my($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz); |
308 my($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz); |
308 my($rms_heave_accel_ssq,$rms_heave_accel_nsamp); |
309 my($rms_heave_accel_ssq,$rms_heave_accel_nsamp); |
|
310 |
|
311 $min_pctg = 100 unless defined($min_pctg); |
309 |
312 |
310 for (my($z)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
313 for (my($z)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
311 checkEnsemble($dta,$e) if ($check); |
314 checkEnsemble($dta,$e) if ($check); |
312 ### The following line of code, which can only have an effect if check is disabled, |
315 ### 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 |
316 ### seems reasonable but has been found to make matters worse with one particular |
315 ### next if ($dta->{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
318 ### next if ($dta->{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
316 |
319 |
317 filterEnsemble($dta,$e) |
320 filterEnsemble($dta,$e) |
318 if (defined($filter) && |
321 if (defined($filter) && |
319 $dta->{ENSEMBLE}[$e]->{PERCENT_GOOD}[0][0] > 0); |
322 $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 |
323 ref_lr_w($dta,$e,$lr_b0,$lr_b1,$min_corr,$max_e,$min_pctg); # ref. layer w |
321 |
324 |
322 if (defined($firstgood)) { |
325 if (defined($firstgood)) { |
323 $dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = # time since start |
326 $dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = # time since start |
324 $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
327 $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
325 $dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
328 $dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |