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