author | A.M. Thurnherr <athurnherr@yahoo.com> |
Tue, 29 Jun 2021 12:21:32 -0400 | |
changeset 59 | 4f4530fa35da |
parent 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 |
|
51
148c092b3a09
after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
5 |
# dlm: Sat Jul 27 08:27:45 2019 |
0 | 6 |
# (c) 2008 A.M. Thurnherr |
51
148c092b3a09
after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
7 |
# uE-Info: 56 36 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>] " . |
|
51
148c092b3a09
after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
43 |
"[-v)erbose (show progress) " . |
0 | 44 |
"<RDI file>\n") |
51
148c092b3a09
after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
45 |
unless (&getopts("4bd:D:l:M:p:r:QS:v") && @ARGV == 1); |
0 | 46 |
|
47 |
die("$0: -4 and -d are mutually exclusive\n") |
|
48 |
if ($opt_4 && defined($opt_d)); |
|
49 |
||
50 |
die("$0: -p and -b are mutually exclusive\n") |
|
51 |
if ($opt_b && defined($opt_p)); |
|
52 |
||
53 |
$opt_p = 0 unless defined($opt_p); |
|
54 |
||
55 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
|
51
148c092b3a09
after somewhat suspicous RDI_PD0_IO.pl merge and just before adding
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
56 |
$RDI_PD0_IO::show_progress = $opt_v; |
0 | 57 |
|
58 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
59 |
unless defined($opt_M) || defined($opt_b); |
|
60 |
||
61 |
$ifn = $ARGV[0]; |
|
62 |
||
63 |
($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S) |
|
64 |
if defined($opt_S); |
|
65 |
die("$0: Cannot do variable soundspeed correction (implementation restriction)\n") |
|
66 |
if ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
|
67 |
||
68 |
#---------------------------------------------------------------------- |
|
69 |
# Read & Check Data, Transform Velocities |
|
70 |
#---------------------------------------------------------------------- |
|
71 |
||
72 |
$P{RDI_file} = $ifn; |
|
73 |
$P{mag_decl} = $opt_M if defined($opt_M); |
|
74 |
||
75 |
print(STDERR "reading $ifn: "); |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
76 |
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
|
77 |
my($fe,$le) = split(',',$opt_r); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
78 |
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
|
79 |
} else { # read entire file |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
80 |
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
|
81 |
} |
0 | 82 |
printf(STDERR "%d complete ensembles.\n",scalar(@{$dta{ENSEMBLE}})); |
83 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
84 |
||
85 |
if ($dta{BEAM_COORDINATES}) { # coords |
|
86 |
$beamCoords = 1; |
|
87 |
} else { |
|
88 |
die("$0: -b requires input in beam coordinates\n") |
|
89 |
if ($opt_b); |
|
90 |
die("$ifn: only beam and earth coordinates implemented so far\n") |
|
91 |
if (!$dta{EARTH_COORDINATES}); |
|
92 |
} |
|
93 |
||
94 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { # calc dz |
|
95 |
$dz[$b] = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
96 |
} |
|
97 |
||
98 |
$lastGoodBin = 0; |
|
99 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { # check/transform velocities |
|
100 |
$P{first_ens} = $dta{ENSEMBLE}[$e]->{NUMBER},$fe = $e |
|
101 |
unless defined($P{first_ens}); |
|
102 |
$P{last_ens} = $dta{ENSEMBLE}[$e]->{NUMBER}; |
|
103 |
$le = $e; |
|
104 |
||
105 |
die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
106 |
if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4); |
|
107 |
die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
108 |
if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
109 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
110 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN}); |
|
111 |
||
112 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { |
|
113 |
if (defined($opt_d)) { |
|
114 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]); |
|
115 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]); |
|
116 |
} |
|
117 |
for (my($i)=0; $i<4; $i++) { |
|
118 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i] < $opt_p) { |
|
119 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i]); |
|
120 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$i]); |
|
121 |
} |
|
122 |
} |
|
123 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = $beamCoords |
|
124 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
125 |
velBeamToInstrument(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}) |
0 | 126 |
) |
127 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}) |
|
128 |
unless ($opt_b); |
|
129 |
||
130 |
$sum_corr1[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][0]; |
|
131 |
$sum_corr2[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][1]; |
|
132 |
$sum_corr3[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][2]; |
|
133 |
$sum_corr4[$b] += $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][3]; |
|
134 |
||
135 |
$sum_amp1[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][0]; |
|
136 |
$sum_amp2[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][1]; |
|
137 |
$sum_amp3[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][2]; |
|
138 |
$sum_amp4[$b] += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][3]; |
|
139 |
||
140 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { |
|
141 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
|
142 |
next; |
|
143 |
} |
|
144 |
||
145 |
$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b] = $RDI_Coords::threeBeamFlag; |
|
146 |
$three_beam[$b] += $RDI_Coords::threeBeamFlag; |
|
147 |
$dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b] = 1; |
|
148 |
$good_vels[$b]++; |
|
149 |
$lastGoodBin = $b if ($b > $lastGoodBin); |
|
150 |
$firstGoodEns = $e unless defined($firstGoodEns); |
|
151 |
$lastGoodEns = $e; |
|
152 |
||
153 |
$sum_u[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]; |
|
154 |
$sum_v[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]; |
|
155 |
$sum_w[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]; |
|
156 |
$sum_e[$b] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] |
|
157 |
unless ($RDI_Coords::threeBeamFlag); |
|
158 |
||
159 |
$sum_pcg1[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]; |
|
160 |
$n_pcg1[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]); |
|
161 |
$sum_pcg2[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]; |
|
162 |
$n_pcg2[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]); |
|
163 |
$sum_pcg3[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]; |
|
164 |
$n_pcg3[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]); |
|
165 |
$sum_pcg4[$b] += $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]; |
|
166 |
$n_pcg4[$b]++ if defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
unless (defined($opt_r)) { |
|
171 |
$fe = $firstGoodEns; |
|
172 |
$le = $lastGoodEns; |
|
173 |
} |
|
174 |
$nEns = $le - $fe + 1; |
|
175 |
die("$0: insufficient data\n") if ($nEns < 2); |
|
176 |
$P{N_ensembles} = $nEns; |
|
177 |
||
178 |
$firstBin = 0; |
|
179 |
$lastBin = $lastGoodBin; |
|
180 |
||
181 |
print( STDERR "Start : $dta{ENSEMBLE}[$fe]->{DATE} $dta{ENSEMBLE}[$fe]->{TIME}\n"); |
|
182 |
print( STDERR "End : $dta{ENSEMBLE}[$le]->{DATE} $dta{ENSEMBLE}[$le]->{TIME}\n"); |
|
183 |
printf(STDERR "Bins : %d-%d\n",$firstBin+1,$lastBin+1); |
|
184 |
printf(STDERR "3-Beam : %d %d %d %d\n",$RDI_Coords::threeBeam_1, |
|
185 |
$RDI_Coords::threeBeam_2, |
|
186 |
$RDI_Coords::threeBeam_3, |
|
187 |
$RDI_Coords::threeBeam_4) |
|
188 |
unless ($opt_b); |
|
189 |
||
190 |
#---------------------------------------------------------------------- |
|
191 |
# Calculate Stddevs |
|
192 |
#---------------------------------------------------------------------- |
|
193 |
||
194 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
195 |
$mean_corr1[$b] = $sum_corr1[$b] / $nEns; $mean_corr2[$b] = $sum_corr2[$b] / $nEns; |
|
196 |
$mean_corr3[$b] = $sum_corr3[$b] / $nEns; $mean_corr4[$b] = $sum_corr4[$b] / $nEns; |
|
197 |
$mean_amp1[$b] = $sum_amp1[$b] / $nEns; $mean_amp2[$b] = $sum_amp2[$b] / $nEns; |
|
198 |
$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
|
199 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
200 |
$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
|
201 |
$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
|
202 |
$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
|
203 |
$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
|
204 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
205 |
next unless ($good_vels[$b] > 0); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
206 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
207 |
$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
|
208 |
$mean_v[$b] = $sum_v[$b] / $good_vels[$b]; |
0 | 209 |
$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
|
210 |
$mean_e[$b] = ($good_vels[$b] - $three_beam[$b] > 0) ? $sum_e[$b] / ($good_vels[$b] - $three_beam[$b]) : undef; |
0 | 211 |
} |
212 |
||
213 |
for ($e=$fe; $e<=$le; $e++) { |
|
214 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
215 |
$sumsq_corr1[$b] += ($mean_corr1[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][0])**2; |
|
216 |
$sumsq_corr2[$b] += ($mean_corr2[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][1])**2; |
|
217 |
$sumsq_corr3[$b] += ($mean_corr3[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][2])**2; |
|
218 |
$sumsq_corr4[$b] += ($mean_corr4[$b] - $dta{ENSEMBLE}[$e]->{CORRELATION}[$b][3])**2; |
|
219 |
||
220 |
$sumsq_amp1[$b] += ($mean_amp1[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][0])**2; |
|
221 |
$sumsq_amp2[$b] += ($mean_amp2[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][1])**2; |
|
222 |
$sumsq_amp3[$b] += ($mean_amp3[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][2])**2; |
|
223 |
$sumsq_amp4[$b] += ($mean_amp4[$b] - $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][3])**2; |
|
224 |
||
225 |
$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
|
226 |
if defined($mean_pcg1[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]); |
0 | 227 |
$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
|
228 |
if defined($mean_pcg2[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1]); |
0 | 229 |
$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
|
230 |
if defined($mean_pcg3[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2]); |
0 | 231 |
$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
|
232 |
if defined($mean_pcg4[$b]) && defined($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
0 | 233 |
|
234 |
next unless ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]); |
|
235 |
||
236 |
$sumsq_u[$b] += ($mean_u[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])**2; |
|
237 |
$sumsq_v[$b] += ($mean_v[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])**2; |
|
238 |
$sumsq_w[$b] += ($mean_w[$b] - $dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])**2; |
|
239 |
||
240 |
next if ($dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]); |
|
241 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
242 |
$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
|
243 |
if defined($mean_e[$b]); |
0 | 244 |
} |
245 |
} |
|
246 |
||
247 |
for ($b=0; $b<=$lastGoodBin; $b++) { |
|
248 |
$var_corr1[$b] = $sumsq_corr1[$b] / ($nEns-1); $var_corr2[$b] = $sumsq_corr2[$b] / ($nEns-1); |
|
249 |
$var_corr3[$b] = $sumsq_corr3[$b] / ($nEns-1); $var_corr4[$b] = $sumsq_corr4[$b] / ($nEns-1); |
|
250 |
$var_amp1[$b] = $sumsq_amp1[$b] / ($nEns-1); $var_amp2[$b] = $sumsq_amp2[$b] / ($nEns-1); |
|
251 |
$var_amp3[$b] = $sumsq_amp3[$b] / ($nEns-1); $var_amp4[$b] = $sumsq_amp4[$b] / ($nEns-1); |
|
252 |
$var_pcg1[$b] = $sumsq_pcg1[$b] / ($n_pcg1[$b]-1) if ($n_pcg1[$b] > 1); |
|
253 |
$var_pcg2[$b] = $sumsq_pcg2[$b] / ($n_pcg2[$b]-1) if ($n_pcg2[$b] > 1); |
|
254 |
$var_pcg3[$b] = $sumsq_pcg3[$b] / ($n_pcg3[$b]-1) if ($n_pcg3[$b] > 1); |
|
255 |
$var_pcg4[$b] = $sumsq_pcg4[$b] / ($n_pcg4[$b]-1) if ($n_pcg4[$b] > 1); |
|
256 |
next unless ($good_vels[$b] > 1); |
|
257 |
$var_u[$b] = $sumsq_u[$b] / ($good_vels[$b]-1); |
|
258 |
$var_v[$b] = $sumsq_v[$b] / ($good_vels[$b]-1); |
|
259 |
$var_w[$b] = $sumsq_w[$b] / ($good_vels[$b]-1); |
|
260 |
next unless ($good_vels[$b] - $three_beam[$b] > 1); |
|
261 |
$var_e[$b] = $sumsq_e[$b] / ($good_vels[$b] - $three_beam[$b] - 1); |
|
262 |
} |
|
263 |
||
264 |
#---------------------------------------------------------------------- |
|
265 |
# Calculate Beam Statistics |
|
266 |
#---------------------------------------------------------------------- |
|
267 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
268 |
# not implemented yet |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
269 |
|
0 | 270 |
#---------------------------------------------------------------------- |
271 |
# Produce Output |
|
272 |
#---------------------------------------------------------------------- |
|
273 |
||
274 |
unless ($opt_Q) { |
|
275 |
my($ssCorr) = defined($opt_S) |
|
276 |
? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) |
|
277 |
: 1; |
|
278 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
279 |
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
|
280 |
chmod(0777&~umask,*STDOUT); |
0 | 281 |
print("#ANTS#PARAMS# "); |
282 |
foreach my $k (keys(%P)) { |
|
283 |
print("$k\{$P{$k}\} "); |
|
284 |
} |
|
285 |
printf("soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!'); |
|
286 |
print("\n"); |
|
287 |
||
288 |
print("#ANTS#FIELDS# " . |
|
289 |
"{bin} {dz} " . |
|
290 |
(defined($opt_D) ? "{depth} " : "") . |
|
291 |
($opt_b ? "{v1} {v2} {v3} {v4} " : "{u} {v} {w} {err_vel} ") . |
|
292 |
($opt_b ? "{sig_v1} {sig_v2} {sig_v3} {sig_v4} " : "{sig_u} {sig_v} {sig_w} {sig_err_vel} ") . |
|
293 |
"{corr1} {corr2} {corr3} {corr4} " . |
|
294 |
"{sig_corr1} {sig_corr2} {sig_corr3} {sig_corr4} " . |
|
295 |
"{amp1} {amp2} {amp3} {amp4} " . |
|
296 |
"{sig_amp1} {sig_amp2} {sig_amp3} {sig_amp4} " . |
|
297 |
"{pcg1} {pcg2} {pcg3} {pcg4} " . |
|
298 |
"{sig_pcg1} {sig_pcg2} {sig_pcg3} {sig_pcg4}" . |
|
299 |
"\n" |
|
300 |
); |
|
301 |
||
302 |
for ($b=$firstBin; $b<=$lastBin; $b++) { |
|
303 |
printf("%d %.1f ",$b+1,$dz[$b]*$ssCorr); |
|
304 |
printf("%.1f ",$opt_D - $dz[$b]*$ssCorr) |
|
305 |
if defined($opt_D); |
|
306 |
||
307 |
printf("%s ",defined($mean_u[$b]) ? $mean_u[$b] : nan); |
|
308 |
printf("%s ",defined($mean_v[$b]) ? $mean_v[$b] : nan); |
|
309 |
printf("%s ",defined($mean_w[$b]) ? $mean_w[$b] : nan); |
|
310 |
printf("%s ",defined($mean_e[$b]) ? $mean_e[$b] : nan); |
|
311 |
||
312 |
printf("%s ",defined($var_u[$b]) ? sqrt($var_u[$b]) : nan); |
|
313 |
printf("%s ",defined($var_v[$b]) ? sqrt($var_v[$b]) : nan); |
|
314 |
printf("%s ",defined($var_w[$b]) ? sqrt($var_w[$b]) : nan); |
|
315 |
printf("%s ",defined($var_e[$b]) ? sqrt($var_e[$b]) : nan); |
|
316 |
||
317 |
printf("%g %g %g %g ",$mean_corr1[$b],$mean_corr2[$b], |
|
318 |
$mean_corr3[$b],$mean_corr4[$b]); |
|
319 |
printf("%g %g %g %g ",sqrt($var_corr1[$b]),sqrt($var_corr2[$b]), |
|
320 |
sqrt($var_corr3[$b]),sqrt($var_corr4[$b])); |
|
321 |
||
322 |
printf("%g %g %g %g ",$mean_amp1[$b],$mean_amp2[$b], |
|
323 |
$mean_amp3[$b],$mean_amp4[$b]); |
|
324 |
printf("%g %g %g %g ",sqrt($var_amp1[$b]),sqrt($var_amp2[$b]), |
|
325 |
sqrt($var_amp3[$b]),sqrt($var_amp4[$b])); |
|
326 |
||
327 |
if ($good_vels[$b] > 0) { |
|
328 |
printf("%g %g %g %g ",$mean_pcg1[$b],$mean_pcg2[$b], |
|
329 |
$mean_pcg3[$b],$mean_pcg4[$b]); |
|
330 |
printf("%g %g %g %g\n",sqrt($var_pcg1[$b]),sqrt($var_pcg2[$b]), |
|
331 |
sqrt($var_pcg3[$b]),sqrt($var_pcg4[$b])); |
|
332 |
} else { |
|
333 |
print("nan nan nan nan "); |
|
334 |
print("nan nan nan nan\n"); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
exit(0); |