author | A.M. Thurnherr <athurnherr@yahoo.com> |
Fri, 18 Nov 2022 12:53:19 -0500 | |
changeset 61 | 69192495f0db |
parent 58 | 78607e2e8add |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# M K P R O F I L E |
|
4 |
# doc: Sun Jan 19 18:55:26 2003 |
|
61 | 5 |
# dlm: Mon Oct 18 11:02:31 2021 |
0 | 6 |
# (c) 2003 A.M. Thurnherr |
61 | 7 |
# uE-Info: 101 76 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 8 |
#====================================================================== |
9 |
||
10 |
# Make an LADCP Profile by Integrating W (similar to Firing's scan*). |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Jan 19, 2003: - written in order to test the RDI libs |
|
14 |
# Jan 20, 2003: - added ensemble number |
|
15 |
# Jan 21, 2003: - added horizontal integration |
|
16 |
# Jan 22, 2003: - corrected magnetic declination |
|
17 |
# Jan 23, 2003: - added -F)ilter |
|
18 |
# Jan 24, 2003: - added more %PARAMs; started integration from 1st bin |
|
19 |
# - added -g, -f, battery status |
|
20 |
# Jan 25, 2003: - added more %PARAMs |
|
21 |
# Feb 1, 2003: - BUG: bottom-track quality checking was bad |
|
22 |
# Feb 8, 2003: - allowed for array-indices on -f |
|
23 |
# Feb 9, 2003: - added 50% goodvelbin |
|
24 |
# - removed unknown-field err on -f to allow -f W |
|
25 |
# Feb 10, 2003: - changed initialization depth to 0m |
|
26 |
# - changed %bottom_depth to %max_depth |
|
27 |
# Feb 11, 2003: - changed sign of magnetic declination |
|
28 |
# Feb 12, 2003: - corrected BT-range scaling |
|
29 |
# Feb 14, 2003: - added %pinging_hours, %min_range |
|
30 |
# - removed magnetic declination from default |
|
31 |
# Feb 26, 2004: - added earth coordinates |
|
32 |
# Mar 3, 2004: - removed requirement for -M on !-Q |
|
33 |
# - corrected range-stats on earth coordinates |
|
34 |
# Mar 4, 2004: - added number of ensebles to output |
|
35 |
# Mar 11, 2004: - BUG: rename ACD -> ADC |
|
36 |
# Mar 12, 2004: - added %bottom_xmit_{current|voltage} |
|
37 |
# Mar 16, 2004: - BUG: on -M u/v/x/y were wrong |
|
38 |
# Mar 17, 2004: - added error estimates on u/v/x/y |
|
39 |
# - removed battery stuff (has to be done btw casts) |
|
40 |
# Mar 18, 2004: - totally re-did u/v integration |
|
41 |
# Mar 19, 2004: - re-designed u/v uncertainty estimation |
|
42 |
# Mar 28, 2004: - added MEAN_CORRELATION, MEAN_ECHO_AMPLITUDE |
|
43 |
# Sep 15, 2005: - changed BinRead library name |
|
44 |
# - made max gap length variable |
|
45 |
# Sep 16, 2005: - re-did u,v,w uncertainties |
|
46 |
# Nov 8, 2005: - UNIXTIME => UNIX_TIME |
|
47 |
# - added unix_time, secno, z_BT to default output |
|
48 |
# Dec 1, 2005: - moved profile-building code to [RDI_utils.pl] |
|
49 |
# - changed -f syntax to allow name=FIELD |
|
50 |
# - added %bin1_dist, %bin_length |
|
51 |
# Dec 8, 2005: - remove spaces from -f argument to allow multiline |
|
52 |
# definitions in Makefiles |
|
53 |
# Nov 13, 2006: - BUG: end-of-cast depth had not been reported correctly |
|
54 |
# - cosmetics |
|
55 |
# Nov 30, 2007: - adapted to 3-beam solutions |
|
56 |
# Dec 11, 2007: - adapted to earlier modifications (Sep 2007) of |
|
57 |
# [RDI_BB_Read.pl] |
|
58 |
# Dec 14, 2007: - replaced z by depth |
|
59 |
# Dec 17, 2007: - BUG: downcast flag was set incorrectly |
|
60 |
# Jan 24, 2008: - rotation had been output as degrees/s; to make it more |
|
61 |
# consistent with pitch/roll, I changed it to simple degrees |
|
62 |
# - added net rotations [deployment]/down/up/[recovery] |
|
63 |
# Apr 9, 2008: - added profile -B)ottom depth |
|
64 |
# - BUG: depth of first bin was reported as beginning of cast |
|
65 |
# Oct 24, 2008: - added RANGE and RANGE_BINS fields |
|
66 |
# Mar 18, 2009: - BUG: pitch/roll calculation had typo |
|
67 |
# - calc pitch/roll separately for down-/upcasts |
|
68 |
# - removed approximations in pitch/roll calcs |
|
69 |
# Jul 30, 2009: - typo '<' removed from output |
|
70 |
# - NaN => nan |
|
3 | 71 |
# Dec 8, 2010: - added zmax/zend labels to output |
72 |
# Dec 10, 2010: - made mkProfile exit with status 0 if no good ens found but -Q is set |
|
5 | 73 |
# Dec 19, 2010: - finally made -A default and activated output file |
74 |
# Jan 5, 2011: - made no-good-ensembles found test much more robust |
|
7 | 75 |
# Jun 22, 2011: - added bandwith/power warnings |
76 |
# - added ping-interval calculation |
|
77 |
# - BUG: post-recovery rotations were always zero |
|
8 | 78 |
# Sep 9, 2011: - BUG: range calculation for Earth coordinate data included bins without |
79 |
# valid velocities |
|
80 |
# Sep 21, 2010: - added %rms_heave_acceleration |
|
11 | 81 |
# Apr 12, 2013: - added -p |
12 | 82 |
# May 10, 2013: - BUG: mkProfile bombed when ADCP file is truncated at deepest location |
83 |
# May 14, 2013: - added heading to output |
|
84 |
# - added err_vel to output |
|
85 |
# - finally removed -d/-g |
|
14 | 86 |
# Nov 25, 2013: - expunged checkEnsemble |
87 |
# Feb 13, 2014: - added support set_range_lim() |
|
18 | 88 |
# Mar 4, 2014: - added support to allow missing PITCH/ROLL/HEADING values |
89 |
# May 24, 2014: - finally added (gimbal-)pitch & roll to default output |
|
90 |
# - renamed heading to hdg and pitchroll to tilt |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
91 |
# Mar 22, 2015: - made it work for moored time series as well |
33 | 92 |
# Mar 17, 2015: - adapted to new Getopt library |
93 |
# - removed warning |
|
37 | 94 |
# Sep 12, 2016: - added %PD0_file |
39 | 95 |
# Oct 13, 2017: - added instrument orientation |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
39
diff
changeset
|
96 |
# Apr 2, 2018: - BUG: velBeamToInstrument() used old usage |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
39
diff
changeset
|
97 |
# Apr 24, 2018: - BUG: bin1 was used even with zero blanking |
47
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
98 |
# Apr 18, 2019: - added coord-transformation %PARAMs |
58 | 99 |
# Apr 10, 2021: - adapted to V2.4 |
61 | 100 |
# Oct 12, 2021: - added speed to output on -M |
101 |
# Oct 18, 2021: - BUG: speed bombed with zero valid velocities in ensemble |
|
58 | 102 |
# HISTORY END |
0 | 103 |
|
104 |
# NOTES: |
|
105 |
# - the battery values are based on transmission voltages (different |
|
106 |
# from battery voltages) and reported without units (raw 8-bit a2d |
|
107 |
# values) |
|
108 |
# - -B with the CTD max depth can be used to linearly scale the depths; |
|
109 |
# even so, the profile can have negative depths, in particular when |
|
110 |
# the CTD is sent to a shallow depth first and then returned to the surface |
|
111 |
# before beginning the cast |
|
112 |
# - in one case that I looked at (Anslope ][, cast 82), there are large |
|
113 |
# depth errors, even when -B is used |
|
114 |
# - this utility works only approximately for uplookers (profile is |
|
115 |
# roughly ok, but apparently contaminated by surface reflection, |
|
116 |
# but stats are not ok; e.g. NBP0402 037U.prof) |
|
117 |
||
118 |
$0 =~ m{(.*)/[^/]+}; |
|
119 |
require "$1/RDI_BB_Read.pl"; |
|
120 |
require "$1/RDI_Coords.pl"; |
|
121 |
require "$1/RDI_Utils.pl"; |
|
33 | 122 |
use Getopt::Std; |
0 | 123 |
|
124 |
$USAGE = "$0 @ARGV"; |
|
125 |
die("Usage: $0 " . |
|
5 | 126 |
"[-Q)uiet] [-F)ilter <script>] " . |
12 | 127 |
"[require -4)-beam solutions] [-d)iscard <beam#>] [apply beamvel-m)ask <file>] " . |
0 | 128 |
"[-r)ef-layer <bin|1,bin|6>] [-n) vels <min|2>] " . |
11 | 129 |
"[-e)rr-vel <max[0.1]] [-c)orrelation <min>] [-p)ct-good <min[100]>] " . |
12 | 130 |
"[max -g)ap <len>] " . |
0 | 131 |
"[output -f)ields <field[,...]> " . |
132 |
"[-M)agnetic <declination>] [profile -B)ottom <depth>] " . |
|
133 |
"<RDI file>\n") |
|
33 | 134 |
unless (&getopts("4AB:F:M:Qd:g:r:n:e:c:f:m:p:") && @ARGV == 1); |
0 | 135 |
|
136 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
|
137 |
||
138 |
require $opt_F if defined($opt_F); # load filter |
|
139 |
||
140 |
$opt_r = "1,6" unless defined($opt_r); # defaults |
|
141 |
$opt_n = 2 unless defined($opt_n); |
|
142 |
$opt_e = 0.1 unless defined($opt_e); |
|
143 |
$opt_c = 70 unless defined($opt_c); |
|
12 | 144 |
$opt_g = 120 unless defined($opt_g); |
11 | 145 |
$opt_p = 100 unless defined($opt_p); |
0 | 146 |
|
147 |
($minb,$maxb) = split(',',$opt_r); # reference layer |
|
148 |
die("$0: can't decode -r $opt_r\n") unless defined($maxb); |
|
149 |
||
150 |
print(STDERR "Reading $ARGV[0]..."); # read data |
|
151 |
readData($ARGV[0],\%dta); |
|
152 |
print(STDERR "done\n"); |
|
153 |
||
154 |
die("$ARGV[0]: not enough bins for choice of -r\n") # enough bins? |
|
155 |
unless ($dta{N_BINS} >= $maxb); |
|
156 |
if ($dta{BEAM_COORDINATES}) { # coords used |
|
157 |
$beamCoords = 1; |
|
158 |
} elsif (!$dta{EARTH_COORDINATES}) { |
|
159 |
die("$ARGV[0]: only beam and earth coordinates implemented so far\n"); |
|
160 |
} |
|
7 | 161 |
|
12 | 162 |
if (defined($opt_m) && -r $opt_m) { |
163 |
die("$ARGV[0]: -m only implemented for data collected in beam coordinates\n") |
|
164 |
unless ($beamCoords); |
|
165 |
print(STDERR "Masking beam velocities as prescribed in $opt_m..."); |
|
166 |
||
167 |
open(BVM,$opt_m) || die("$opt_m: $!\n"); |
|
168 |
while (<BVM>) { |
|
169 |
s/#.*//; |
|
170 |
s/^\s*$//; |
|
171 |
next if ($_ eq ''); |
|
172 |
my($fe,$te,$db) = split; |
|
173 |
die("$opt_m: cannot decode $_\n") |
|
174 |
unless (numberp($fe) && numberp($te) && $te>=$fe && $db>=1 && $db<=4); |
|
175 |
die("$0: assertion failed") |
|
176 |
unless ($dta{ENSEMBLE}[$fe-1]->{NUMBER} == $fe && |
|
177 |
$dta{ENSEMBLE}[$te-1]->{NUMBER} == $te); |
|
178 |
for (my($ens)=$fe-1; $ens<=$te-1; $ens++) { |
|
179 |
$nens++; |
|
180 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
181 |
undef($dta{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$db-1]); |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
close(BVM); |
|
186 |
print(STDERR " $nens ensembles edited\n"); |
|
187 |
} |
|
188 |
||
189 |
if (defined($opt_d)) { # discard entire beam |
|
190 |
die("$ARGV[0]: -d only implemented for data collected in beam coordinates\n") |
|
191 |
unless ($beamCoords); |
|
192 |
print(STDERR "Discarding beam-$opt_d velocities..."); |
|
193 |
for (my($ens)=0; $ens<=$#{$dta{ENSEMBLE}}; $ens++) { |
|
194 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
195 |
undef($dta{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$opt_d-1]); |
|
196 |
} |
|
197 |
} |
|
198 |
print(STDERR "done\n"); |
|
199 |
} |
|
200 |
||
0 | 201 |
if (defined($opt_M)) { # magnetic declination |
202 |
$dta{HEADING_BIAS} = -1*$opt_M; |
|
203 |
} else { |
|
204 |
$dta{HEADING_BIAS} = 0; |
|
205 |
} |
|
206 |
||
14 | 207 |
ensure_BT_RANGE(\%dta); # set BT_RANGE field if it is missing (old firmware bug) |
0 | 208 |
|
209 |
if ($opt_f) { # additional fields |
|
210 |
@f = split(',',$opt_f); |
|
211 |
foreach $f (@f) { |
|
212 |
$f =~ s/\s//g; # remove spaces |
|
213 |
@def = split('=',$f); |
|
214 |
if (@def == 2) { # name=field |
|
215 |
$addFields .= " {$def[0]}"; |
|
216 |
$f = $def[1]; |
|
217 |
} else { # field |
|
218 |
$addFields .= " {$f}"; |
|
219 |
} |
|
220 |
} |
|
221 |
# print(STDERR "addFields = $addFields\n"); |
|
222 |
# print(STDERR "\@f = @f\n"); |
|
223 |
} |
|
224 |
||
225 |
#====================================================================== |
|
7 | 226 |
# Step 0: Check data & Calculate Ping Rates |
227 |
#====================================================================== |
|
228 |
||
229 |
unless ($dta{NARROW_BANDWIDTH}) { |
|
230 |
print(STDERR "WARNING: $0 WIDE BANDWIDTH!\n"); |
|
231 |
} |
|
232 |
||
58 | 233 |
unless ($dta{TRANSMIT_POWER_MAX}) { |
7 | 234 |
print(STDERR "WARNING: $0 LOW TRANSMIT POWER!\n"); |
235 |
} |
|
236 |
||
39 | 237 |
printf(STDERR "ADCP : %s (s/n %d) %s\n", |
238 |
$dta{INSTRUMENT_TYPE},$dta{SERIAL_NUMBER}, |
|
239 |
$dta{ENSEMBLE}[0]->{XDUCER_FACING_UP} ? 'UL' : 'DL'); |
|
8 | 240 |
printf(STDERR "# of ensembles : %d\n",scalar(@{$dta{ENSEMBLE}})); |
7 | 241 |
|
242 |
my($sdt1,$sdt2,$ndt); |
|
243 |
my($mindt1) = my($mindt2) = 9e99; |
|
244 |
my($maxdt1) = my($maxdt2) = 0; |
|
245 |
for (my($e)=2; $e<=$#{$dta{ENSEMBLE}}; $e+=2,$ndt++) { |
|
246 |
my($dt1) = $dta{ENSEMBLE}[$e-1]->{UNIX_TIME} - $dta{ENSEMBLE}[$e-2]->{UNIX_TIME}; |
|
247 |
my($dt2) = $dta{ENSEMBLE}[$e-0]->{UNIX_TIME} - $dta{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
248 |
$mindt1 = $dt1 if ($dt1 < $mindt1); |
|
249 |
$mindt2 = $dt2 if ($dt2 < $mindt2); |
|
250 |
$maxdt1 = $dt1 if ($dt1 > $maxdt1); |
|
251 |
$maxdt2 = $dt2 if ($dt2 > $maxdt2); |
|
252 |
$sdt1 += $dt1; $sdt2 += $dt2; |
|
253 |
} |
|
254 |
||
8 | 255 |
printf(STDERR "Ping intervals : %.1fs/%.1fs",$sdt1/$ndt,$sdt2/$ndt); |
256 |
if ($maxdt1-$mindt1>=0.1 || $maxdt2-$mindt2>=0.1) { |
|
257 |
printf(STDERR " (%.1fs-%.1fs/%.1fs-%.1fs)\n",$mindt1,$maxdt1,$mindt2,$maxdt2); |
|
258 |
} else { |
|
259 |
print(STDERR "\n"); |
|
260 |
} |
|
7 | 261 |
|
262 |
#====================================================================== |
|
0 | 263 |
# Step 1: Integrate w & determine water depth |
264 |
#====================================================================== |
|
265 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
39
diff
changeset
|
266 |
$minb = 2 if ($dta{BLANKING_DISTANCE} == 0); |
8 | 267 |
($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz,$rms_heave_accel) = |
14 | 268 |
mk_prof(\%dta,0,$opt_F,$minb,$maxb,$opt_c,$opt_e,$opt_g,$opt_p); |
0 | 269 |
|
21 | 270 |
if ($lastgood == $atbottom) { |
271 |
print(STDERR "$ARGV[0]: truncated file (ends at max depth)\n") |
|
272 |
} elsif (($atbottom > $firstgood) && ($lastgood > $atbottom)) { |
|
273 |
# all good |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
274 |
} elsif ($lastgood > $firstgood) { |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
275 |
print(STDERR "$ARGV[0]: no bottom depth found\n") |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
276 |
unless ($atbottom > 0); |
21 | 277 |
} else { |
3 | 278 |
if ($opt_Q) { |
5 | 279 |
print(STDERR "$ARGV[0]: no valid cast data found\n"); |
3 | 280 |
exit(0); |
281 |
} else { |
|
21 | 282 |
die(sprintf("$ARGV[0]: no valid cast data found (firstgood=%d atbottom=%d lastgood=%d)\n",$firstgood,$atbottom,$lastgood)); |
3 | 283 |
} |
284 |
} |
|
0 | 285 |
|
286 |
if (defined($opt_B)) { # scale Z |
|
287 |
my($zscale) = $opt_B / ($dta{ENSEMBLE}[$atbottom]->{DEPTH} -# downcast |
|
288 |
$dta{ENSEMBLE}[$firstgood]->{DEPTH}); |
|
289 |
# printf(STDERR "scaling downcast depths by %.2f\n",$zscale); |
|
290 |
for (my($e)=$firstgood; $e<$atbottom; $e++) { |
|
291 |
next unless defined($dta{ENSEMBLE}[$e]->{DEPTH}); |
|
292 |
$dta{ENSEMBLE}[$e]->{DEPTH} = |
|
293 |
$dta{ENSEMBLE}[$firstgood]->{DEPTH} + $zscale * |
|
294 |
($dta{ENSEMBLE}[$e]->{DEPTH}-$dta{ENSEMBLE}[$firstgood]->{DEPTH}); |
|
295 |
} |
|
296 |
||
297 |
$zscale = $opt_B / ($dta{ENSEMBLE}[$atbottom]->{DEPTH} - # upcast |
|
298 |
$dta{ENSEMBLE}[$lastgood]->{DEPTH}); |
|
299 |
# printf(STDERR "scaling upcast depths by %.2f\n",$zscale); |
|
300 |
for (my($e)=$atbottom; $e<=$lastgood; $e++) { |
|
301 |
next unless defined($dta{ENSEMBLE}[$e]->{DEPTH}); |
|
302 |
$dta{ENSEMBLE}[$e]->{DEPTH} = |
|
303 |
$dta{ENSEMBLE}[$firstgood]->{DEPTH} + $zscale * |
|
304 |
($dta{ENSEMBLE}[$e]->{DEPTH}-$dta{ENSEMBLE}[$lastgood]->{DEPTH}); |
|
305 |
} |
|
306 |
} |
|
307 |
||
14 | 308 |
set_range_lim(\%dta); # set {range_lim} field |
309 |
||
0 | 310 |
($water_depth,$sig_wd) = # sea bed |
311 |
find_seabed(\%dta,$atbottom,$beamCoords); |
|
312 |
||
313 |
#====================================================================== |
|
314 |
# Step 2: Integrate u & v |
|
315 |
#====================================================================== |
|
316 |
||
317 |
sub ref_lr_uv($$$) # calc ref-level u/v |
|
318 |
{ |
|
319 |
my($ens,$z,$water_depth) = @_; |
|
320 |
my($i,$n,@v,@goodU,@goodV); |
|
321 |
||
322 |
$water_depth = 99999 unless defined($water_depth); |
|
323 |
||
324 |
for ($i=$minb; $i<=$maxb; $i++) { |
|
325 |
next if ($dta{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $opt_c || |
|
326 |
$dta{ENSEMBLE}[$ens]->{CORRELATION}[$i][1] < $opt_c || |
|
327 |
$dta{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $opt_c || |
|
328 |
$dta{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $opt_c); |
|
329 |
if ($beamCoords) { |
|
330 |
next if ($dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < 100 || |
|
331 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < 100 || |
|
332 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < 100 || |
|
333 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
|
334 |
@v = velInstrumentToEarth(\%dta,$ens, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
39
diff
changeset
|
335 |
velBeamToInstrument(\%dta,$ens, |
0 | 336 |
@{$dta{ENSEMBLE}[$ens]->{VELOCITY}[$i]})); |
337 |
} else { |
|
338 |
next if ($dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 || |
|
339 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 || |
|
340 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
|
341 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < 100); |
|
342 |
@v = velApplyHdgBias(\%dta,$ens, |
|
343 |
@{$dta{ENSEMBLE}[$ens]->{VELOCITY}[$i]}); |
|
344 |
} |
|
345 |
next if (!defined($v[3]) || abs($v[3]) > $opt_e); |
|
346 |
||
347 |
# Martin's BT routines show strong shear just above sea bed |
|
348 |
# => skip lowest 20m. |
|
349 |
if (defined($v[0])) { # valid u,v |
|
350 |
if ($dta{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { |
|
351 |
if ($z - $dta{DISTANCE_TO_BIN1_CENTER} |
|
352 |
- $i*$dta{BIN_LENGTH} > 0) { |
|
353 |
push(@goodU,$v[0]); push(@goodV,$v[1]); |
|
354 |
$dta{ENSEMBLE}[$ens]->{U} += $v[0]; |
|
355 |
$dta{ENSEMBLE}[$ens]->{V} += $v[1]; |
|
356 |
$n++; |
|
357 |
} |
|
358 |
} else { |
|
359 |
if ($z + $dta{DISTANCE_TO_BIN1_CENTER} |
|
360 |
+ $i*$dta{BIN_LENGTH} < $water_depth-20) { |
|
361 |
push(@goodU,$v[0]); push(@goodV,$v[1]); |
|
362 |
$dta{ENSEMBLE}[$ens]->{U} += $v[0]; |
|
363 |
$dta{ENSEMBLE}[$ens]->{V} += $v[1]; |
|
364 |
$n++; |
|
365 |
} |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
if ($n >= 2) { |
|
371 |
my(@sumsq) = (0,0); |
|
372 |
$dta{ENSEMBLE}[$ens]->{U} /= $n; |
|
373 |
$dta{ENSEMBLE}[$ens]->{V} /= $n; |
|
61 | 374 |
$dta{ENSEMBLE}[$ens]->{SPEED} = sqrt($dta{ENSEMBLE}[$ens]->{U}**2 + |
375 |
$dta{ENSEMBLE}[$ens]->{V}**2); |
|
0 | 376 |
for ($i=0; $i<$n; $i++) { |
377 |
$sumsq[0] += ($dta{ENSEMBLE}[$ens]->{U}-$goodU[$i])**2; |
|
378 |
$sumsq[1] += ($dta{ENSEMBLE}[$ens]->{V}-$goodV[$i])**2; |
|
379 |
} |
|
380 |
$dta{ENSEMBLE}[$ens]->{U_ERR} = sqrt($sumsq[0])/($n-1); |
|
381 |
$dta{ENSEMBLE}[$ens]->{V_ERR} = sqrt($sumsq[1])/($n-1); |
|
382 |
} else { |
|
383 |
$dta{ENSEMBLE}[$ens]->{U} = undef; |
|
384 |
$dta{ENSEMBLE}[$ens]->{V} = undef; |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
#---------------------------------------------------------------------- |
|
61 | 389 |
# Create Progressive Vector Diagram |
390 |
#---------------------------------------------------------------------- |
|
0 | 391 |
|
61 | 392 |
($x,$y,$cAvg,$ngood) = (0,0,0,0); # init |
0 | 393 |
|
394 |
$dta{ENSEMBLE}[$firstgood]->{X} = $dta{ENSEMBLE}[$firstgood]->{X_ERR} = 0; |
|
395 |
$dta{ENSEMBLE}[$firstgood]->{Y} = $dta{ENSEMBLE}[$firstgood]->{Y_ERR} = 0; |
|
396 |
$prevgood = $firstgood; |
|
397 |
||
398 |
for ($e=$firstgood+1; defined($opt_M)&&$e<=$lastgood; $e++) { |
|
399 |
||
400 |
#-------------------------------------------------- |
|
401 |
# within profile: both $firstgood and $prevgood set |
|
402 |
#-------------------------------------------------- |
|
403 |
||
404 |
ref_lr_uv($e,$dta{ENSEMBLE}[$e]->{DEPTH},$water_depth) # instrument vel |
|
405 |
if (defined($dta{ENSEMBLE}[$e]->{W})); |
|
406 |
||
407 |
if (!defined($dta{ENSEMBLE}[$e]->{U})) { # gap |
|
408 |
$uv_gap_time += $dta{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
409 |
$dta{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
410 |
next; |
|
411 |
} |
|
412 |
||
413 |
my($dt) = $dta{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
414 |
$dta{ENSEMBLE}[$prevgood]->{UNIX_TIME}; # ...last good ens |
|
415 |
||
416 |
#----------------------------------- |
|
417 |
# The current ensemble has valid u/v |
|
418 |
#----------------------------------- |
|
419 |
||
61 | 420 |
$cAvg += $dta{ENSEMBLE}[$e]->{SPEED}; $ngood++; |
421 |
||
0 | 422 |
$x -= $dta{ENSEMBLE}[$prevgood]->{U} * $dt; # integrate |
423 |
$xErr += ($dta{ENSEMBLE}[$prevgood]->{U_ERR} * $dt)**2; |
|
424 |
$dta{ENSEMBLE}[$e]->{X} = $x; |
|
425 |
$dta{ENSEMBLE}[$e]->{X_ERR} = sqrt($xErr); |
|
426 |
||
427 |
$y -= $dta{ENSEMBLE}[$prevgood]->{V} * $dt; |
|
428 |
$yErr += ($dta{ENSEMBLE}[$prevgood]->{V_ERR} * $dt)**2; |
|
429 |
$dta{ENSEMBLE}[$e]->{Y} = $y; |
|
430 |
$dta{ENSEMBLE}[$e]->{Y_ERR} = sqrt($yErr); |
|
431 |
||
432 |
$prevgood = $e; |
|
433 |
} |
|
434 |
||
435 |
unless (defined($dta{ENSEMBLE}[$lastgood]->{X})) { # last is bad in u/v |
|
436 |
my($dt) = $dta{ENSEMBLE}[$lastgood]->{UNIX_TIME} - # time step since |
|
437 |
$dta{ENSEMBLE}[$prevgood]->{UNIX_TIME}; # ...last good ens |
|
438 |
||
439 |
$x -= $dta{ENSEMBLE}[$prevgood]->{U} * $dt; # integrate |
|
440 |
$xErr += ($dta{ENSEMBLE}[$prevgood]->{U_ERR} * $dt)**2; |
|
441 |
$dta{ENSEMBLE}[$lastgood]->{X} = $x; |
|
442 |
$dta{ENSEMBLE}[$lastgood]->{X_ERR} = sqrt($xErr); |
|
443 |
||
444 |
$y -= $dta{ENSEMBLE}[$prevgood]->{V} * $dt; |
|
445 |
$yErr += ($dta{ENSEMBLE}[$prevgood]->{V_ERR} * $dt)**2; |
|
446 |
$dta{ENSEMBLE}[$lastgood]->{Y} = $y; |
|
447 |
$dta{ENSEMBLE}[$lastgood]->{Y_ERR} = sqrt($yErr); |
|
448 |
} |
|
449 |
||
450 |
$firstgood++ if ($firstgood == 0); # centered diff |
|
451 |
$lastgood-- if ($lastgood == $#{$dta{ENSEMBLE}}); # in step 6 |
|
452 |
||
61 | 453 |
$cAvg = $ngood ? ($cAvg / $ngood) : nan; |
454 |
||
0 | 455 |
#====================================================================== |
456 |
# Step 3: Calculate Uncertainties |
|
457 |
#====================================================================== |
|
458 |
||
459 |
# Time series of W_ERR indicate that errors are very large near the |
|
460 |
# surface and near the sea bed, perhaps because of reflections. |
|
461 |
# A reasonable estimate for typical uncertainty is therefore the mode |
|
462 |
# of the std errors. |
|
463 |
||
464 |
my(@histUErr,@histVErr,@histWErr); |
|
465 |
my($histRez) = 1e-4; |
|
466 |
||
467 |
for ($e=$firstgood; $e<=$lastgood; $e++) { |
|
468 |
$histWErr[int($dta{ENSEMBLE}[$e]->{W_ERR}/$histRez+0.5)]++ |
|
469 |
if defined($dta{ENSEMBLE}[$e]->{W_ERR}); |
|
470 |
$histUErr[int($dta{ENSEMBLE}[$e]->{U_ERR}/$histRez+0.5)]++ |
|
471 |
if defined($dta{ENSEMBLE}[$e]->{U_ERR}); |
|
472 |
$histVErr[int($dta{ENSEMBLE}[$e]->{V_ERR}/$histRez+0.5)]++ |
|
473 |
if defined($dta{ENSEMBLE}[$e]->{V_ERR}); |
|
474 |
} |
|
475 |
||
476 |
my($max) = 0; my($mode); |
|
477 |
for (my($i)=0; $i<=$#histWErr; $i++) { |
|
478 |
next if ($histWErr[$i] < $max); |
|
479 |
$max = $histWErr[$i]; $mode = $i; |
|
480 |
} |
|
481 |
$wErr = $mode * $histRez if defined($mode); |
|
482 |
||
483 |
$max = 0; $mode = undef; |
|
484 |
for (my($i)=0; $i<=$#histUErr; $i++) { |
|
485 |
next if ($histUErr[$i] < $max); |
|
486 |
$max = $histUErr[$i]; $mode = $i; |
|
487 |
} |
|
488 |
$uErr = $mode * $histRez if defined($mode); |
|
489 |
||
490 |
$max = 0; $mode = undef; |
|
491 |
for (my($i)=0; $i<=$#histVErr; $i++) { |
|
492 |
next if ($histVErr[$i] < $max); |
|
493 |
$max = $histVErr[$i]; $mode = $i; |
|
494 |
} |
|
495 |
$vErr = $mode * $histRez if defined($mode); |
|
496 |
||
497 |
#print(STDERR "u: mu = $meanU / sigma = $uErr\n"); |
|
498 |
#print(STDERR "v: mu = $meanV / sigma = $vErr\n"); |
|
499 |
#print(STDERR "w: mu = $meanW / sigma = $wErr\n"); |
|
500 |
||
501 |
if (defined($opt_M)) { # displacement errors |
|
502 |
$x_err = $uErr * $uv_gap_time + $dta{ENSEMBLE}[$lastgood]->{X_ERR}; |
|
503 |
$y_err = $vErr * $uv_gap_time + $dta{ENSEMBLE}[$lastgood]->{Y_ERR}; |
|
504 |
} |
|
505 |
$z_err = $wErr * $w_gap_time + $dta{ENSEMBLE}[$lastgood]->{DEPTH_ERR}; |
|
506 |
||
507 |
#printf(STDERR "x_err = $dta{ENSEMBLE}[$lastgood]->{X_ERR} + %g\n", |
|
508 |
# $uErr * $uv_gap_time); |
|
509 |
#printf(STDERR "y_err = $dta{ENSEMBLE}[$lastgood]->{Y_ERR} + %g\n", |
|
510 |
# $vErr * $uv_gap_time); |
|
511 |
#printf(STDERR "z_err = $dta{ENSEMBLE}[$lastgood]->{DEPTH_ERR} + %g\n", |
|
512 |
# $wErr * $w_gap_time); |
|
513 |
||
514 |
#====================================================================== |
|
515 |
# Step 4: Calculate Beam Range Stats |
|
516 |
#====================================================================== |
|
517 |
||
518 |
my($min_good_bins) = 999; |
|
519 |
my($worst_beam); |
|
520 |
||
521 |
sub count_good_vels($) # count good vels |
|
522 |
{ |
|
523 |
my($ens) = @_; |
|
524 |
my($good) = -1; my($this_worst_beam); |
|
525 |
||
526 |
if ($beamCoords) { |
|
527 |
for (my($i)=0; $i<$dta{N_BINS}; $i++) { |
|
528 |
for (my($b)=0; $b<4; $b++) { |
|
529 |
$good=$i,$this_worst_beam=$b,$nVels[$i][$b]++ |
|
530 |
if defined($dta{ENSEMBLE}[$ens]->{VELOCITY}[$i][$b]); |
|
531 |
} |
|
532 |
} |
|
533 |
} else { |
|
534 |
for (my($i)=0; $i<$dta{N_BINS}; $i++) { |
|
8 | 535 |
next unless defined($dta{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]); |
0 | 536 |
for (my($b)=0; $b<4; $b++) { |
537 |
$good=$i,$this_worst_beam=$b,$nVels[$i][$b]++ |
|
538 |
if ($dta{ENSEMBLE}[$ens]->{CORRELATION}[$i][$b] >= |
|
539 |
$dta{MIN_CORRELATION}); |
|
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
$min_good_ens=$ens, $min_good_bins=$good, $worst_beam=$this_worst_beam |
|
544 |
if ((!defined($water_depth) || |
|
545 |
$dta{ENSEMBLE}[$ens]->{DEPTH} < $water_depth-200) |
|
546 |
&& $good >= 0 && $good < $min_good_bins); |
|
547 |
} |
|
548 |
||
549 |
#---------------------------------------------------------------------- |
|
550 |
||
551 |
for ($e=$firstgood; $e<=$lastgood; $e++) { # range |
|
552 |
my($i); |
|
553 |
for ($i=0; $i<$dta{N_BINS}; $i++) { |
|
554 |
last if (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$i][0]) + |
|
555 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$i][1]) + |
|
556 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$i][2]) + |
|
557 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$i][3]) < 3); |
|
558 |
} |
|
559 |
$dta{ENSEMBLE}[$e]->{RANGE_BINS} = $i; |
|
560 |
$dta{ENSEMBLE}[$e]->{RANGE} = |
|
561 |
$dta{DISTANCE_TO_BIN1_CENTER} + $i * $dta{BIN_LENGTH}; |
|
562 |
} |
|
563 |
||
564 |
for ($e=$firstgood; $e<=$lastgood; $e++) { # mean corr/amp |
|
565 |
$sumcor = $sumamp = $ndata = 0; |
|
566 |
for (my($i)=0; $i<$dta{N_BINS}; $i++) { |
|
567 |
for (my($b)=0; $b<4; $b++) { |
|
568 |
next unless ($dta{ENSEMBLE}[$e]->{CORRELATION}[$i][$b]); |
|
569 |
$sumcor += $dta{ENSEMBLE}[$e]->{CORRELATION}[$i][$b]; |
|
570 |
$sumamp += $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b]; |
|
571 |
$ndata++; |
|
572 |
} |
|
573 |
} |
|
574 |
$dta{ENSEMBLE}[$e]->{MEAN_CORRELATION} = $sumcor/$ndata; |
|
575 |
$dta{ENSEMBLE}[$e]->{MEAN_ECHO_AMPLITUDE} = $sumamp/$ndata; |
|
576 |
} |
|
577 |
||
578 |
for ($e=$firstgood+50; $e<=$lastgood-50; $e++) { # range stats |
|
579 |
count_good_vels($e); |
|
580 |
} |
|
581 |
for ($i=0; $i<$dta{N_BINS}; $i++) { |
|
582 |
for ($b=0; $b<4; $b++) { |
|
583 |
$maxVels = $nVels[$i][$b] unless ($maxVels > $nVels[$i][$b]); |
|
584 |
} |
|
585 |
} |
|
586 |
for ($i=0; $i<$dta{N_BINS}; $i++) { |
|
587 |
for ($b=0; $b<4; $b++) { |
|
588 |
$gb[$b] = $i if ($nVels[$i][$b] >= 0.8*$maxVels); |
|
589 |
} |
|
590 |
} |
|
591 |
$gb = ($gb[0]+$gb[1]+$gb[2]+$gb[3]) / 4; |
|
592 |
||
593 |
#====================================================================== |
|
12 | 594 |
# Step 5: Remove Ship Drift (probably not useful => removed) |
0 | 595 |
#====================================================================== |
596 |
||
597 |
#====================================================================== |
|
598 |
# Step 6: Pitch, Roll, Rotation |
|
599 |
#====================================================================== |
|
600 |
||
18 | 601 |
# in case of PITCH/ROLL/HEADING data gaps (IMP data), the calculations |
602 |
# are not entirely correct, as |
|
603 |
# i) the rotation implied by the pre-/post-gap headings is not counted |
|
604 |
# ii) the gappy ensembles are counted for calculating the rms vals |
|
605 |
||
0 | 606 |
my($prrms,$dnprrms,$upprrms) = (0,0,0); |
607 |
my($rotrms,$prerot,$dnrot,$uprot,$postrot) = (0,0,0,0,0); |
|
608 |
||
609 |
sub rot($) |
|
610 |
{ |
|
611 |
my($e) = @_; |
|
18 | 612 |
return 0 |
613 |
unless defined($dta{ENSEMBLE}[$e]->{HEADING}) && defined($dta{ENSEMBLE}[$e-1]->{HEADING}); |
|
0 | 614 |
my($rot) = $dta{ENSEMBLE}[$e]->{HEADING} - |
615 |
$dta{ENSEMBLE}[$e-1]->{HEADING}; |
|
616 |
$rot -= 360 if ($rot > 180); |
|
617 |
$rot += 360 if ($rot < -180); |
|
618 |
return $rot; |
|
619 |
} |
|
620 |
||
621 |
for ($e=1; $e<$firstgood; $e++) { # pre-deployment |
|
622 |
$prerot += rot($e); |
|
623 |
} |
|
624 |
||
625 |
for (; $e<= $atbottom; $e++) { # downcast |
|
18 | 626 |
$dta{ENSEMBLE}[$e]->{TILT} = |
0 | 627 |
&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH}, |
628 |
$dta{ENSEMBLE}[$e]->{ROLL}); |
|
18 | 629 |
$prrms += $dta{ENSEMBLE}[$e]->{TILT}**2 |
630 |
if numberp($dta{ENSEMBLE}[$e]->{TILT}); |
|
0 | 631 |
|
632 |
$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e); |
|
633 |
$dnrot += $dta{ENSEMBLE}[$e]->{ROTATION}; |
|
634 |
$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2; |
|
635 |
} |
|
636 |
$dnprrms = $prrms; |
|
637 |
||
638 |
for (; $e<=$lastgood; $e++) { # upcast |
|
18 | 639 |
$dta{ENSEMBLE}[$e]->{TILT} = |
0 | 640 |
&angle_from_vertical($dta{ENSEMBLE}[$e]->{PITCH}, |
641 |
$dta{ENSEMBLE}[$e]->{ROLL}); |
|
18 | 642 |
$prrms += $dta{ENSEMBLE}[$e]->{TILT}**2 |
643 |
if numberp($dta{ENSEMBLE}[$e]->{TILT}); |
|
0 | 644 |
|
645 |
$dta{ENSEMBLE}[$e]->{ROTATION} = rot($e); |
|
646 |
$uprot += $dta{ENSEMBLE}[$e]->{ROTATION}; |
|
647 |
$rotrms += $dta{ENSEMBLE}[$e]->{ROTATION}**2; |
|
648 |
} |
|
649 |
$upprrms = $prrms - $dnprrms; |
|
650 |
||
7 | 651 |
for (; $e<=$#{$dta{ENSEMBLE}}; $e++) { # post-recovery |
0 | 652 |
$postrot += rot($e); |
653 |
} |
|
654 |
||
655 |
$prerot /= 360; # rotations, not degrees |
|
656 |
$dnrot /= 360; |
|
657 |
$uprot /= 360; |
|
658 |
$postrot /= 360; |
|
659 |
||
660 |
$prrms = sqrt($prrms/($lastgood-$firstgood)); |
|
661 |
$dnprrms = sqrt($dnprrms/($atbottom-$firstgood)); |
|
12 | 662 |
|
663 |
if ($lastgood == $atbottom) { |
|
664 |
print(STDERR "WARNING: $0 NO UPCAST DATA\n"); |
|
665 |
$upprrms = nan; |
|
666 |
} else { |
|
667 |
$upprrms = sqrt($upprrms/($lastgood-$atbottom)); |
|
668 |
} |
|
0 | 669 |
|
670 |
$rotrms = sqrt($rotrms/($lastgood-$firstgood)); |
|
671 |
||
672 |
#====================================================================== |
|
673 |
# PRODUCE OUTPUT |
|
674 |
#====================================================================== |
|
675 |
||
8 | 676 |
printf(STDERR "Start of cast : %s (#%5d) at %6.1fm\n", |
0 | 677 |
$dta{ENSEMBLE}[$firstgood]->{TIME}, |
678 |
$dta{ENSEMBLE}[$firstgood]->{NUMBER}, |
|
679 |
$dta{ENSEMBLE}[$firstgood]->{DEPTH}); |
|
8 | 680 |
printf(STDERR "Bottom of cast (zmax) : %s (#%5d) at %6.1fm\n", |
0 | 681 |
$dta{ENSEMBLE}[$atbottom]->{TIME}, |
682 |
$dta{ENSEMBLE}[$atbottom]->{NUMBER}, |
|
683 |
$dta{ENSEMBLE}[$atbottom]->{DEPTH}); |
|
684 |
if (defined($water_depth)) { |
|
8 | 685 |
printf(STDERR "Seabed : at %6.1fm (+-%dm)\n",$water_depth,$sig_wd); |
0 | 686 |
} else { |
8 | 687 |
print(STDERR "Seabed : not found\n"); |
0 | 688 |
} |
8 | 689 |
printf(STDERR "End of cast (zend) : %s (#%5d) at %6.1fm\n", |
0 | 690 |
$dta{ENSEMBLE}[$lastgood]->{TIME}, |
691 |
$dta{ENSEMBLE}[$lastgood]->{NUMBER}, |
|
692 |
$dta{ENSEMBLE}[$lastgood]->{DEPTH}); |
|
693 |
||
8 | 694 |
printf(STDERR "Rel. Displacement : x = %d(%d)m / y = %d(%d)m\n", |
0 | 695 |
$dta{ENSEMBLE}[$lastgood]->{X}, $x_err, |
696 |
$dta{ENSEMBLE}[$lastgood]->{Y}, $y_err, |
|
697 |
) if defined($opt_M); |
|
698 |
||
8 | 699 |
printf(STDERR "Cast Duration : %.1f hours (pinging for %.1f hours)\n", |
0 | 700 |
$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME} / 3600, |
701 |
($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} - |
|
702 |
$dta{ENSEMBLE}[0]->{UNIX_TIME}) / 3600); |
|
703 |
||
8 | 704 |
printf(STDERR "Minimum range : %dm at ensemble %d, beam %d\n", |
0 | 705 |
$dta{DISTANCE_TO_BIN1_CENTER} + |
706 |
$min_good_bins*$dta{BIN_LENGTH}, |
|
707 |
$dta{ENSEMBLE}[$min_good_ens]->{NUMBER}, |
|
708 |
$worst_beam); |
|
8 | 709 |
printf(STDERR "80%%-valid bins : %.1f\n",$gb+1); |
710 |
printf(STDERR "80%%-valid range : %dm\n", |
|
0 | 711 |
$dta{DISTANCE_TO_BIN1_CENTER} + $gb*$dta{BIN_LENGTH}); |
8 | 712 |
printf(STDERR "3-beam solutions : $RDI_Coords::threeBeam_1 " . |
3 | 713 |
"$RDI_Coords::threeBeam_2 " . |
714 |
"$RDI_Coords::threeBeam_3 " . |
|
715 |
"$RDI_Coords::threeBeam_4\n") |
|
0 | 716 |
unless ($opt_4); |
8 | 717 |
printf(STDERR "net rotations : [%d]/%d/%d/[%d]\n",$prerot,$dnrot,$uprot,$postrot); |
718 |
printf(STDERR "rms pitch/roll : %.1fdeg/%.1fdeg\n",$dnprrms,$upprrms); |
|
719 |
printf(STDERR "rms heave acceleration: %.2fm/s^2\n",$rms_heave_accel); |
|
0 | 720 |
|
5 | 721 |
exit(0) if ($opt_Q); |
722 |
||
723 |
#---------------------------------------------------------------------- |
|
724 |
# output profile in active ANTS format |
|
725 |
#---------------------------------------------------------------------- |
|
726 |
||
727 |
print("#!/usr/bin/perl -S list\n"); |
|
728 |
chmod(0777&~umask,*STDOUT); |
|
729 |
||
730 |
print("#ANTS# [] $USAGE\n"); |
|
61 | 731 |
$uFields = "{u} {u_err} {v} {v_err} {x} {x_err} {y} {y_err} {speed}" |
5 | 732 |
if defined($opt_M); |
733 |
print("#ANTS#FIELDS# {ens} {time} {elapsed} {secno} {downcast} " . |
|
14 | 734 |
"{w} {w_err} {err_vel} {depth} {depth_err} {seabed} " . |
18 | 735 |
"{pitch} {roll} {tilt} {hdg} {rotation} " . |
5 | 736 |
"$uFields $addFields\n"); |
0 | 737 |
|
47
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
738 |
printf( "#ANTS#PARAMS# date{$dta{ENSEMBLE}[$firstgood]->{DATE}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
739 |
"start_time{$dta{ENSEMBLE}[$firstgood]->{TIME}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
740 |
"bottom_time{$dta{ENSEMBLE}[$atbottom]->{TIME}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
741 |
"end_time{$dta{ENSEMBLE}[$lastgood]->{TIME}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
742 |
"bottom_xmit_voltage{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_VOLTAGE}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
743 |
"bottom_xmit_current{$dta{ENSEMBLE}[$atbottom]->{ADC_XMIT_CURRENT}} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
744 |
"PD0_file{$ARGV[0]} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
745 |
"RDI_Coords::minValidVels{$RDI_Coords::minValidVels} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
746 |
"RDI_Coords::binMapping{$RDI_Coords::binMapping} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
747 |
"RDI_Coords::beamTransformation{$RDI_Coords::beamTransformation} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
748 |
"pinging_duration{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
749 |
"cast_duration{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
750 |
"0.8_valid_bins{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
751 |
"0.8_valid_range{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
752 |
"max_depth{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
753 |
"depth_error{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
754 |
"min_range{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
755 |
"n_ensembles{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
756 |
"w_gap_time{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
757 |
"stderr_w{%.4f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
758 |
"rms_tilt{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
759 |
"downcast_rms_tilt{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
760 |
"upcast_rms_tilt{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
761 |
"rms_rotation{%.2f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
762 |
"deployment_rotations{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
763 |
"downcast_rotations{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
764 |
"upcast_rotations{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
765 |
"recovery_rotations{%d} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
766 |
"rms_heave_acceleration{%.2f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
767 |
"bin1_dist{%.1f} " . |
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
768 |
"bin_length{%.1f} " . |
5 | 769 |
"\n", |
770 |
($dta{ENSEMBLE}[$#{$dta{ENSEMBLE}}]->{UNIX_TIME} - |
|
771 |
$dta{ENSEMBLE}[0]->{UNIX_TIME}), |
|
0 | 772 |
$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME}, |
5 | 773 |
$gb+1, |
774 |
$dta{DISTANCE_TO_BIN1_CENTER} + $gb*$dta{BIN_LENGTH}, |
|
775 |
$dta{ENSEMBLE}[$atbottom]->{DEPTH}, |
|
776 |
$dta{ENSEMBLE}[$lastgood]->{DEPTH} - |
|
777 |
$dta{ENSEMBLE}[$firstgood]->{DEPTH}, |
|
778 |
$dta{DISTANCE_TO_BIN1_CENTER} + |
|
779 |
$min_good_bins*$dta{BIN_LENGTH}, |
|
780 |
scalar(@{$dta{ENSEMBLE}}), |
|
781 |
$w_gap_time,$wErr,$prrms,$dnprrms,$upprrms,$rotrms, |
|
8 | 782 |
$prerot,$dnrot,$uprot,$postrot,$rms_heave_accel, |
5 | 783 |
$dta{DISTANCE_TO_BIN1_CENTER}, |
784 |
$dta{BIN_LENGTH}, |
|
785 |
); |
|
786 |
printf("#ANTS#PARAMS# magnetic_declination{$opt_M} " . |
|
787 |
"uv_gap_time{%d} " . |
|
61 | 788 |
"u.mean{%.4f} " . |
789 |
"u.sterrr{%.4f} " . |
|
5 | 790 |
"dx{%d} " . |
61 | 791 |
"dx.err{%d} " . |
792 |
"v.mean{%.4f} " . |
|
793 |
"v.stderr{%.4f} " . |
|
5 | 794 |
"dy{%d} " . |
61 | 795 |
"dy.err{%d} " . |
796 |
"speed.mean{%.2f}\n", |
|
5 | 797 |
$uv_gap_time, |
798 |
$dta{ENSEMBLE}[$lastgood]->{X} / |
|
799 |
$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME}, |
|
800 |
$uErr, $dta{ENSEMBLE}[$lastgood]->{X}, $x_err, |
|
801 |
$dta{ENSEMBLE}[$lastgood]->{Y} / |
|
802 |
$dta{ENSEMBLE}[$lastgood]->{ELAPSED_TIME}, |
|
803 |
$vErr, $dta{ENSEMBLE}[$lastgood]->{Y}, $y_err, |
|
61 | 804 |
$cAvg |
5 | 805 |
) if defined ($opt_M); |
806 |
if ($dta{TIME_BETWEEN_PINGS} == 0) { |
|
807 |
print("#ANTS#PARAMS# pinging_rate{staggered}\n"); |
|
808 |
} else { |
|
809 |
printf("#ANTS#PARAMS# pinging_rate{%.2f}\n", |
|
810 |
1/$dta{TIME_BETWEEN_PINGS}); |
|
811 |
} |
|
812 |
if (defined($water_depth)) { |
|
813 |
printf("#ANTS#PARAMS# water_depth{%d} sig-water_depth{%d}\n", |
|
814 |
$water_depth,$sig_wd); |
|
815 |
} else { |
|
816 |
print("#ANTS#PARAMS# water_depth{nan} sig-water_depth{nan}\n"); |
|
0 | 817 |
} |
818 |
||
819 |
sub p($) { print(defined($_[0])?"$_[0] ":"nan "); } |
|
820 |
sub pb($) { print($_[0]?"1 ":"0 "); } |
|
821 |
||
5 | 822 |
for ($e=$firstgood; $e<=$lastgood; $e++) { |
823 |
p($dta{ENSEMBLE}[$e]->{NUMBER}); |
|
824 |
p($dta{ENSEMBLE}[$e]->{UNIX_TIME}); |
|
825 |
p($dta{ENSEMBLE}[$e]->{ELAPSED_TIME}); |
|
826 |
p($dta{ENSEMBLE}[$e]->{SECNO}); |
|
827 |
pb($dta{ENSEMBLE}[$e]->{UNIX_TIME} < $dta{ENSEMBLE}[$atbottom]->{UNIX_TIME}); |
|
828 |
p($dta{ENSEMBLE}[$e]->{W}); |
|
829 |
p($dta{ENSEMBLE}[$e]->{W_ERR}); |
|
12 | 830 |
p($dta{ENSEMBLE}[$e]->{ERR_VEL}); |
5 | 831 |
p($dta{ENSEMBLE}[$e]->{DEPTH}); |
832 |
p($dta{ENSEMBLE}[$e]->{DEPTH_ERR}); |
|
14 | 833 |
p($dta{ENSEMBLE}[$e]->{seabed}); |
18 | 834 |
p(&gimbal_pitch($dta{ENSEMBLE}[$e]->{PITCH},$dta{ENSEMBLE}[$e]->{ROLL})); |
835 |
p($dta{ENSEMBLE}[$e]->{ROLL}); |
|
836 |
p($dta{ENSEMBLE}[$e]->{TILT}); |
|
12 | 837 |
p($dta{ENSEMBLE}[$e]->{HEADING}); |
5 | 838 |
p($dta{ENSEMBLE}[$e]->{ROTATION}); |
839 |
if (defined($opt_M)) { |
|
840 |
p($dta{ENSEMBLE}[$e]->{U}); p($dta{ENSEMBLE}[$e]->{U_ERR}); |
|
841 |
p($dta{ENSEMBLE}[$e]->{V}); p($dta{ENSEMBLE}[$e]->{V_ERR}); |
|
842 |
p($dta{ENSEMBLE}[$e]->{X}); p($dta{ENSEMBLE}[$e]->{X_ERR}); |
|
843 |
p($dta{ENSEMBLE}[$e]->{Y}); p($dta{ENSEMBLE}[$e]->{Y_ERR}); |
|
61 | 844 |
p($dta{ENSEMBLE}[$e]->{SPEED}); |
5 | 845 |
} |
33 | 846 |
if (@f) { |
5 | 847 |
foreach $f (@f) { |
848 |
my($fn,$fi) = ($f =~ m{([^[]*)(\[.*)}); |
|
849 |
$fn = $f unless defined($fn); |
|
850 |
p(eval("\$dta{ENSEMBLE}[$e]->{$fn}$fi")); |
|
0 | 851 |
} |
852 |
} |
|
5 | 853 |
print("\n"); |
0 | 854 |
} |
855 |
||
856 |
exit(0); |