author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sun, 12 Apr 2020 19:52:19 -0400 | |
changeset 50 | 6bfec705d25e |
parent 45 | 5767cbe470a0 |
child 51 | 148c092b3a09 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# M E A N P R O F |
|
4 |
# doc: Fri Feb 22 08:40:18 2008 |
|
44 | 5 |
# dlm: Fri Aug 24 13:45:21 2018 |
0 | 6 |
# (c) 2008 A.M. Thurnherr |
44 | 7 |
# uE-Info: 15 71 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 8 |
#====================================================================== |
9 |
||
10 |
# extract time-averaged mean profile from ADCP data |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Feb 22, 2008: - created from [listBins] |
|
33 | 14 |
# Mar 16, 2016: - adapted to new Getopt library |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
15 |
# Apr 2, 2018: - BUG: velBeamToInstrument() used old usage |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
16 |
# Apr 9, 2018: - adapted to "new" readData() ensemble limits |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
17 |
# - added -l to set final bin |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
18 |
# - BUG: division by zero in empty bins |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
19 |
# Apr 10, 2018: - activate output |
44 | 20 |
# Aug 24, 2018: - BUG: code bombed when there are no 4-beam solutions |
0 | 21 |
|
22 |
# Soundspeed Correction: |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
23 |
# - based on first ensemble only |
0 | 24 |
# - applied as described in the RDI coord-trans manual |
25 |
# - sound-speed variation over range is ignored (valid for small gradients) |
|
26 |
# => - same simple correction for all velocity components |
|
27 |
# - simple correction for cell depths |
|
28 |
||
33 | 29 |
use Getopt::Std; |
30 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
31 |
$ADCP_tools_minVersion = 2.2; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
32 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
33 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
0 | 34 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
35 |
die("Usage: $0 [-r)ange <first_ens,last_ens>] [-l)ast <bin>] " . |
0 | 36 |
"[-Q)uiet (stats only)] " . |
37 |
"[-S)oundspeed correction <salin|*,temp|*,depth|*> " . |
|
38 |
"[require -4)-beam solutions] [-d)iscard <beam#>] " . |
|
39 |
"[-%)good <min>] " . |
|
40 |
"[output -b)eam coordinates] " . |
|
41 |
"[-M)agnetic <declination>] " . |
|
42 |
"[-D)epth <depth>] " . |
|
43 |
"<RDI file>\n") |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
44 |
unless (&getopts("4bd:D:l:M:p:r:QS:") && @ARGV == 1); |
0 | 45 |
|
46 |
die("$0: -4 and -d are mutually exclusive\n") |
|
47 |
if ($opt_4 && defined($opt_d)); |
|
48 |
||
49 |
die("$0: -p and -b are mutually exclusive\n") |
|
50 |
if ($opt_b && defined($opt_p)); |
|
51 |
||
52 |
$opt_p = 0 unless defined($opt_p); |
|
53 |
||
54 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
|
55 |
||
56 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
57 |
unless defined($opt_M) || defined($opt_b); |
|
58 |
||
59 |
$ifn = $ARGV[0]; |
|
60 |
||
61 |
($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S) |
|
62 |
if defined($opt_S); |
|
63 |
die("$0: Cannot do variable soundspeed correction (implementation restriction)\n") |
|
64 |
if ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
|
65 |
||
66 |
#---------------------------------------------------------------------- |
|
67 |
# Read & Check Data, Transform Velocities |
|
68 |
#---------------------------------------------------------------------- |
|
69 |
||
70 |
$P{RDI_file} = $ifn; |
|
71 |
$P{mag_decl} = $opt_M if defined($opt_M); |
|
72 |
||
73 |
print(STDERR "reading $ifn: "); |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
74 |
if (defined($opt_r)) { # read selected range |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
75 |
my($fe,$le) = split(',',$opt_r); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
76 |
readData($ifn,\%dta,$fe,$le,$opt_l); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
77 |
} else { # read entire file |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
78 |
readData($ifn,\%dta,undef,undef,$opt_l); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
79 |
} |
0 | 80 |
printf(STDERR "%d complete ensembles.\n",scalar(@{$dta{ENSEMBLE}})); |
81 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
82 |
||
83 |
if ($dta{BEAM_COORDINATES}) { # coords |
|
84 |
$beamCoords = 1; |
|
85 |
} else { |
|
86 |
die("$0: -b requires input in beam coordinates\n") |
|
87 |
if ($opt_b); |
|
88 |
die("$ifn: only beam and earth coordinates implemented so far\n") |
|
89 |
if (!$dta{EARTH_COORDINATES}); |
|
90 |
} |
|
91 |
||
92 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { # calc dz |
|
93 |
$dz[$b] = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
94 |
} |
|
95 |
||
96 |
$lastGoodBin = 0; |
|
97 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { # check/transform velocities |
|
98 |
$P{first_ens} = $dta{ENSEMBLE}[$e]->{NUMBER},$fe = $e |
|
99 |
unless defined($P{first_ens}); |
|
100 |
$P{last_ens} = $dta{ENSEMBLE}[$e]->{NUMBER}; |
|
101 |
$le = $e; |
|
102 |
||
103 |
die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
104 |
if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4); |
|
105 |
die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
106 |
if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
107 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
108 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN}); |
|
109 |
||
110 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { |
|
111 |
if (defined($opt_d)) { |
|
112 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]); |
|
113 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]); |
|
114 |
} |
|
115 |
for (my($i)=0; $i<4; $i++) { |
|
116 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i] < $opt_p) { |
|
117 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i]); |
|
118 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$i]); |
|
119 |
} |
|
120 |
} |
|
121 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = $beamCoords |
|
122 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
123 |
velBeamToInstrument(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}) |
0 | 124 |
) |
125 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}) |
|
126 |
unless ($opt_b); |
|
127 |
||
128 |
$sum_corr1[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][0]; |
|
129 |
$sum_corr2[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][1]; |
|
130 |
$sum_corr3[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][2]; |
|
131 |
$sum_corr4[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][3]; |
|
132 |
||
133 |
$sum_amp1[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][0]; |
|
134 |
$sum_amp2[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][1]; |
|
135 |
$sum_amp3[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][2]; |
|
136 |
$sum_amp4[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][3]; |
|
137 |
||
138 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { |
|
139 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
|
140 |
next; |
|
141 |
} |
|
142 |
||
143 |
$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b] = $RDI_Coords::threeBeamFlag; |
|
144 |
$three_beam[$b] += $RDI_Coords::threeBeamFlag; |
|
145 |
$dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b] = 1; |
|
146 |
$good_vels[$b]++; |
|
147 |
$lastGoodBin = $b if ($b > $lastGoodBin); |
|
148 |
$firstGoodEns = $e unless defined($firstGoodEns); |
|
149 |
$lastGoodEns = $e; |
|
150 |
||
151 |
$sum_u[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]; |
|
152 |
$sum_v[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]; |
|
153 |
$sum_w[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]; |
|
154 |
$sum_e[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] |
|
155 |
unless ($RDI_Coords::threeBeamFlag); |
|
156 |
||
157 |
$sum_pcg1[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]; |
|
158 |
$n_pcg1[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]); |
|
159 |
$sum_pcg2[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]; |
|
160 |
$n_pcg2[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]); |
|
161 |
$sum_pcg3[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]; |
|
162 |
$n_pcg3[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]); |
|
163 |
$sum_pcg4[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]; |
|
164 |
$n_pcg4[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
unless (defined($opt_r)) { |
|
169 |
$fe = $firstGoodEns; |
|
170 |
$le = $lastGoodEns; |
|
171 |
} |
|
172 |
$nEns = $le - $fe + 1; |
|
173 |
die("$0: insufficient data\n") if ($nEns < 2); |
|
174 |
$P{N_ensembles} = $nEns; |
|
175 |
||
176 |
$firstBin = 0; |
|
177 |
$lastBin = $lastGoodBin; |
|
178 |
||
179 |
print( STDERR "Start : $dta{ENSEMBLE}[$fe]->{DATE} $dta{ENSEMBLE}[$fe]->{TIME}\n"); |
|
180 |
print( STDERR "End : $dta{ENSEMBLE}[$le]->{DATE} $dta{ENSEMBLE}[$le]->{TIME}\n"); |
|
181 |
printf(STDERR "Bins : %d-%d\n",$firstBin+1,$lastBin+1); |
|
182 |
printf(STDERR "3-Beam : %d %d %d %d\n",$RDI_Coords::threeBeam_1, |
|
183 |
$RDI_Coords::threeBeam_2, |
|
184 |
$RDI_Coords::threeBeam_3, |
|
185 |
$RDI_Coords::threeBeam_4) |
|
186 |
unless ($opt_b); |
|
187 |
||
188 |
#---------------------------------------------------------------------- |
|
189 |
# Calculate Stddevs |
|
190 |
#---------------------------------------------------------------------- |
|
191 |
||
192 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
193 |
$mean_corr1[$b] = $sum_corr1[$b] / $nEns; $mean_corr2[$b] = $sum_corr2[$b] / $nEns; |
|
194 |
$mean_corr3[$b] = $sum_corr3[$b] / $nEns; $mean_corr4[$b] = $sum_corr4[$b] / $nEns; |
|
195 |
$mean_amp1[$b] = $sum_amp1[$b] / $nEns; $mean_amp2[$b] = $sum_amp2[$b] / $nEns; |
|
196 |
$mean_amp3[$b] = $sum_amp3[$b] / $nEns; $mean_amp4[$b] = $sum_amp4[$b] / $nEns; |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
197 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
198 |
$mean_pcg1[$b] = $sum_pcg1[$b] / $n_pcg1[$b] if ($n_pcg1[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
199 |
$mean_pcg2[$b] = $sum_pcg2[$b] / $n_pcg2[$b] if ($n_pcg2[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
200 |
$mean_pcg3[$b] = $sum_pcg3[$b] / $n_pcg3[$b] if ($n_pcg3[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
201 |
$mean_pcg4[$b] = $sum_pcg4[$b] / $n_pcg4[$b] if ($n_pcg4[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
202 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
203 |
next unless ($good_vels[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
204 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
205 |
$mean_u[$b] = $sum_u[$b] / $good_vels[$b]; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
206 |
$mean_v[$b] = $sum_v[$b] / $good_vels[$b]; |
0 | 207 |
$mean_w[$b] = $sum_w[$b] / $good_vels[$b]; |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
208 |
$mean_e[$b] = ($good_vels[$b] - $three_beam[$b] > 0) ? $sum_e[$b] / ($good_vels[$b] - $three_beam[$b]) : undef; |
0 | 209 |
} |
210 |
||
211 |
for ($e=$fe; $e<=$le; $e++) { |
|
212 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
213 |
$sumsq_corr1[$b] += ($mean_corr1[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][0])**2; |
|
214 |
$sumsq_corr2[$b] += ($mean_corr2[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][1])**2; |
|
215 |
$sumsq_corr3[$b] += ($mean_corr3[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][2])**2; |
|
216 |
$sumsq_corr4[$b] += ($mean_corr4[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][3])**2; |
|
217 |
||
218 |
$sumsq_amp1[$b] += ($mean_amp1[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][0])**2; |
|
219 |
$sumsq_amp2[$b] += ($mean_amp2[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][1])**2; |
|
220 |
$sumsq_amp3[$b] += ($mean_amp3[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][2])**2; |
|
221 |
$sumsq_amp4[$b] += ($mean_amp4[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][3])**2; |
|
222 |
||
223 |
$sumsq_pcg1[$b] += ($mean_pcg1[$b] - $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0])**2 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
224 |
if defined($mean_pcg1[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]); |
0 | 225 |
$sumsq_pcg2[$b] += ($mean_pcg2[$b] - $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1])**2 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
226 |
if defined($mean_pcg2[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]); |
0 | 227 |
$sumsq_pcg3[$b] += ($mean_pcg3[$b] - $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2])**2 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
228 |
if defined($mean_pcg3[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]); |
0 | 229 |
$sumsq_pcg4[$b] += ($mean_pcg4[$b] - $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3])**2 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
230 |
if defined($mean_pcg4[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
0 | 231 |
|
232 |
next unless ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]); |
|
233 |
||
234 |
$sumsq_u[$b] += ($mean_u[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])**2; |
|
235 |
$sumsq_v[$b] += ($mean_v[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])**2; |
|
236 |
$sumsq_w[$b] += ($mean_w[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])**2; |
|
237 |
||
238 |
next if ($dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]); |
|
239 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
240 |
$sumsq_e[$b] += ($mean_e[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])**2 |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
241 |
if defined($mean_e[$b]); |
0 | 242 |
} |
243 |
} |
|
244 |
||
245 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
246 |
$var_corr1[$b] = $sumsq_corr1[$b] / ($nEns-1); $var_corr2[$b] = $sumsq_corr2[$b] / ($nEns-1); |
|
247 |
$var_corr3[$b] = $sumsq_corr3[$b] / ($nEns-1); $var_corr4[$b] = $sumsq_corr4[$b] / ($nEns-1); |
|
248 |
$var_amp1[$b] = $sumsq_amp1[$b] / ($nEns-1); $var_amp2[$b] = $sumsq_amp2[$b] / ($nEns-1); |
|
249 |
$var_amp3[$b] = $sumsq_amp3[$b] / ($nEns-1); $var_amp4[$b] = $sumsq_amp4[$b] / ($nEns-1); |
|
250 |
$var_pcg1[$b] = $sumsq_pcg1[$b] / ($n_pcg1[$b]-1) if ($n_pcg1[$b] > 1); |
|
251 |
$var_pcg2[$b] = $sumsq_pcg2[$b] / ($n_pcg2[$b]-1) if ($n_pcg2[$b] > 1); |
|
252 |
$var_pcg3[$b] = $sumsq_pcg3[$b] / ($n_pcg3[$b]-1) if ($n_pcg3[$b] > 1); |
|
253 |
$var_pcg4[$b] = $sumsq_pcg4[$b] / ($n_pcg4[$b]-1) if ($n_pcg4[$b] > 1); |
|
254 |
next unless ($good_vels[$b] > 1); |
|
255 |
$var_u[$b] = $sumsq_u[$b] / ($good_vels[$b]-1); |
|
256 |
$var_v[$b] = $sumsq_v[$b] / ($good_vels[$b]-1); |
|
257 |
$var_w[$b] = $sumsq_w[$b] / ($good_vels[$b]-1); |
|
258 |
next unless ($good_vels[$b] - $three_beam[$b] > 1); |
|
259 |
$var_e[$b] = $sumsq_e[$b] / ($good_vels[$b] - $three_beam[$b] - 1); |
|
260 |
} |
|
261 |
||
262 |
#---------------------------------------------------------------------- |
|
263 |
# Calculate Beam Statistics |
|
264 |
#---------------------------------------------------------------------- |
|
265 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
266 |
# not implemented yet |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
267 |
|
0 | 268 |
#---------------------------------------------------------------------- |
269 |
# Produce Output |
|
270 |
#---------------------------------------------------------------------- |
|
271 |
||
272 |
unless ($opt_Q) { |
|
273 |
my($ssCorr) = defined($opt_S) |
|
274 |
? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) |
|
275 |
: 1; |
|
276 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
277 |
print("#!/usr/bin/perl -S list\n"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
278 |
chmod(0777&~umask,*STDOUT); |
0 | 279 |
print("#ANTS#PARAMS# "); |
280 |
foreach my $k (keys(%P)) { |
|
281 |
print("$k\{$P{$k}\} "); |
|
282 |
} |
|
283 |
printf("soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!'); |
|
284 |
print("\n"); |
|
285 |
||
286 |
print("#ANTS#FIELDS# " . |
|
287 |
"{bin} {dz} " . |
|
288 |
(defined($opt_D) ? "{depth} " : "") . |
|
289 |
($opt_b ? "{v1} {v2} {v3} {v4} " : "{u} {v} {w} {err_vel} ") . |
|
290 |
($opt_b ? "{sig_v1} {sig_v2} {sig_v3} {sig_v4} " : "{sig_u} {sig_v} {sig_w} {sig_err_vel} ") . |
|
291 |
"{corr1} {corr2} {corr3} {corr4} " . |
|
292 |
"{sig_corr1} {sig_corr2} {sig_corr3} {sig_corr4} " . |
|
293 |
"{amp1} {amp2} {amp3} {amp4} " . |
|
294 |
"{sig_amp1} {sig_amp2} {sig_amp3} {sig_amp4} " . |
|
295 |
"{pcg1} {pcg2} {pcg3} {pcg4} " . |
|
296 |
"{sig_pcg1} {sig_pcg2} {sig_pcg3} {sig_pcg4}" . |
|
297 |
"\n" |
|
298 |
); |
|
299 |
||
300 |
for ($b=$firstBin; $b<=$lastBin; $b++) { |
|
301 |
printf("%d %.1f ",$b+1,$dz[$b]*$ssCorr); |
|
302 |
printf("%.1f ",$opt_D - $dz[$b]*$ssCorr) |
|
303 |
if defined($opt_D); |
|
304 |
||
305 |
printf("%s ",defined($mean_u[$b]) ? $mean_u[$b] : nan); |
|
306 |
printf("%s ",defined($mean_v[$b]) ? $mean_v[$b] : nan); |
|
307 |
printf("%s ",defined($mean_w[$b]) ? $mean_w[$b] : nan); |
|
308 |
printf("%s ",defined($mean_e[$b]) ? $mean_e[$b] : nan); |
|
309 |
||
310 |
printf("%s ",defined($var_u[$b]) ? sqrt($var_u[$b]) : nan); |
|
311 |
printf("%s ",defined($var_v[$b]) ? sqrt($var_v[$b]) : nan); |
|
312 |
printf("%s ",defined($var_w[$b]) ? sqrt($var_w[$b]) : nan); |
|
313 |
printf("%s ",defined($var_e[$b]) ? sqrt($var_e[$b]) : nan); |
|
314 |
||
315 |
printf("%g %g %g %g ",$mean_corr1[$b],$mean_corr2[$b], |
|
316 |
$mean_corr3[$b],$mean_corr4[$b]); |
|
317 |
printf("%g %g %g %g ",sqrt($var_corr1[$b]),sqrt($var_corr2[$b]), |
|
318 |
sqrt($var_corr3[$b]),sqrt($var_corr4[$b])); |
|
319 |
||
320 |
printf("%g %g %g %g ",$mean_amp1[$b],$mean_amp2[$b], |
|
321 |
$mean_amp3[$b],$mean_amp4[$b]); |
|
322 |
printf("%g %g %g %g ",sqrt($var_amp1[$b]),sqrt($var_amp2[$b]), |
|
323 |
sqrt($var_amp3[$b]),sqrt($var_amp4[$b])); |
|
324 |
||
325 |
if ($good_vels[$b] > 0) { |
|
326 |
printf("%g %g %g %g ",$mean_pcg1[$b],$mean_pcg2[$b], |
|
327 |
$mean_pcg3[$b],$mean_pcg4[$b]); |
|
328 |
printf("%g %g %g %g\n",sqrt($var_pcg1[$b]),sqrt($var_pcg2[$b]), |
|
329 |
sqrt($var_pcg3[$b]),sqrt($var_pcg4[$b])); |
|
330 |
} else { |
|
331 |
print("nan nan nan nan "); |
|
332 |
print("nan nan nan nan\n"); |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
exit(0); |