author | A.M. Thurnherr <athurnherr@yahoo.com> |
Wed, 13 May 2015 21:30:27 +0000 | |
changeset 35 | 3d769eee8c4f |
parent 33 | dd5b67a41791 |
permissions | -rw-r--r-- |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
1 |
#====================================================================== |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
2 |
# L A D C P P R O C . B E S T L A G |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
3 |
# doc: Tue Sep 28 21:58:48 2010 |
33
dd5b67a41791
merged Explorer with DoMORE-1 changes
A.M. Thurnherr <athurnherr@yahoo.com>
diff
changeset
|
4 |
# dlm: Fri Mar 6 15:53:43 2015 |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
5 |
# (c) 2010 A.M. Thurnherr |
33
dd5b67a41791
merged Explorer with DoMORE-1 changes
A.M. Thurnherr <athurnherr@yahoo.com>
diff
changeset
|
6 |
# uE-Info: 33 0 NIL 0 0 72 2 2 4 NIL ofnI |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
7 |
#====================================================================== |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
8 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
9 |
# TODO: |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
10 |
# - first lag is always(?) nan unless CTD is turned on with LADCP in water |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
11 |
|
1 | 12 |
# HISTORY: |
13 |
# Sep 28, 2010: - created |
|
14 |
# Dec 9, 2010: - adapted to %CTD |
|
15 |
# Dec 10, 2010: - hardened bestlag failure test to require 1/3 agreeing lags |
|
16 |
# Jan 5, 2011: - changed first guess from 80% down to 10% down |
|
17 |
# - added LADCP time lag to %PARAMs |
|
18 |
# - added support of -i |
|
3 | 19 |
# Jul 7, 2011: - added code to remove window-mean of w before lagging to |
20 |
# make it work in regions of crazy ocean w (IWISE 16007) |
|
6 | 21 |
# Jul 15, 2011: - changed screen-output of lag to take first guess lag into |
22 |
# account |
|
9
48b2d27aaebf
after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
6
diff
changeset
|
23 |
# Apr 11, 2011: - removed 1st guess lag consistency check based on large |
48b2d27aaebf
after fixing bad magdec bug
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
6
diff
changeset
|
24 |
# elapsed offsets |
14 | 25 |
# May 18, 2012: - BUG: window start index was not always calculated correctly |
17 | 26 |
# Oct 19, 2012: - BUG: opt_i had wrong sign! |
20 | 27 |
# Jun 25, 2013: - adapted to :: %PARAM convention |
25
91bd907db97f
before debugging weird nsamp problem
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
20
diff
changeset
|
28 |
# Mar 19, 2014: - moved %PARAM to LADCPproc |
30
8697ba5a88ec
before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
25
diff
changeset
|
29 |
# Jul 19, 2014: - made lagging obey -z)oom |
29 | 30 |
# May 25, 2015: - added assertion to require numeric interpolated LADCP_w |
31 |
# - BUG: interp_LADCP_w left gaps |
|
32 |
# - added debug code to output bestLag input time series |
|
1 | 33 |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
34 |
sub interp_LADCP_w($$) |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
35 |
{ |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
36 |
my($elapsed,$ens) = @_; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
37 |
my($sc) = ($elapsed - $LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}) / |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
38 |
($LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME} - |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
39 |
$LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}); |
29 | 40 |
unless (numberp($LADCP{ENSEMBLE}[$ens]->{W})) { |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
41 |
$nGaps++; |
29 | 42 |
$LADCP{ENSEMBLE}[$ens]->{W} = $LADCP{ENSEMBLE}[$ens-1]->{W}; |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
43 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
44 |
return $LADCP{ENSEMBLE}[$ens-1]->{W} + |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
45 |
$sc * ($LADCP{ENSEMBLE}[$ens]->{W} - $LADCP{ENSEMBLE}[$ens-1]->{W}); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
46 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
47 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
48 |
sub bestLag($) |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
49 |
{ |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
50 |
my($ws) = @_; # window start index |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
51 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
52 |
my($best); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
53 |
my($bestmad) = 9e99; # mean absolute deviation |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
54 |
for (my($Llag)=-int($opt_w/2); $Llag<int($opt_w/2); $Llag++) { |
3 | 55 |
my($mCw,$mLw,$nw) = (0,0,0); # first calc means |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
56 |
for (my($Ci)=0; $Ci<$opt_w; $Ci++) { |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
57 |
my($Li) = $Ci + $Llag; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
58 |
next if ($Li<0 || $Li>=$opt_w); |
1 | 59 |
next unless numberp($CTD{w}[$ws+$Ci]) && numberp($LADCP_w[$ws+$Li]); |
3 | 60 |
$mCw += $CTD{w}[$ws+$Ci]; |
61 |
$mLw += $LADCP_w[$ws+$Li]; |
|
62 |
$nw++; |
|
63 |
} |
|
64 |
next unless ($nw > 0); |
|
65 |
$mCw /= $nw; $mLw /= $nw; |
|
66 |
||
67 |
my($sad) = my($nad) = 0; # calc mad with means removed |
|
68 |
for (my($Ci)=0; $Ci<$opt_w; $Ci++) { |
|
69 |
my($Li) = $Ci + $Llag; |
|
70 |
next if ($Li<0 || $Li>=$opt_w); |
|
71 |
next unless numberp($CTD{w}[$ws+$Ci]) && numberp($LADCP_w[$ws+$Li]); |
|
72 |
$sad += abs($CTD{w}[$ws+$Ci]-$mCw - ($LADCP_w[$ws+$Li]-$mLw)); |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
73 |
$nad++; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
74 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
75 |
if ($sad/$nad < $bestmad) { |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
76 |
$best = $Llag; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
77 |
$bestmad = $sad/$nad; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
78 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
79 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
80 |
return $best; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
81 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
82 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
83 |
sub lagLADCP2CTD() |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
84 |
{ |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
85 |
#------------------------------------------------------------------------ |
1 | 86 |
# find 1st rec & ensemble >=10% down to max depth & make 1st guess at lag |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
87 |
#------------------------------------------------------------------------ |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
88 |
|
1 | 89 |
my($first_guess_lag); # in units of CTD records |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
90 |
|
1 | 91 |
if (defined($opt_i)) { |
17 | 92 |
$first_guess_lag = $opt_i / $CTD{sampint}; |
1 | 93 |
} else { |
94 |
my($CTD_10pct_down) = 0; |
|
95 |
$CTD_10pct_down++ # "until" formulation allows for missing pressures |
|
96 |
until ($CTD{press}[$CTD_10pct_down]-$CTD{press}[0] >= 0.1*($CTD{maxpress}-$CTD{press}[0])); |
|
97 |
||
98 |
my($LADCP_10pct_down) = 0; |
|
99 |
$LADCP_10pct_down++ |
|
100 |
while ($LADCP{ENSEMBLE}[$LADCP_10pct_down]->{DEPTH} < 0.1*$LADCP{ENSEMBLE}[$LADCP_bottom]->{DEPTH}); |
|
101 |
||
102 |
$first_guess_lag = ($LADCP{ENSEMBLE}[$LADCP_10pct_down]->{ELAPSED_TIME} - |
|
103 |
$CTD_10pct_down*$CTD{sampint}) / $CTD{sampint}; |
|
104 |
||
105 |
printf(STDERR "\n\t1st guess offset [CTD pressure, LADCP estimated depth] = %ds [%ddbar, %dm]\n", |
|
106 |
$first_guess_lag*$CTD{sampint},$CTD{press}[$CTD_10pct_down],$LADCP{ENSEMBLE}[$LADCP_10pct_down]->{DEPTH}) |
|
107 |
if ($opt_d); |
|
108 |
} |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
109 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
110 |
#------------------------------------------------------------------------------------ |
1 | 111 |
# Linearly interpolate LADCP time series onto a new grid with $CTD{sampint} resolution |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
112 |
# ALSO: apply first_guess_lag to make lags small, which keeps the bestlag data |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
113 |
# chunks large |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
114 |
#------------------------------------------------------------------------------------ |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
115 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
116 |
$nGaps = 0; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
117 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
118 |
for (my($ens)=$LADCP_start,my($r)=0; $ens<=$LADCP_end; $ens++) { |
1 | 119 |
while ($r*$CTD{sampint} < $LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}) { |
14 | 120 |
unless ($first_guess_lag > $r) { |
29 | 121 |
my($w) = interp_LADCP_w($r*$CTD{sampint},$ens); |
122 |
next if (!defined($firstValid) && !defined($w)); |
|
14 | 123 |
$firstValid = $r-$first_guess_lag unless defined($firstValid); |
29 | 124 |
die("assertion failed") unless defined($w); |
125 |
$LADCP_w[$r-$first_guess_lag] = $w; |
|
14 | 126 |
$nValid++; |
127 |
} |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
128 |
$r++; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
129 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
130 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
131 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
132 |
print(STDERR "\t$nGaps gaps in w timeseries") |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
133 |
if ($opt_d); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
134 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
135 |
print(STDERR "\n"); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
136 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
137 |
#---------------------------------------------------------------------- |
29 | 138 |
# Output w Time Series |
139 |
#---------------------------------------------------------------------- |
|
140 |
||
141 |
# open(F,'>bestLag.out'); |
|
142 |
# print(F "#ANTS#FIELDS# {rec} {LADCP_w} {CTD_w}\n"); |
|
143 |
# for (my($r)=$firstValid; $r<$firstValid+$nValid; $r++) { |
|
144 |
# print(F "$r $LADCP_w[$r] $CTD{w}[$r]\n"); |
|
145 |
# } |
|
146 |
# close(F); |
|
147 |
||
148 |
#---------------------------------------------------------------------- |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
149 |
# Calculate lags |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
150 |
#---------------------------------------------------------------------- |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
151 |
|
1 | 152 |
printf(STDERR "\tcalculating $opt_n lags from %ds-long windows [s]:",$opt_w); |
153 |
$opt_w = int($opt_w / $CTD{sampint}); |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
154 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
155 |
#--------------------------------------------------------------- |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
156 |
# carry out opt_n lag correlations and keep tally of the results |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
157 |
#--------------------------------------------------------------- |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
158 |
my(%nBest); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
159 |
my($nLags) = 0; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
160 |
my($lags) = ''; |
1 | 161 |
my($lastLag) = 9e99; my($nSame) = 1; |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
162 |
for (my($window)=0; $window<$opt_n; $window++) { |
14 | 163 |
my($ws) = $firstValid + $window * int($nValid/$opt_n); # window start |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
164 |
$ws = @LADCP_w-$opt_w if ($ws+$opt_w >= @LADCP_w); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
165 |
$bestLag = bestLag($ws); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
166 |
if (defined($bestLag)) { |
1 | 167 |
if (defined($lastLag) && $bestLag == $lastLag) { |
168 |
$nSame++; |
|
169 |
} else { |
|
170 |
printf(STDERR "(x%d)",$nSame) |
|
171 |
if ($nSame > 1); |
|
172 |
printf(STDERR " %d",$bestLag*$CTD{sampint}); |
|
173 |
$nSame = 1; |
|
174 |
$lastLag = $bestLag; |
|
175 |
} |
|
176 |
$lags .= sprintf(" %s",$bestLag*$CTD{sampint}); |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
177 |
$nBest{$bestLag}++; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
178 |
$nLags++; |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
179 |
} else { |
1 | 180 |
if (!defined($lastLag)) { |
181 |
$nSame++; |
|
182 |
} else { |
|
183 |
printf(STDERR "(x%d)",$nSame) |
|
184 |
if ($nSame > 1); |
|
185 |
printf(STDERR " nan"); |
|
186 |
$nSame = 1; |
|
187 |
$lastLag = $bestLag; |
|
188 |
} |
|
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
189 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
190 |
} |
1 | 191 |
printf(STDERR "(x%d)",$nSame) if ($nSame > 1); |
20 | 192 |
&antsAddParams('LADCPproc::time_lags',$lags); |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
193 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
194 |
#---------------------- |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
195 |
# find most popular lag |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
196 |
#---------------------- |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
197 |
my($best_lag); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
198 |
foreach my $i (keys(%nBest)) { |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
199 |
$best_lag = $i if ($nBest{$i} > $nBest{$best_lag}); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
200 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
201 |
croak("\n$0: cannot determine a valid lag\n") |
30
8697ba5a88ec
before beginning to add code to calculate package velocity
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
25
diff
changeset
|
202 |
unless ($opt_z || $nBest{$best_lag}>$opt_n/3); |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
203 |
print(STDERR "\n\n\t\tWARNING: only $nBest{$best_lag} of the lag estimates agree!\n") |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
204 |
if ($nBest{$best_lag} < $opt_n/2); |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
205 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
206 |
if ($nBest{$best_lag} == $nLags) { |
6 | 207 |
printf(STDERR "\n\t\tunanimous lag = %ds\n",($first_guess_lag+$best_lag)*$CTD{sampint}); |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
208 |
} else { |
6 | 209 |
printf(STDERR "\n\t\tmost popular lag = %ds\n",($first_guess_lag+$best_lag)*$CTD{sampint}); |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
210 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
211 |
|
1 | 212 |
return ($first_guess_lag + $best_lag) * $CTD{sampint}; |
0
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
213 |
} |
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
214 |
|
de00d0f32431
initial version to process P403 yoyo
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff
changeset
|
215 |
1; |