author | A.M. Thurnherr <athurnherr@yahoo.com> |
Thu, 13 Jun 2019 20:31:30 -0400 | |
changeset 47 | 494a76548e94 |
parent 43 | b63fa355644c |
permissions | -rwxr-xr-x |
34 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# L I S T V E L S |
|
4 |
# doc: Mon Apr 25 21:12:54 2016 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
5 |
# dlm: Thu Oct 4 16:03:35 2018 |
34 | 6 |
# (c) 2016 A.M. Thurnherr |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
7 |
# uE-Info: 14 61 NIL 0 0 72 10 2 4 NIL ofnI |
34 | 8 |
#====================================================================== |
9 |
||
10 |
# list water-track velocity samples as ANTS records (PD02ANTS) |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Apr 25, 2016: - created from [listBins] |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
14 |
# Oct 4, 2016: - removed pointless transducer config check |
34 | 15 |
|
16 |
# General Notes: |
|
17 |
# - everything (e.g. beams) is numbered from 1 |
|
18 |
# - no support for BT data |
|
19 |
||
20 |
use Getopt::Std; |
|
21 |
||
42 | 22 |
$ADCP_tools_minVersion = 2.1; |
34 | 23 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
24 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
|
25 |
||
26 |
die("Usage: $0 [-r)ange <first_ens,last_ens>] [-b)ins <first_bin,last_bin>] " . |
|
27 |
"[-M)agnetic <declination>] " . |
|
28 |
"[-S)oundspeed correction <salin|*,temp|*,depth|*> " . |
|
29 |
"[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " . |
|
30 |
"[require -4)-beam solutions] [-d)iscard <beam#>] " . |
|
31 |
"<RDI file>\n") |
|
32 |
unless (&getopts("4b:B:d:M:r:P:S:") && @ARGV == 1); |
|
33 |
||
34 |
($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P); |
|
35 |
($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B); |
|
36 |
||
37 |
die("$0: -4 and -d are mutually exclusive\n") |
|
38 |
if ($opt_4 && defined($opt_d)); |
|
39 |
||
40 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
|
41 |
||
42 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
43 |
unless defined($opt_M); |
|
44 |
||
45 |
$ifn = $ARGV[0]; |
|
46 |
||
47 |
($first_ens,$last_ens) = split(',',$opt_r) if defined($opt_r); |
|
48 |
($first_bin,$last_bin) = split(',',$opt_b) if defined($opt_b); |
|
49 |
||
50 |
if (defined($opt_S)) { |
|
51 |
($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S); |
|
52 |
$variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
|
53 |
} else { |
|
54 |
print(STDERR "WARNING: no soundspeed correction applied!\n"); |
|
55 |
} |
|
56 |
||
57 |
#---------------------------------------------------------------------- |
|
58 |
# MAIN |
|
59 |
#---------------------------------------------------------------------- |
|
60 |
||
61 |
$P{RDI_file} = $ifn; |
|
62 |
$P{mag_decl} = $opt_M if defined($opt_M); |
|
63 |
||
64 |
readData($ifn,\%dta); |
|
65 |
printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}})); |
|
66 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
67 |
||
68 |
if ($dta{BEAM_COORDINATES}) { # coords |
|
69 |
$beamCoords = 1; |
|
70 |
} else { |
|
71 |
die("$ifn: only beam and earth coordinates supported\n") |
|
72 |
if (!$dta{EARTH_COORDINATES}); |
|
73 |
die("$ifn: -d requires beam-coordinate data\n") |
|
74 |
if defined($opt_d); |
|
75 |
die("$ifn: -B requires beam-coordinate data\n") |
|
76 |
if defined($opt_B); |
|
77 |
} |
|
78 |
||
79 |
$first_bin = 1 unless ($first_bin > 0); |
|
80 |
$last_bin = $dta{N_BINS}+1 unless ($last_bin >= $first_bin && $last_bin <= $dta{N_BINS}+1); |
|
81 |
||
82 |
$lastGoodBin = 0; |
|
83 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { # check/transform velocities |
|
84 |
next if (defined($first_ens) && |
|
85 |
$dta{ENSEMBLE}[$e]->{NUMBER} < $first_ens); |
|
86 |
||
87 |
$dta{ENSEMBLE}[$e]->{PITCH} -= $P{pitch_bias} |
|
88 |
if defined($dta{ENSEMBLE}[$e]->{PITCH}); |
|
89 |
$dta{ENSEMBLE}[$e]->{ROLL} -= $P{roll_bias} |
|
90 |
if defined($dta{ENSEMBLE}[$e]->{ROLL}); |
|
91 |
||
92 |
$P{first_ens} = $dta{ENSEMBLE}[$e]->{NUMBER},$fe = $e |
|
93 |
unless defined($P{first_ens}); |
|
94 |
last if (defined($last_ens) && |
|
95 |
$dta{ENSEMBLE}[$e]->{NUMBER} > $last_ens); |
|
96 |
$P{last_ens} = $dta{ENSEMBLE}[$e]->{NUMBER}; |
|
97 |
$le = $e; |
|
98 |
||
99 |
die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
100 |
if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
101 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
102 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN}); |
|
103 |
||
104 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { |
|
105 |
if ($beamCoords) { |
|
106 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] -= $P{velbias_b1} # beam-velocity biases (-B) |
|
107 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]); |
|
108 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] -= $P{velbias_b2} |
|
109 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]); |
|
110 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] -= $P{velbias_b3} |
|
111 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]); |
|
112 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] -= $P{velbias_b4} |
|
113 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3]); |
|
114 |
||
115 |
if (defined($opt_d)) { # discard data from given beam (-d) |
|
116 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]); |
|
117 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]); |
|
118 |
} |
|
119 |
||
120 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # save beam velocities |
|
121 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}; |
|
122 |
||
123 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate w12, w34 |
|
124 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
125 |
||
126 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = # calculate earth velocities |
|
127 |
velBeamToEarth(\%dta,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
128 |
$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b] = $RDI_Coords::threeBeamFlag; |
|
129 |
$three_beam[$b] += $RDI_Coords::threeBeamFlag; |
|
130 |
||
131 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { |
|
132 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); # not sure when this can happen |
|
133 |
next; |
|
134 |
} |
|
135 |
} else { # Earth coordinates |
|
136 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # calculate beam velocities |
|
137 |
velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
138 |
||
139 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate w12, w34 |
|
140 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
141 |
||
142 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = # correct for heading bias |
|
143 |
velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
144 |
||
145 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { |
|
146 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); # not sure when/if this can happen |
|
147 |
next; |
|
148 |
} |
|
149 |
||
150 |
} |
|
151 |
||
152 |
$dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b] = 1; |
|
153 |
$good_vels[$b]++; |
|
154 |
$lastGoodBin = $b if ($b > $lastGoodBin); |
|
155 |
$firstGoodEns = $e unless defined($firstGoodEns); |
|
156 |
$lastGoodEns = $e; |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
unless (defined($opt_r)) { |
|
161 |
$fe = $firstGoodEns; |
|
162 |
$le = $lastGoodEns; |
|
163 |
} |
|
164 |
||
165 |
$P{N_ensembles} = $le - $fe + 1; |
|
166 |
||
167 |
$firstBin = 0; |
|
168 |
$lastBin = $lastGoodBin; |
|
169 |
||
170 |
print( STDERR "Start : $dta{ENSEMBLE}[$fe]->{DATE} $dta{ENSEMBLE}[$fe]->{TIME}\n"); |
|
171 |
print( STDERR "End : $dta{ENSEMBLE}[$le]->{DATE} $dta{ENSEMBLE}[$le]->{TIME}\n"); |
|
172 |
printf(STDERR "Bins : %d-%d\n",$firstBin+1,$lastBin+1); |
|
173 |
if ($beamCoords) { |
|
174 |
printf(STDERR "3-Beam : %d %d %d %d\n",$RDI_Coords::threeBeam_1, |
|
175 |
$RDI_Coords::threeBeam_2, |
|
176 |
$RDI_Coords::threeBeam_3, |
|
177 |
$RDI_Coords::threeBeam_4); |
|
178 |
||
179 |
} |
|
180 |
||
181 |
||
182 |
#---------------------------------------------------------------------- |
|
183 |
# generate output |
|
184 |
#---------------------------------------------------------------------- |
|
185 |
||
186 |
print("#ANTS#PARAMS# "); # %PARAMs |
|
187 |
foreach my $k (keys(%P)) { |
|
188 |
print(P "$k\{$P{$k}\} "); |
|
189 |
} |
|
190 |
printf(" soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!'); |
|
191 |
print("\n"); |
|
192 |
||
193 |
print("#ANTS#FIELDS# " . # LAYOUT |
|
194 |
"{ensemble} {heading} {pitch} {roll} {bin} " . |
|
195 |
"{b1} {b2} {b3} {b4} {u} {v} {w} {err_vel} " . |
|
196 |
"{v12} {w12} {v34} {w34} " . |
|
197 |
"{corr1} {corr2} {corr3} {corr4} " . |
|
198 |
"{amp1} {amp2} {amp3} {amp4} " . |
|
199 |
"{pcg1} {pcg2} {pcg3} {pcg4}\n" |
|
200 |
); |
|
201 |
||
202 |
for (my($e)=$fe; $e<=$le; $e++) { |
|
203 |
my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1; |
|
204 |
for (my($b)=$first_bin=1; $b<=$last_bin-1; $b++) { |
|
205 |
print("$dta{ENSEMBLE}[$e]->{NUMBER} "); |
|
206 |
print(defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan '); |
|
207 |
print(defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan '); |
|
208 |
print(defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan '); |
|
209 |
printf("%d ",$b+1); |
|
210 |
||
211 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
|
212 |
printf("%g %g %g %g ",@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
213 |
printf("%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] * $ssCorr); |
|
214 |
printf("%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] * $ssCorr); |
|
215 |
printf("%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] * $ssCorr); |
|
216 |
if ($dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]) { |
|
217 |
print("nan "); |
|
218 |
} else { |
|
219 |
printf("%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] * $ssCorr); |
|
220 |
} |
|
221 |
printf(defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]) ? "%g " : "nan ", |
|
222 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]); |
|
223 |
printf(defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]) ? "%g " : "nan ", |
|
224 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]); |
|
225 |
printf(defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]) ? "%g " : "nan ", |
|
226 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]); |
|
227 |
printf(defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ", |
|
228 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]); |
|
229 |
} else { |
|
230 |
print("nan nan nan nan "); |
|
231 |
print("nan nan nan nan "); |
|
232 |
print("nan nan nan nan "); |
|
233 |
} |
|
234 |
||
235 |
print("@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} "); |
|
236 |
print("@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} "); |
|
237 |
||
238 |
if ($beamCoords) { |
|
239 |
print("@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} "); |
|
240 |
} else { |
|
241 |
printf("nan nan nan nan "); |
|
242 |
} |
|
243 |
print("\n"); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
exit(0); |