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