1 #====================================================================== |
1 #====================================================================== |
2 # L A D C P P R O C . B E S T L A G |
2 # L A D C P P R O C . B E S T L A G |
3 # doc: Tue Sep 28 21:58:48 2010 |
3 # doc: Tue Sep 28 21:58:48 2010 |
4 # dlm: Sat Jul 19 18:32:26 2014 |
4 # dlm: Fri Mar 6 15:53:43 2015 |
5 # (c) 2010 A.M. Thurnherr |
5 # (c) 2010 A.M. Thurnherr |
6 # uE-Info: 29 44 NIL 0 0 72 2 2 4 NIL ofnI |
6 # uE-Info: 33 0 NIL 0 0 72 2 2 4 NIL ofnI |
7 #====================================================================== |
7 #====================================================================== |
8 |
8 |
9 # TODO: |
9 # TODO: |
10 # - first lag is always(?) nan unless CTD is turned on with LADCP in water |
10 # - first lag is always(?) nan unless CTD is turned on with LADCP in water |
11 |
11 |
25 # May 18, 2012: - BUG: window start index was not always calculated correctly |
25 # May 18, 2012: - BUG: window start index was not always calculated correctly |
26 # Oct 19, 2012: - BUG: opt_i had wrong sign! |
26 # Oct 19, 2012: - BUG: opt_i had wrong sign! |
27 # Jun 25, 2013: - adapted to :: %PARAM convention |
27 # Jun 25, 2013: - adapted to :: %PARAM convention |
28 # Mar 19, 2014: - moved %PARAM to LADCPproc |
28 # Mar 19, 2014: - moved %PARAM to LADCPproc |
29 # Jul 19, 2014: - made lagging obey -z)oom |
29 # Jul 19, 2014: - made lagging obey -z)oom |
|
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 |
30 |
33 |
31 sub interp_LADCP_w($$) |
34 sub interp_LADCP_w($$) |
32 { |
35 { |
33 my($elapsed,$ens) = @_; |
36 my($elapsed,$ens) = @_; |
34 my($sc) = ($elapsed - $LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}) / |
37 my($sc) = ($elapsed - $LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}) / |
35 ($LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME} - |
38 ($LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME} - |
36 $LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}); |
39 $LADCP{ENSEMBLE}[$ens-1]->{ELAPSED_TIME}); |
37 unless (numberp($LADCP{ENSEMBLE}[$ens-1]->{W})) { |
40 unless (numberp($LADCP{ENSEMBLE}[$ens]->{W})) { |
38 $nGaps++; |
41 $nGaps++; |
39 return $LADCP{ENSEMBLE}[$ens]->{W}; |
42 $LADCP{ENSEMBLE}[$ens]->{W} = $LADCP{ENSEMBLE}[$ens-1]->{W}; |
40 } |
43 } |
41 return $LADCP{ENSEMBLE}[$ens-1]->{W} + |
44 return $LADCP{ENSEMBLE}[$ens-1]->{W} + |
42 $sc * ($LADCP{ENSEMBLE}[$ens]->{W} - $LADCP{ENSEMBLE}[$ens-1]->{W}); |
45 $sc * ($LADCP{ENSEMBLE}[$ens]->{W} - $LADCP{ENSEMBLE}[$ens-1]->{W}); |
43 } |
46 } |
44 |
47 |
113 $nGaps = 0; |
116 $nGaps = 0; |
114 |
117 |
115 for (my($ens)=$LADCP_start,my($r)=0; $ens<=$LADCP_end; $ens++) { |
118 for (my($ens)=$LADCP_start,my($r)=0; $ens<=$LADCP_end; $ens++) { |
116 while ($r*$CTD{sampint} < $LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}) { |
119 while ($r*$CTD{sampint} < $LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME}) { |
117 unless ($first_guess_lag > $r) { |
120 unless ($first_guess_lag > $r) { |
118 $LADCP_w[$r-$first_guess_lag] = interp_LADCP_w($r*$CTD{sampint},$ens); |
121 my($w) = interp_LADCP_w($r*$CTD{sampint},$ens); |
|
122 next if (!defined($firstValid) && !defined($w)); |
119 $firstValid = $r-$first_guess_lag unless defined($firstValid); |
123 $firstValid = $r-$first_guess_lag unless defined($firstValid); |
|
124 die("assertion failed") unless defined($w); |
|
125 $LADCP_w[$r-$first_guess_lag] = $w; |
120 $nValid++; |
126 $nValid++; |
121 } |
127 } |
122 $r++; |
128 $r++; |
123 } |
129 } |
124 } |
130 } |
125 |
131 |
126 print(STDERR "\t$nGaps gaps in w timeseries") |
132 print(STDERR "\t$nGaps gaps in w timeseries") |
127 if ($opt_d); |
133 if ($opt_d); |
128 |
134 |
129 print(STDERR "\n"); |
135 print(STDERR "\n"); |
|
136 |
|
137 #---------------------------------------------------------------------- |
|
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); |
130 |
147 |
131 #---------------------------------------------------------------------- |
148 #---------------------------------------------------------------------- |
132 # Calculate lags |
149 # Calculate lags |
133 #---------------------------------------------------------------------- |
150 #---------------------------------------------------------------------- |
134 |
151 |