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