0
|
1 |
#!/usr/bin/perl
|
|
2 |
#======================================================================
|
|
3 |
# L I S T E N S
|
|
4 |
# doc: Sat Jan 18 18:41:49 2003
|
6
|
5 |
# dlm: Thu May 12 10:46:46 2011
|
0
|
6 |
# (c) 2003 A.M. Thurnherr
|
6
|
7 |
# uE-Info: 37 99 NIL 0 0 72 2 2 4 NIL ofnI
|
0
|
8 |
#======================================================================
|
|
9 |
|
|
10 |
# Print useful info from the ensemble list or dump ensembles to
|
|
11 |
# separate files.
|
|
12 |
|
|
13 |
# HISTORY:
|
|
14 |
# Jan 18, 2003: - created
|
|
15 |
# Mar 18, 2004: - updated
|
|
16 |
# Sep 15, 2005: - made ESW optional (BB150)
|
|
17 |
# - change RDI binread library name
|
|
18 |
# Aug 25, 2006: - added -r)ange
|
|
19 |
# - added write -E)nsembles
|
|
20 |
# Aug 26, 2006: - added -M)agdecl
|
|
21 |
# Sep 19, 2007: - adapted to new [RDI_BB_Read.pl] (not tested)
|
|
22 |
# Jan 26, 2008: - BUG: diagnostic output had been written to STDOUT
|
|
23 |
# Feb 1, 2008: - BUG: still more diagnostic output written to STDOUT
|
|
24 |
# - BUG: -E/-A combo had ignored -E
|
|
25 |
# - changed %-good fieldnames for earth coordinates
|
|
26 |
# - allowed for 3-beam solutions
|
|
27 |
# Feb 7, 2008: - added -f)ields
|
|
28 |
# Apr 4, 2008: - made -f output nan on undefined values
|
|
29 |
# - BUG: -f fields did not allow array indices
|
|
30 |
# - added in-w)ater data only
|
|
31 |
# - restructured for simplicity
|
|
32 |
# Mar 2, 2009: - added # of valid bin-1 vels to non-ANTS output
|
|
33 |
# Jul 30, 2009: - NaN => nan
|
1
|
34 |
# Aug 15, 2010: - BUG: usage typo
|
5
|
35 |
# Dec 10, 2010: - changed ANTS output to time/date instead of UNIX time
|
|
36 |
# Jan 5, 2011: - added -b
|
6
|
37 |
# May 12, 2011: - disabled error exit on built-in-test errors when ensembles are dumped to stdout
|
0
|
38 |
|
|
39 |
# Notes:
|
5
|
40 |
# - -E outputs data in earth coordinates, unless -b is set also
|
0
|
41 |
# - -E output is always in ANTS format, ignoring -A
|
|
42 |
# - no soundspeed correction
|
|
43 |
|
|
44 |
require "getopts.pl";
|
|
45 |
$0 =~ m{(.*/)[^/]+};
|
|
46 |
require "$1RDI_BB_Read.pl";
|
|
47 |
require "$1RDI_Coords.pl";
|
|
48 |
|
|
49 |
die("Usage: $0 [-A)nts] [-Q)uiet (errcheck only)] " .
|
|
50 |
"[-f)ields <[name=]FIELD[,...]>] " .
|
5
|
51 |
"[write -E)nsemples <pref> [-M)agnetic <declination>] [min -p)ercent-good <#>] [keep -b)eam coords]] " .
|
1
|
52 |
"[-r)ange <first_ens,last_ens>] [in-w)ater ensembles only] " .
|
0
|
53 |
"<RDI file...>\n")
|
5
|
54 |
unless (&Getopts("AbE:f:M:p:Qr:w") && $#ARGV >= 0);
|
0
|
55 |
|
|
56 |
print(STDERR "WARNING: magnetic declination not set!\n")
|
|
57 |
if defined($opt_E) && !defined($opt_M);
|
|
58 |
|
|
59 |
die("$0: illegal option combination\n")
|
5
|
60 |
if ($opt_Q && $opt_A) || ((defined($opt_M) || defined($opt_p) || defined($opt_b)) && !defined($opt_E));
|
0
|
61 |
|
|
62 |
($first_ens,$last_ens) = split(',',$opt_r)
|
|
63 |
if defined($opt_r);
|
|
64 |
|
|
65 |
undef($opt_A) if defined($opt_E);
|
|
66 |
|
|
67 |
$opt_p = 0 unless defined($opt_p);
|
|
68 |
|
|
69 |
if ($opt_f) { # additional fields
|
|
70 |
@addFields = split(',',$opt_f);
|
|
71 |
foreach my $f (@addFields) {
|
|
72 |
$f =~ s/\s//g; # remove spaces
|
|
73 |
@def = split('=',$f);
|
|
74 |
if (@def == 2) { # name=field
|
|
75 |
$addLayout .= $opt_A ? " {$def[0]}" : " $def[0]";
|
|
76 |
$f = $def[1];
|
|
77 |
} else { # field
|
|
78 |
$addLayout .= " {$f}";
|
|
79 |
}
|
|
80 |
}
|
|
81 |
# print(STDERR "addLayout = $addLayout\n");
|
|
82 |
# print(STDERR "\@addFields = @addFields\n");
|
|
83 |
}
|
|
84 |
|
|
85 |
#----------------------------------------------------------------------
|
|
86 |
# MAIN
|
|
87 |
#----------------------------------------------------------------------
|
|
88 |
|
|
89 |
while (-f $ARGV[0]) {
|
|
90 |
if ($opt_A && !$opt_E) {
|
|
91 |
print("#ANTS#PARAMS# RDI_file{$ARGV[0]}\n");
|
|
92 |
} elsif (!$opt_Q) {
|
|
93 |
print(STDERR "$ARGV[0]: ");
|
|
94 |
}
|
|
95 |
readData(@ARGV,\%dta);
|
|
96 |
printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}}))
|
|
97 |
unless ($opt_Q);
|
|
98 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination
|
|
99 |
shift;
|
|
100 |
|
|
101 |
if ($dta{BEAM_COORDINATES}) { # coords used
|
|
102 |
$beamCoords = 1;
|
|
103 |
} elsif (!$dta{EARTH_COORDINATES}) {
|
|
104 |
die("$ARGV[0]: only beam and earth coordinates implemented so far\n");
|
|
105 |
}
|
|
106 |
|
5
|
107 |
die("$ARGV[0]: -b only makes sense for beam-coordinate data\n")
|
|
108 |
if ($opt_b && !$beamCoords);
|
|
109 |
|
0
|
110 |
if ($opt_A) { # select output fmt: ANTS
|
|
111 |
unless ($opt_Q) {
|
|
112 |
printf("#ANTS#PARAMS# N_ensembles{%d}\n",scalar(@{$dta{ENSEMBLE}}));
|
|
113 |
print('#ANTS#FIELDS# {ens} {time} {xducer_up} {temp} {hdg} {pitch} {roll} {XMIT_VOLTAGE} {XMIT_CURRENT}');
|
|
114 |
print(' {ESW}') if ($dta{DATA_FORMAT} eq 'WH300');
|
|
115 |
print("$addLayout\n");
|
|
116 |
}
|
|
117 |
|
|
118 |
$dumpEns = sub ($)
|
|
119 |
{
|
|
120 |
my($e) = @_;
|
|
121 |
|
|
122 |
printf('%d %lf %d %g %g %g %g %g %g',
|
|
123 |
$dta{ENSEMBLE}[$e]->{NUMBER},
|
|
124 |
$dta{ENSEMBLE}[$e]->{UNIX_TIME},
|
|
125 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} ? 1 : 0,
|
|
126 |
$dta{ENSEMBLE}[$e]->{TEMPERATURE},
|
|
127 |
$dta{ENSEMBLE}[$e]->{HEADING},
|
|
128 |
$dta{ENSEMBLE}[$e]->{PITCH},
|
|
129 |
$dta{ENSEMBLE}[$e]->{ROLL},
|
|
130 |
$dta{ENSEMBLE}[$e]->{ADC_XMIT_VOLTAGE},
|
|
131 |
$dta{ENSEMBLE}[$e]->{ADC_XMIT_CURRENT},
|
|
132 |
);
|
|
133 |
printf(' %08X',$dta{ENSEMBLE}[$e]->{ERROR_STATUS_WORD})
|
|
134 |
if ($dta{DATA_FORMAT} eq 'WH300');
|
|
135 |
foreach my $f (@addFields) {
|
|
136 |
my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
|
|
137 |
$fn = $f unless defined($fn);
|
|
138 |
my($v) = eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi");
|
|
139 |
print(defined($v) ? " $v" : " nan");
|
|
140 |
}
|
|
141 |
print("\n");
|
|
142 |
}
|
|
143 |
|
|
144 |
} elsif ($opt_E) { # one file per ens
|
|
145 |
|
|
146 |
$dumpEns = sub ($)
|
|
147 |
{
|
|
148 |
my($e) = @_;
|
|
149 |
my($b,$i);
|
|
150 |
my($file) = "$opt_E.$dta{ENSEMBLE}[$e]->{NUMBER}";
|
|
151 |
|
|
152 |
open(P,">$file") || die("$file: $!\n");
|
|
153 |
print(P "#ANTS#PARAMS# " .
|
|
154 |
"BT_u{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]} " .
|
|
155 |
"BT_v{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]} " .
|
|
156 |
"BT_w{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2]} " .
|
|
157 |
"BT_e{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[3]} " .
|
|
158 |
"BT_cor1{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[0]} " .
|
|
159 |
"BT_cor2{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[1]} " .
|
|
160 |
"BT_cor3{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[2]} " .
|
|
161 |
"BT_cor4{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[3]} " .
|
|
162 |
"BT_amp1{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[0]} " .
|
|
163 |
"BT_amp2{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[1]} " .
|
|
164 |
"BT_amp3{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[2]} " .
|
|
165 |
"BT_amp4{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[3]} " .
|
|
166 |
"\n"
|
|
167 |
);
|
|
168 |
print(P "#ANTS#FIELDS# " .
|
|
169 |
"{dz} {u} {v} {w} {e} {cor1} {cor2} {cor3} {cor4} " .
|
|
170 |
"{amp1} {amp2} {amp3} {amp4} "
|
|
171 |
);
|
|
172 |
if ($beamCoords) {
|
|
173 |
print(P "{pcg1} {pcg2} {pcg3} {pcg4}");
|
|
174 |
} else {
|
|
175 |
print(P "{pc3beam} {pcBadErrVel} {pc1or2beam} {pc4beam}");
|
|
176 |
}
|
|
177 |
print(P "$addLayout\n");
|
|
178 |
|
|
179 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) {
|
|
180 |
my(@v);
|
|
181 |
my($dz) = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH};
|
|
182 |
|
|
183 |
if ($beamCoords) {
|
|
184 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])
|
|
185 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] < $opt_p);
|
|
186 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1])
|
|
187 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][1] < $opt_p);
|
|
188 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2])
|
|
189 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][2] < $opt_p);
|
|
190 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])
|
|
191 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3] < $opt_p);
|
5
|
192 |
@v = $opt_b ? @{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} :
|
|
193 |
velInstrumentToEarth(\%dta,$e,
|
|
194 |
velBeamToInstrument(\%dta,
|
|
195 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}));
|
0
|
196 |
} else {
|
|
197 |
@v = velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]});
|
|
198 |
}
|
|
199 |
|
|
200 |
$v[0] = nan unless defined($v[0]);
|
|
201 |
$v[1] = nan unless defined($v[1]);
|
|
202 |
$v[2] = nan unless defined($v[2]);
|
|
203 |
$v[3] = nan unless defined($v[3]);
|
|
204 |
my(@out) = (
|
|
205 |
$dz,$v[0],$v[1],$v[2],$v[3],
|
|
206 |
@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]},
|
|
207 |
@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]},
|
|
208 |
@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}
|
|
209 |
);
|
|
210 |
foreach my $f (@addFields) {
|
|
211 |
my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
|
|
212 |
$fn = $f unless defined($fn);
|
|
213 |
push(@out,eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi"));
|
|
214 |
}
|
|
215 |
for ($i=0; $i<17+@addFields; $i++) {
|
|
216 |
$out[$i] = nan unless defined($out[$i]);
|
|
217 |
}
|
|
218 |
print(P "@out\n");
|
|
219 |
}
|
|
220 |
close(P);
|
|
221 |
}
|
|
222 |
|
|
223 |
} else { # neither ANTS nor ens files
|
|
224 |
unless ($opt_Q) {
|
|
225 |
if ($dta{DATA_FORMAT} eq 'WH300') {
|
|
226 |
printf(" # Date Time XD Temp Headng Pitch Roll vels(bin1) ESW$addLayout\n");
|
|
227 |
printf("-----------------------------------------------------------------------\n");
|
|
228 |
} else {
|
|
229 |
printf(" # Date Time XD Temp Headng Pitch Roll vels(bin1)$addLayout\n");
|
|
230 |
printf("-------------------------------------------------------------------\n");
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
$dumpEns = sub ($)
|
|
235 |
{
|
|
236 |
my($e) = @_;
|
|
237 |
|
|
238 |
printf('%5d %s %s %s %5.1f %6.1f %5.1f %5.1f %3d',
|
|
239 |
$dta{ENSEMBLE}[$e]->{NUMBER},
|
|
240 |
$dta{ENSEMBLE}[$e]->{DATE},
|
|
241 |
$dta{ENSEMBLE}[$e]->{TIME},
|
|
242 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} ? "UP" : "DN",
|
|
243 |
$dta{ENSEMBLE}[$e]->{TEMPERATURE},
|
|
244 |
$dta{ENSEMBLE}[$e]->{HEADING},
|
|
245 |
$dta{ENSEMBLE}[$e]->{PITCH},
|
|
246 |
$dta{ENSEMBLE}[$e]->{ROLL},
|
|
247 |
$dta{ENSEMBLE}[$e]->{BIN1VELS},
|
|
248 |
);
|
|
249 |
printf(' 0x%08X',$dta{ENSEMBLE}[$e]->{ERROR_STATUS_WORD})
|
|
250 |
if ($dta{DATA_FORMAT} eq 'WH300');
|
|
251 |
foreach my $f (@addFields) {
|
|
252 |
my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)});
|
|
253 |
$fn = $f unless defined($fn);
|
|
254 |
my($v) = eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi");
|
|
255 |
print(defined($v) ? " $v" : " nan");
|
|
256 |
}
|
6
|
257 |
print(" BUILT-IN-TEST ERROR")
|
|
258 |
if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
|
0
|
259 |
print("\n");
|
|
260 |
}
|
|
261 |
|
|
262 |
}
|
|
263 |
|
|
264 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) {
|
|
265 |
next if (defined($first_ens) &&
|
|
266 |
$dta{ENSEMBLE}[$e]->{NUMBER} < $first_ens);
|
|
267 |
last if (defined($last_ens) &&
|
|
268 |
$dta{ENSEMBLE}[$e]->{NUMBER} > $last_ens);
|
|
269 |
$dta{ENSEMBLE}[$e]->{BIN1VELS} =
|
|
270 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][0]) +
|
|
271 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][1]) +
|
|
272 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][2]) +
|
|
273 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[1][3]);
|
|
274 |
next if ($opt_w && $dta{ENSEMBLE}[$e]->{BIN1VELS}<3);
|
|
275 |
|
|
276 |
die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n")
|
|
277 |
if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4);
|
|
278 |
die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n")
|
6
|
279 |
if ($opt_Q || $opt_A || $opt_E) && defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR});
|
0
|
280 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n")
|
|
281 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN});
|
|
282 |
|
|
283 |
&$dumpEns($e)
|
|
284 |
unless ($opt_Q);
|
|
285 |
}
|
|
286 |
}
|
|
287 |
|
|
288 |
exit(0);
|