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