2
|
1 |
#======================================================================
|
|
2 |
# T I M E _ S E R I E S . P L
|
|
3 |
# doc: Sun May 23 16:40:53 2010
|
|
4 |
# dlm: Sat Jul 2 21:12:35 2011
|
|
5 |
# (c) 2010 A.M. Thurnherr
|
|
6 |
# uE-Info: 15 48 NIL 0 0 72 2 2 4 NIL ofnI
|
|
7 |
#======================================================================
|
|
8 |
|
|
9 |
# HISTORY:
|
|
10 |
# May 23, 2010: - created from [perl-tools/RDI_Utils.pl]
|
|
11 |
# Oct 20, 2010: - disabled max_gap profile-restarting code
|
|
12 |
# Dec 17, 2010: - re-added {DEPTH} field to ensembles
|
|
13 |
# Dec 18, 2010: - max gap re-enabled
|
|
14 |
# Dec 20, 2010: - cosmetics
|
|
15 |
# Jul 2, 2011: - tightened gap-detection code
|
|
16 |
|
|
17 |
# NOTES:
|
|
18 |
# - resulting DEPTH field based on integrated w without any sound speed correction
|
|
19 |
# - single-ping ensembles assumed, i.e. no percent-good tests applied
|
|
20 |
# - specified bin numbers are 1-relative
|
|
21 |
|
|
22 |
sub ref_lr_w($$$$) # calc ref-layer vert vels
|
|
23 |
{
|
|
24 |
my($dta,$ens,$rl_b0,$rl_b1) = @_;
|
|
25 |
my($i,@n,@bn,@v,@vel,@bv,@w);
|
|
26 |
|
|
27 |
for ($i=$rl_b0-1; $i<=$rl_b1-1; $i++) {
|
|
28 |
if (defined($dta->{ENSEMBLE}[$ens]->{W}[$i])) { # valid w
|
|
29 |
$vel[2] += $dta->{ENSEMBLE}[$ens]->{W}[$i]; $n[2]++;
|
|
30 |
$vel[3] += $dta->{ENSEMBLE}[$ens]->{ERRVEL}[$i], $n[3]++ if defined($dta->{ENSEMBLE}[$ens]->{ERRVEL}[$i]);
|
|
31 |
push(@w,$dta->{ENSEMBLE}[$ens]->{W}[$i]); # for stderr test
|
|
32 |
}
|
|
33 |
}
|
|
34 |
|
|
35 |
my($w) = $n[2] ? $vel[2]/$n[2] : undef; # w uncertainty
|
|
36 |
my($sumsq) = 0;
|
|
37 |
for ($i=0; $i<=$#w; $i++) {
|
|
38 |
$sumsq += ($w-$w[$i])**2;
|
|
39 |
}
|
|
40 |
my($stderr) = $n[2]>=2 ? sqrt($sumsq)/($n[2]-1) : undef;
|
|
41 |
|
|
42 |
if (defined($w)) { # valid w
|
|
43 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W} = $w;
|
|
44 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W_ERR} = $stderr;
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
#======================================================================
|
|
49 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time) =
|
|
50 |
# calcLADCPts($dta,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap);
|
|
51 |
#======================================================================
|
|
52 |
|
|
53 |
sub calcLADCPts($$$$)
|
|
54 |
{
|
|
55 |
my($dta,$rl_b0,$rl_b1,$max_gap) = @_;
|
|
56 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$max_depth);
|
|
57 |
|
|
58 |
for (my($depth)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) {
|
|
59 |
|
|
60 |
ref_lr_w($dta,$e,$rl_b0,$rl_b1);
|
|
61 |
|
|
62 |
if (defined($firstgood)) {
|
|
63 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = # time since start
|
|
64 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} -
|
|
65 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME};
|
|
66 |
} else {
|
|
67 |
if (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # start of prof.
|
|
68 |
$firstgood = $lastgood = $e;
|
|
69 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
|
|
70 |
}
|
|
71 |
next;
|
|
72 |
}
|
|
73 |
|
|
74 |
unless (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # gap
|
|
75 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} -
|
|
76 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME};
|
|
77 |
next;
|
|
78 |
}
|
|
79 |
|
|
80 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since
|
|
81 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens
|
|
82 |
|
|
83 |
if ($dt > $max_gap) {
|
|
84 |
if ($max_depth>50 && $depth<0.1*$max_depth) {
|
|
85 |
warning(1,"long gap (%ds) near end of profile --- terminated at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
|
|
86 |
last;
|
|
87 |
}
|
|
88 |
if ($depth < 10) {
|
|
89 |
warning(1,"long gap (%ds) near beginning of profile --- restarted at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
|
|
90 |
$firstgood = $lastgood = $e;
|
|
91 |
undef($atbottom); undef($max_depth);
|
|
92 |
$depth = 0;
|
|
93 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
|
|
94 |
$w_gap_time = 0;
|
|
95 |
next;
|
|
96 |
}
|
|
97 |
if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) {
|
|
98 |
warning(1,"long gap (%ds) at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n",
|
|
99 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED});
|
|
100 |
} else {
|
|
101 |
warning(1,"long gap (%ds) at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}, %.1fmin into the profile\n",
|
|
102 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}/60);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
$depth += $dta->{ENSEMBLE}[$lastgood]->{REFLR_W} * $dt; # integrate
|
|
107 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
|
|
108 |
|
|
109 |
$atbottom = $e, $max_depth = $depth if ($depth > $max_depth);
|
|
110 |
$lastgood = $e;
|
|
111 |
}
|
|
112 |
|
|
113 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time);
|
|
114 |
}
|
|
115 |
|
|
116 |
1;
|