0
|
1 |
#!/usr/bin/perl
|
|
2 |
#======================================================================
|
|
3 |
# M E R G E C T D + L A D C P
|
|
4 |
# doc: Wed Apr 28 21:50:01 2010
|
|
5 |
# dlm: Fri Dec 17 16:51:33 2010
|
|
6 |
# (c) 2010 A.M. Thurnherr
|
|
7 |
# uE-Info: 25 44 NIL 0 0 72 2 2 4 NIL ofnI
|
|
8 |
#======================================================================
|
|
9 |
|
|
10 |
# TODO:
|
|
11 |
# - make sure range data in ADCP header are really along-beam
|
|
12 |
|
|
13 |
$antsSummary = 'match and merge LADCP with CTD time series for caclulating vertical velocities';
|
|
14 |
|
|
15 |
# HISTORY:
|
|
16 |
# Apr 28, 2010: - created early version
|
|
17 |
# May 12, 2010: - time-shift each ensemble separately (V2)
|
|
18 |
# May 21, 2010: - read raw LADCP files (V3)
|
|
19 |
# Jun 5, 2010: - first "fully debugged" version (V4)
|
|
20 |
# Oct 29, 2010: - hastily adapted to Earth coordinates
|
|
21 |
# Oct 30: 2010: - -w => -l, max -g)ap removed, added -w)ater depth
|
|
22 |
# Dec 14, 2010: - BUG: percentages were wrong (forgot to round)
|
|
23 |
# Dec 16, 2010: - removed hard-coded PERL_TOOLS directory
|
|
24 |
# - added -m)ax vertical velocity
|
|
25 |
# Dec 17, 2010: - added -a)djust CTD depth
|
|
26 |
|
|
27 |
# ASSUMPTIONS:
|
|
28 |
# - LADCP elapsed field lagged approximately at beginning of record
|
|
29 |
# - LADCP data collected with nominal soundspeed of 1500m/s
|
|
30 |
# - correct layout of old time-series file
|
|
31 |
|
|
32 |
# NOTES:
|
|
33 |
# - by default, bin 1 is not used
|
|
34 |
# - the initial lag estimate can be calculated by creating a 1Hz version
|
|
35 |
# of the CTD file; the number of seconds that are added to the CTD elapsed
|
|
36 |
# field to achieve a visually satisfying match is the initial guess for the lag
|
|
37 |
# - if there are a sequence of +ve jumps at the beginning of the profile, the
|
|
38 |
# initial lag estimate should be decreased
|
|
39 |
# - in a clean data set, decreasing -m should not be required; however,
|
|
40 |
# in some cases (ambiguity velocity too small?) there are large LADCP
|
|
41 |
# ref-lr w spikes that must be ignored; this can be accomplished by
|
|
42 |
# setting -m to a value like 1m/s; the symptom of the problem is usually
|
|
43 |
# that the time-lagging does not work
|
|
44 |
|
|
45 |
# POTENTIAL IMPROVEMENTS:
|
|
46 |
# - correct for sound-speed variations within instrument range
|
|
47 |
# - probably not important except perhaps near sea surface
|
|
48 |
# - cannot be done for data below max CTD depth
|
|
49 |
# - allow specifying vertical offset between CTD & ADCP
|
|
50 |
# - not important, given size of output bins
|
|
51 |
# - add edits for vertical & horizontal rotation velocities
|
|
52 |
# - may be important, as it is implemented in veloity inversion
|
|
53 |
# - add user-definable edit functions
|
|
54 |
# - estimate first guess of CTD_timoff
|
|
55 |
# - output correct ensemble number during warnings
|
|
56 |
|
|
57 |
($ANTS) = ($0 =~ m{^(.*)/[^/]*$});
|
|
58 |
($PERL_TOOLS) = (`which mkProfile` =~ m{^(.*)/[^/]*$});
|
|
59 |
|
|
60 |
require "$ANTS/ants.pl";
|
|
61 |
require "$ANTS/libstats.pl";
|
|
62 |
require "$ANTS/mergeCTD+LADCP.bestLag";
|
|
63 |
require "$ANTS/mergeCTD+LADCP.editData";
|
|
64 |
require "$ANTS/mergeCTD+LADCP.timeMatchingProblems";
|
|
65 |
require "$ANTS/mergeCTD+LADCP.LADCPtimeSeries";
|
|
66 |
require "$ANTS/mergeCTD+LADCP.seabed";
|
|
67 |
require "$PERL_TOOLS/RDI_BB_Read.pl";
|
|
68 |
require "$PERL_TOOLS/RDI_Coords.pl";
|
|
69 |
|
|
70 |
$antsParseHeader = 0;
|
|
71 |
&antsUsage('4a:b:c:d:e:fl:m:o:r:w:p:s:t:z:',2,
|
|
72 |
'[-w)ater <depth>]',
|
|
73 |
'[-l)ag-search <window[60s]>]',
|
|
74 |
'[max lag-s)earch <time[2s]> between LADCP ensembles]',
|
|
75 |
'[ref-l)ayer <bin[2],bin[6]>] [valid -b)ins for final w <bin[2],bin[*]>',
|
|
76 |
'[-c)orrelation <min[70]>] [-p)itch/roll <max[10deg]>',
|
|
77 |
'[-e)rr-vel <max[0.1m/s]>]',
|
|
78 |
'[-m)ax vertical <velocity[10m/s]>',
|
|
79 |
'[require -4)-beam solutions]',
|
|
80 |
'[read/write -t)imes-eries <file> [-f)orce re-make]]',
|
|
81 |
'[-o)uput bin <resolution[10m]>',
|
|
82 |
'[-d)ump depth-bins to <basename>]',
|
|
83 |
'[-a)djust CTD depth <by>] [CTD time re-z) <val[1/24s]>]',
|
|
84 |
'[--] <initial CTD time offset> <LADCP-file> [CTD-file]');
|
|
85 |
|
|
86 |
&antsFloatOpt(\$opt_a,0); # CTD depth adjustment
|
|
87 |
&antsFloatOpt(\$opt_z,1/24); # CTD time resolution
|
|
88 |
&antsFloatOpt(\$opt_l,60); # time-lagging window size
|
|
89 |
&antsFloatOpt(\$opt_s,2); # max possible CTD time jump btw LADCP pings
|
|
90 |
&antsFloatOpt(\$opt_c,70); # min correlation
|
|
91 |
&antsFloatOpt(\$opt_p,5); # max pitch/roll
|
|
92 |
&antsFloatOpt(\$opt_e,0.1); # max err vel
|
|
93 |
&antsFloatOpt(\$opt_m,1.0); # max allowed vertical velocity
|
|
94 |
&antsFloatOpt(\$opt_o,10); # max err vel
|
|
95 |
$opt_b = '2,*' unless defined($opt_b); # bins to use
|
|
96 |
$opt_r = '2,6' unless defined($opt_r); # reference layer bins for w for time matching
|
|
97 |
|
|
98 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # suppress 3-beam solutions
|
|
99 |
|
|
100 |
($LADCP_firstBin,$LADCP_lastBin) = split(',',$opt_b); # decode -b
|
|
101 |
croak("$0: cannot decode -b $opt_b\n")
|
|
102 |
unless (numberp($LADCP_firstBin) &&
|
|
103 |
($LADCP_lastBin eq '*' || numberp($LADCP_lastBin)));
|
|
104 |
|
|
105 |
($refLr_firstBin,$refLr_lastBin) = split(',',$opt_r); # decode -r
|
|
106 |
croak("$0: cannot decode -r $opt_r\n")
|
|
107 |
unless numberp($refLr_firstBin) && numberp($refLr_lastBin);
|
|
108 |
|
|
109 |
$CTD_timoff = &antsFloatArg(); # initial (good) guess
|
|
110 |
$LADCP_file = &antsFileArg();
|
|
111 |
|
|
112 |
{ my($warned) = 0; # handle warnings
|
|
113 |
|
|
114 |
sub warning(@)
|
|
115 |
{
|
|
116 |
print(STDERR "\n");
|
|
117 |
&antsInfo(@_);
|
|
118 |
$warned++;
|
|
119 |
croak("$0: too many warnings\n")
|
|
120 |
if ($warned > 10);
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
#======================================================================
|
|
125 |
# STAGE 1: match CTD to LADCP time series, find seabed, edit sidelobes
|
|
126 |
#
|
|
127 |
# KEY VARIABLES:
|
|
128 |
# $LADCP_bufStart index of first element in LADCP "buffer" [0]
|
|
129 |
# $ens index of current target elapsed time of LADCP
|
|
130 |
# $LADCP_bufEnd index of first element in LADCP "buffer" [$#LADCP]
|
|
131 |
# $CTD_trg index of record closest to target elapsed time in CTD buf
|
|
132 |
# $CTD_timoff current best CTD time offset
|
|
133 |
#======================================================================
|
|
134 |
|
|
135 |
#----------------------
|
|
136 |
# S1 STEP: Read LADCP data
|
|
137 |
#----------------------
|
|
138 |
|
|
139 |
print(STDERR "Reading LADCP data ($LADCP_file)...");
|
|
140 |
readData($LADCP_file,\%LADCP);
|
|
141 |
printf(STDERR "\n\t%d ensembles\n",scalar(@{$LADCP{ENSEMBLE}}));
|
|
142 |
|
|
143 |
croak("$LADCP_file: not enough LADCP bins ($LADCP{N_BINS}) for choice of -l\n")
|
|
144 |
unless ($LADCP{N_BINS} >= $refLr_lastBin);
|
|
145 |
#croak("$LADCP_file: require beam coordinates\n")
|
|
146 |
# unless ($LADCP{BEAM_COORDINATES});
|
|
147 |
|
|
148 |
croak("$0: first reference-layer bin outside valid range\n")
|
|
149 |
unless ($refLr_firstBin>=1 && $refLr_firstBin<=$LADCP{N_BINS});
|
|
150 |
croak("$0: last reference-layer bin outside valid range\n")
|
|
151 |
unless ($refLr_lastBin>=1 && $refLr_lastBin<=$LADCP{N_BINS});
|
|
152 |
croak("$0: first reference-layer bin > last reference-layer bin\n")
|
|
153 |
unless ($refLr_firstBin <= $refLr_lastBin);
|
|
154 |
|
|
155 |
$LADCP_lastBin = $LADCP{N_BINS}-1
|
|
156 |
if ($LADCP_lastBin eq '*');
|
|
157 |
croak("$0: first valid LADCP bin outside valid range\n")
|
|
158 |
unless ($LADCP_firstBin>=1 && $LADCP_firstBin<=$LADCP{N_BINS});
|
|
159 |
croak("$0: last valid LADCP bin outside valid range\n")
|
|
160 |
unless ($LADCP_lastBin>=1 && $LADCP_lastBin<=$LADCP{N_BINS});
|
|
161 |
croak("$0: first valid LADCP bin > last valid LADCP bin\n")
|
|
162 |
unless ($LADCP_firstBin <= $LADCP_lastBin);
|
|
163 |
|
|
164 |
warning("WARNING: first reference-layer bin < first valid LADCP bin")
|
|
165 |
unless ($refLr_firstBin >= $LADCP_firstBin);
|
|
166 |
warning("WARNING: last reference-layer bin > last valid LADCP bin")
|
|
167 |
unless ($refLr_lastBin <= $LADCP_lastBin);
|
|
168 |
|
|
169 |
warning("WARNING: if at all, bin 1 should not be used for short blank-after-transmit values")
|
|
170 |
if ($LADCP{BLANKING_DISTANCE} < $LADCP{BIN_LENGTH} &&
|
|
171 |
($LADCP_firstBin == 1 || $refLr_firstBin == 1));
|
|
172 |
|
|
173 |
#--------------------------------------------------------------------
|
|
174 |
# S1 STEP: Edit beam-velocity data
|
|
175 |
# 1) correlation threshold
|
|
176 |
# 2) pitch/roll threshold
|
|
177 |
#--------------------------------------------------------------------
|
|
178 |
|
|
179 |
if ($LADCP{BEAM_COORDINATES}) {
|
|
180 |
print(STDERR "Editing beam-velocity data...");
|
|
181 |
$nvv = $cte = 0;
|
|
182 |
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
|
|
183 |
$nvv += countValidBeamVels($ens);
|
|
184 |
$cte += editCorr($ens,$opt_c);
|
|
185 |
$pte += editPitchRoll($ens,$opt_p);
|
|
186 |
}
|
|
187 |
print(STDERR "\n");
|
|
188 |
printf(STDERR "\tcorrelation threshold (-c %d): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv));
|
|
189 |
printf(STDERR "\tattitude threshold (-p %d): %d velocites removed (%d%% of total)\n",$opt_p,$pte,round(100*$pte/$nvv));
|
|
190 |
} else {
|
|
191 |
print(STDERR "Editing velocity data...");
|
|
192 |
$nvv = $cte = 0;
|
|
193 |
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
|
|
194 |
$nvv += countValidBeamVels($ens);
|
|
195 |
$cte += editCorr_Earthcoords($ens,$opt_c);
|
|
196 |
$pte += editPitchRoll($ens,$opt_p);
|
|
197 |
}
|
|
198 |
print(STDERR "\n");
|
|
199 |
printf(STDERR "\tcorrelation threshold (-c %d): %d velocites removed (%d%% of total)\n",$opt_c,$cte,round(100*$cte/$nvv));
|
|
200 |
printf(STDERR "\tattitude threshold (-p %d): %d velocites removed (%d%% of total)\n",$opt_p,$pte,round(100*$pte/$nvv));
|
|
201 |
}
|
|
202 |
|
|
203 |
#--------------------------------------------------------------------
|
|
204 |
# S1 STEP: Calculate earth velocities
|
|
205 |
# - this is done for all bins (not just valid ones), to allow
|
|
206 |
# useless possibility that invalid bins are used for reflr calcs
|
|
207 |
#--------------------------------------------------------------------
|
|
208 |
|
|
209 |
if ($LADCP{BEAM_COORDINATES}) {
|
|
210 |
print(STDERR "Calculating earth-coordinate velocities...");
|
|
211 |
$nvw = 0;
|
|
212 |
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
|
|
213 |
for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
|
|
214 |
($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
|
|
215 |
$LADCP{ENSEMBLE}[$ens]->{V}[$bin],
|
|
216 |
$LADCP{ENSEMBLE}[$ens]->{W}[$bin],
|
|
217 |
$LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) =
|
|
218 |
velInstrumentToEarth(\%LADCP,$ens,
|
|
219 |
velBeamToInstrument(\%LADCP,
|
|
220 |
@{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]}));
|
|
221 |
$nvw += defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
|
|
222 |
}
|
|
223 |
}
|
|
224 |
print(STDERR "\n\t$nvw valid velocities\n");
|
|
225 |
printf(STDERR "\t3-beam solutions : $RDI_Coords::threeBeam_1 " .
|
|
226 |
"$RDI_Coords::threeBeam_2 " .
|
|
227 |
"$RDI_Coords::threeBeam_3 " .
|
|
228 |
"$RDI_Coords::threeBeam_4\n")
|
|
229 |
unless ($opt_4);
|
|
230 |
} else {
|
|
231 |
print(STDERR "Counting valid vertical velocities...");
|
|
232 |
$nvw = 0;
|
|
233 |
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
|
|
234 |
for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
|
|
235 |
($LADCP{ENSEMBLE}[$ens]->{U}[$bin],
|
|
236 |
$LADCP{ENSEMBLE}[$ens]->{V}[$bin],
|
|
237 |
$LADCP{ENSEMBLE}[$ens]->{W}[$bin],
|
|
238 |
$LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) = @{$LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin]};
|
|
239 |
$nvw += defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
|
|
240 |
}
|
|
241 |
}
|
|
242 |
print(STDERR "\n\t$nvw valid velocities\n");
|
|
243 |
}
|
|
244 |
|
|
245 |
#--------------------------------------------------------------------
|
|
246 |
# S1 STEP: Edit earth-coordinate -velocity data
|
|
247 |
# 1) error-velocity threshold
|
|
248 |
#--------------------------------------------------------------------
|
|
249 |
|
|
250 |
print(STDERR "Editing earth-coordinate velocity data...");
|
|
251 |
|
|
252 |
$ete = 0;
|
|
253 |
for ($ens=0; $ens<=$#{$LADCP{ENSEMBLE}}; $ens++) {
|
|
254 |
$ete += editErrVel($ens,$opt_e);
|
|
255 |
}
|
|
256 |
printf(STDERR "\n\t error-velocity threshold (-e %.1f): %d velocites removed (%d%% of total)\n",$opt_e,$ete,round(100*$ete/$nvw));
|
|
257 |
|
|
258 |
#----------------------------------------------------------------------
|
|
259 |
# S1 BRANCH POINT: If up-to-date time-series file is found, read it
|
|
260 |
# and skip to STAGE 2
|
|
261 |
#----------------------------------------------------------------------
|
|
262 |
|
|
263 |
if ($opt_t && -f $opt_t) {
|
|
264 |
print(STDERR "Time-series file <$opt_t> found:\n");
|
|
265 |
|
|
266 |
my(@s,$ct,$Lct,$Cct);
|
|
267 |
my($ctf) = 10;
|
|
268 |
|
|
269 |
die unless (@s = stat($opt_t)); $ct = $s[$ctf]; # ctime of time-series file
|
|
270 |
die unless (@s = stat($LADCP_file)); my($Lct) = $s[$ctf]; # ctime of LADCP file
|
|
271 |
printf(STDERR "\t%s wrt $LADCP_file\n",$Lct>$ct ? 'stale' : 'up-to-date');
|
|
272 |
|
|
273 |
if ($ARGV[0] eq '-') {
|
|
274 |
print(STDERR "\tCTD data on stdin assumed up-to-date\n");
|
|
275 |
} else {
|
|
276 |
die("$ARGV[0]: $!") unless (@s = stat($ARGV[0])); $Cct = $s[$ctf]; # ctime of CTD file
|
|
277 |
printf(STDERR "\t%s wrt $ARGV[0]\n",$Cct>$ct ? 'stale' : 'up-to-date');
|
|
278 |
}
|
|
279 |
|
|
280 |
if ($ct >= $LCt && $ct >= $Cct && !$opt_f) { # read time-series file
|
|
281 |
print(STDERR "\t-> reading time-series data from <$opt_t>...");
|
|
282 |
|
|
283 |
croak("$0: need CTD data\n") # read 1st CTD rec
|
|
284 |
unless (&antsIn()); # to get %PARAMs
|
|
285 |
|
|
286 |
open(F,$opt_t) || croak("$opt_t: $!\n");
|
|
287 |
|
|
288 |
$firstGoodEns = &antsFileScanParam(F,'LADCP_prof_start');
|
|
289 |
$LADCP_atbottom = &antsFileScanParam(F,'LADCP_at_bottom');
|
|
290 |
$lastGoodEns = &antsFileScanParam(F,'LADCP_prof_end');
|
|
291 |
$water_depth = &antsFileScanParam(F,'water_depth');
|
|
292 |
$sig_water_depth= &antsFileScanParam(F,'water_depth.sig');
|
|
293 |
&antsAddParams('rms_w_reflr_err',&antsFileScanParam(F,'rms_w_reflr_err'),
|
|
294 |
'rms_w_reflr_err_interior',&antsFileScanParam(F,'rms_w_reflr_err_interior'),
|
|
295 |
'LADCP_prof_start',&antsFileScanParam(F,'LADCP_prof_start'),
|
|
296 |
'LADCP_at_bottom',&antsFileScanParam(F,'LADCP_at_bottom'),
|
|
297 |
'LADCP_prof_end',&antsFileScanParam(F,'LADCP_prof_end'));
|
|
298 |
|
|
299 |
for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
|
|
300 |
my(@r) = &antsFileIn(F);
|
|
301 |
die("$0: assertion failed") unless(@r);
|
|
302 |
|
|
303 |
my($f) = 0;
|
|
304 |
croak("Incompatible time-series file (expected ens $ens, got $r[$f])?\n")
|
|
305 |
unless ($r[$f] == $ens);
|
|
306 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME} = $r[++$f];
|
|
307 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_MISMATCH} = $r[++$f];
|
|
308 |
$LADCP{ENSEMBLE}[$ens]->{CTD_TIMOFF} = $r[++$f];
|
|
309 |
$LADCP{ENSEMBLE}[$ens]->{PAST_LAG} = $r[++$f];
|
|
310 |
$LADCP{ENSEMBLE}[$ens]->{PAST_ERR} = $r[++$f];
|
|
311 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_LAG} = $r[++$f];
|
|
312 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_ERR} = $r[++$f];
|
|
313 |
$LADCP{ENSEMBLE}[$ens]->{DEPTH} = $r[++$f];
|
|
314 |
$LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED} = $r[++$f];
|
|
315 |
$LADCP{ENSEMBLE}[$ens]->{PITCH} = $r[++$f];
|
|
316 |
$LADCP{ENSEMBLE}[$ens]->{ROLL} = $r[++$f];
|
|
317 |
$LADCP{ENSEMBLE}[$ens]->{HEADING} = $r[++$f];
|
|
318 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W} = $r[++$f];
|
|
319 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W_T} = $r[++$f];
|
|
320 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W} = $r[++$f];
|
|
321 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W_ERR} = $r[++$f];
|
|
322 |
}
|
|
323 |
close(F);
|
|
324 |
|
|
325 |
print(STDERR "done\n");
|
|
326 |
goto STAGE_2;
|
|
327 |
}
|
|
328 |
}
|
|
329 |
|
|
330 |
#-----------------------------------
|
|
331 |
# S1 STEP: Calculated LADCP time series
|
|
332 |
#-----------------------------------
|
|
333 |
|
|
334 |
print(STDERR "Calculating LADCP time-series...");
|
|
335 |
|
|
336 |
($firstGoodEns,$lastGoodEns,$LADCP_atbottom,$LADCP_w_gap_time) =
|
|
337 |
calcLADCPts(\%LADCP,$refLr_firstBin,$refLr_lastBin,$opt_g);
|
|
338 |
croak("$LADCP_file: no good ensembles\n")
|
|
339 |
unless defined($firstGoodEns);
|
|
340 |
|
|
341 |
printf(STDERR "\n\tStart of cast : %s (#%5d)\n",
|
|
342 |
$LADCP{ENSEMBLE}[$firstGoodEns]->{TIME},
|
|
343 |
$LADCP{ENSEMBLE}[$firstGoodEns]->{NUMBER});
|
|
344 |
printf(STDERR "\tBottom of cast: %s (#%5d)\n",
|
|
345 |
$LADCP{ENSEMBLE}[$LADCP_atbottom]->{TIME},
|
|
346 |
$LADCP{ENSEMBLE}[$LADCP_atbottom]->{NUMBER});
|
|
347 |
printf(STDERR "\tEnd of cast : %s (#%5d)\n",
|
|
348 |
$LADCP{ENSEMBLE}[$lastGoodEns]->{TIME},
|
|
349 |
$LADCP{ENSEMBLE}[$lastGoodEns]->{NUMBER});
|
|
350 |
$cast_duration = int($LADCP{ENSEMBLE}[$lastGoodEns]->{ELAPSED_TIME} -
|
|
351 |
$LADCP{ENSEMBLE}[$firstGoodEns]->{ELAPSED_TIME});
|
|
352 |
printf(STDERR "\tCast Duration : %.1f hours (pinging for %.1f hours)\n",
|
|
353 |
$cast_duration / 3600,
|
|
354 |
($LADCP{ENSEMBLE}[$#{$LADCP{ENSEMBLE}}]->{UNIX_TIME} -
|
|
355 |
$LADCP{ENSEMBLE}[0]->{UNIX_TIME}) / 3600);
|
|
356 |
|
|
357 |
croak("$0: no valid LADCP data\n")
|
|
358 |
unless ($lastGoodEns-$firstGoodEns > 0);
|
|
359 |
|
|
360 |
croak("$0: implausibly short cast ($cast_duration seconds)\n")
|
|
361 |
unless ($cast_duration > 600);
|
|
362 |
|
|
363 |
|
|
364 |
#------------------------------------------------
|
|
365 |
# S1 STEP: time-lag CTD time series to each ensemble
|
|
366 |
#
|
|
367 |
# NOTES:
|
|
368 |
# - time lag done in window of size (in seconds) $opt_l
|
|
369 |
# - after this step, reflr w is sound-speed corrected!!!
|
|
370 |
#------------------------------------------------
|
|
371 |
|
|
372 |
print(STDERR "Matching CTD to LADCP data");
|
|
373 |
|
|
374 |
$LADCP_bufStart = $ens = $LADCP_bufEnd = $firstGoodEns; # init pointers
|
|
375 |
|
|
376 |
sub growLADCPbuf() # adjust $LADCP_bufEnd
|
|
377 |
{ # can safely be called often :-)
|
|
378 |
$LADCP_bufEnd++ while ($LADCP_bufEnd<=$lastGoodEns && &Le($LADCP_bufEnd)-&Le($ens) < $opt_l);
|
|
379 |
return $LADCP_bufEnd<=$lastGoodEns;
|
|
380 |
}
|
|
381 |
|
|
382 |
$sumWsq = $nWsq = $sumWsqI= $nWsqI = 0; # for rms(w_ocean_ref_lr)
|
|
383 |
|
|
384 |
$antsBufSkip = 0; # don't remove recs from buf
|
|
385 |
croak("$0: need CTD data\n")
|
|
386 |
unless (&antsIn()); # read 1st CTD rec
|
|
387 |
($CTD_elapsed,$CTD_depth,$CTD_w,$CTD_w_t,$CTD_svel) = # decode CTD Layout
|
|
388 |
&fnr('elapsed','depth','w','w_t','ss');
|
|
389 |
&antsInstallBufFull('&Ce($#ants_)-&Le($ens) >= $opt_l+$opt_s'); # CTD buffer full criterion
|
|
390 |
&antsIn(); # fill CTD buffer for 1st LADCP ens
|
|
391 |
&growLADCPbuf(); # set up LADCP buffer pointers
|
|
392 |
|
|
393 |
if (&Ce(0) > &Le($LADCP_bufStart)) { # CTD data begin with CTD in water
|
|
394 |
print(STDERR "\n");
|
|
395 |
&antsInfo("CTD data begin with LADCP in water (Ce = %f, Le = %f)",&Ce(0),&Le($LADCP_bufStart));
|
|
396 |
$ens++,$LADCP_bufStart++ while (&Ce(0) > &Le($LADCP_bufStart));
|
|
397 |
&growLADCPbuf();
|
|
398 |
&antsIn();
|
|
399 |
}
|
|
400 |
|
|
401 |
die(sprintf("$0: assertion failed (ens=$ens, Ce($#ants_) = %f, Le($ens) = %f)",&Ce($#ants_),&Le($ens)))
|
|
402 |
unless (&Ce($#ants_) >= &Le($ens));
|
|
403 |
|
|
404 |
$CTD_trg = $#ants_ - int(($opt_l+$opt_s)/$opt_z); # nearest CTD record is -w + -s before end
|
|
405 |
$CTD_trg++ if (abs(&Ce($CTD_trg)-&Le($ens)) > abs(&Ce($CTD_trg+1)-&Le($ens))); # determine nearer of two bracketing recs
|
|
406 |
$CTD_trg-- if (abs(&Ce($CTD_trg)-&Le($ens)) > abs(&Ce($CTD_trg-1)-&Le($ens))); # can happen when CTD data begin with LADCP in water
|
|
407 |
|
|
408 |
while ($ens <= $lastGoodEns && &growLADCPbuf()) { # 2nd test required on EOF(CTD)
|
|
409 |
# printf(STDERR "target = %f\n",&Le($ens));
|
|
410 |
die("$0: assertion failed (CTD_trg=$CTD_trg, ens=$ens)") unless ($CTD_trg>=0 && $CTD_trg<=$#ants_);
|
|
411 |
die("$0: assertion failed (ens=$ens)") unless ($ens>=0 && $ens<=$LADCP_bufEnd);
|
|
412 |
die(sprintf("$0: assertion failed (ens=$ens, abs(%f-%f) > $opt_z/2)",&Ce($CTD_trg-1),&Le($ens)))
|
|
413 |
unless (abs(&Ce($CTD_trg)-&Le($ens)) <= $opt_z/2);
|
|
414 |
|
|
415 |
$LADCP_bufStart++ while (&Le($ens)-&Le($LADCP_bufStart+1) >= $opt_l); # shift beginning of LADCP buffer
|
|
416 |
die("$0: assertion failed (ens=$ens)") unless ($ens>=$LADCP_bufStart);
|
|
417 |
die("$0: assertion failed (ens=$ens)") unless (abs(&Ce($CTD_trg)-&Le($ens)) <= $opt_z/2);
|
|
418 |
|
|
419 |
if (&Le($ens)-&Le($LADCP_bufStart) >= $opt_l) { # find best lag using past data
|
|
420 |
($pCts,$pErr) = &bestLag($LADCP_bufStart,$ens,$ens,$CTD_trg);
|
|
421 |
$pLag = $pCts - $CTD_trg;
|
|
422 |
} else {
|
|
423 |
$pCts = $pErr = $pLag = undef;
|
|
424 |
}
|
|
425 |
|
|
426 |
if (&Le($LADCP_bufEnd)-&Le($ens) >= $opt_l && # find best lag using future data
|
|
427 |
&Ce($#ants_)-&Le($ens) >= $opt_l+$opt_s) {
|
|
428 |
($fCts,$fErr) = &bestLag($ens,$LADCP_bufEnd,$ens,$CTD_trg);
|
|
429 |
$fLag = $fCts - $CTD_trg;
|
|
430 |
} else {
|
|
431 |
$fCts = $fErr = $fLag = undef;
|
|
432 |
}
|
|
433 |
|
|
434 |
if ((defined($fErr) && defined($pErr) && $pErr <= $fErr) || # past data are better correlated
|
|
435 |
(defined($pErr) && !defined($fErr))) {
|
|
436 |
$CTD_timoff -= ($pCts-$CTD_trg) * $opt_z;
|
|
437 |
$CTD_trg = $pCts;
|
|
438 |
} elsif ((defined($fErr) && defined($pErr) && $fErr <= $pErr) || # return w based on future lagcorr
|
|
439 |
(defined($fErr) && !defined($pErr))) {
|
|
440 |
$CTD_timoff -= ($fCts-$CTD_trg) * $opt_z;
|
|
441 |
$CTD_trg = $fCts;
|
|
442 |
}
|
|
443 |
die("$0: assertion failed (ens=$ens)") unless ($CTD_trg>=0 && $CTD_trg<=$#ants_);
|
|
444 |
die("$0: assertion failed (ens=$ens)") unless (abs(&Ce($CTD_trg)-&Le($ens)) <= $opt_z/2);
|
|
445 |
|
|
446 |
croak("$0: CTD velocity spike >5m/s at elapsed time = $ants_[$CTD_trg][$CTD_elapsed]\n")
|
|
447 |
if (abs($ants_[$CTD_trg][$CTD_w] > 5));
|
|
448 |
|
|
449 |
&detectTimeMatchingProblems($ens,$ants_[$CTD_trg][$CTD_depth]+$opt_a,$oCo,$CTD_timoff)
|
|
450 |
if defined($oCo);
|
|
451 |
$oCo = $CTD_timoff;
|
|
452 |
|
|
453 |
if (defined($LADCP{ENSEMBLE}[$ens]->{REFLR_W}) && # not a gap
|
|
454 |
(defined($fErr) || defined($pErr))) { # at least one correlation is defined
|
|
455 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W} *= $ants_[$CTD_trg][$CTD_svel]/1500; # correct for sound-speed variations
|
|
456 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_MISMATCH} = &Ce($CTD_trg) - &Le($ens);
|
|
457 |
$LADCP{ENSEMBLE}[$ens]->{CTD_TIMOFF} = $CTD_timoff;
|
|
458 |
$LADCP{ENSEMBLE}[$ens]->{PAST_LAG} = $pLag;
|
|
459 |
$LADCP{ENSEMBLE}[$ens]->{PAST_ERR} = $pErr;
|
|
460 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_LAG} = $fLag;
|
|
461 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_ERR} = $fErr;
|
|
462 |
croak(sprintf("\n$0: negative depth (%.1fm) in CTD file at elapsed = %.1fs (use -a?)\n",
|
|
463 |
$ants_[$CTD_trg][$CTD_depth]+$opt_a,$ants_[$CTD_trg][$CTD_elapsed]))
|
|
464 |
unless ($ants_[$CTD_trg][$CTD_depth]+$opt_a >= 0);
|
|
465 |
$LADCP{ENSEMBLE}[$ens]->{DEPTH} = $ants_[$CTD_trg][$CTD_depth]+$opt_a;
|
|
466 |
$LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED} = $ants_[$CTD_trg][$CTD_svel];
|
|
467 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W} = $ants_[$CTD_trg][$CTD_w];
|
|
468 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W_T} = $ants_[$CTD_trg][$CTD_w_t];
|
|
469 |
my($reflr_ocean_w) = $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $LADCP{ENSEMBLE}[$ens]->{CTD_W};
|
|
470 |
if (abs($reflr_ocean_w) <= $opt_m) {
|
|
471 |
$sumWsq += &SQR($reflr_ocean_w);
|
|
472 |
$nWsq++;
|
|
473 |
if ($LADCP{ENSEMBLE}[$ens]->{DEPTH} > 100 &&
|
|
474 |
$LADCP{ENSEMBLE}[$ens]->{DEPTH} < $LADCP{ENSEMBLE}[$LADCP_atbottom]->{DEPTH}-100) {
|
|
475 |
$sumWsqI += &SQR($reflr_ocean_w);
|
|
476 |
$nWsqI++;
|
|
477 |
}
|
|
478 |
} else {
|
|
479 |
undef($LADCP{ENSEMBLE}[$ens]->{DEPTH}); # DON'T USE THIS ENSEMBLE LATER
|
|
480 |
}
|
|
481 |
} else{
|
|
482 |
undef($LADCP{ENSEMBLE}[$ens]->{REFLR_W}); # don't output in time-series file
|
|
483 |
undef($LADCP{ENSEMBLE}[$ens]->{DEPTH}); # old DEPTH from calcLADCPts()
|
|
484 |
}
|
|
485 |
|
|
486 |
$ens++; # update target indices
|
|
487 |
$CTD_trg += int((&Le($ens)-&Le($ens-1)) / $opt_z); # NB: int() rounds down
|
|
488 |
unless ($CTD_trg <= $#ants_) {
|
|
489 |
print(STDERR "\n");
|
|
490 |
&antsInfo("CTD data end with LADCP in water");
|
|
491 |
last;
|
|
492 |
}
|
|
493 |
$CTD_trg++ if (abs(&Le($ens)-&Ce($CTD_trg+1)) < abs(&Le($ens)-&Ce($CTD_trg)));
|
|
494 |
die("$0: assertion failed (ens=$ens)") unless ($CTD_trg>=0 && $CTD_trg<=$#ants_);
|
|
495 |
die("$0: assertion failed (ens=$ens)") unless (abs(&Ce($CTD_trg)-&Le($ens)) <= $opt_z/2);
|
|
496 |
|
|
497 |
while (&Le($ens)-&Ce(1) >= $opt_l+$opt_s) { # remove no-longer-needed CTD records
|
|
498 |
splice(@ants_,0,1);
|
|
499 |
$CTD_trg--;
|
|
500 |
}
|
|
501 |
die("$0: assertion failed (ens=$ens)") unless ($CTD_trg>=0 && $CTD_trg<=$#ants_);
|
|
502 |
die("$0: assertion failed (ens=$ens)") unless (abs(&Ce($CTD_trg)-&Le($ens)) <= $opt_z/2);
|
|
503 |
|
|
504 |
$eof = !&antsIn() unless ($eof); # don't antsIn after EOF
|
|
505 |
|
|
506 |
print(STDERR '.')
|
|
507 |
if ($ens % 100 == 0);
|
|
508 |
}
|
|
509 |
|
|
510 |
if ($nWsq > 0 && $nWsqI > 0) {
|
|
511 |
&antsAddParams('rms_w_reflr_err',sqrt($sumWsq/$nWsq),'rms_w_reflr_err_interior',sqrt($sumWsqI/$nWsqI));
|
|
512 |
printf(STDERR "\n\t%.2f cm/s rms reference-layer w_ocean, %.2f cm/s away from boundaries\n",
|
|
513 |
100*sqrt($sumWsq/$nWsq),100*sqrt($sumWsqI/$nWsqI));
|
|
514 |
croak("$0: rms reference-layer w_ocean is too large\n")
|
|
515 |
unless (sqrt($sumWsqI/$nWsqI) < 0.05);
|
|
516 |
} elsif ($nWsq > 0) {
|
|
517 |
&antsAddParams('rms_w_reflr_err',sqrt($sumWsq/$nWsq),'rms_w_reflr_err_interior',nan);
|
|
518 |
printf(STDERR "\n\t%.2f cm/s rms reference-layer w_ocean\n",100*sqrt($sumWsq/$nWsq));
|
|
519 |
} else {
|
|
520 |
croak("$0: no valid vertical velocities\n");
|
|
521 |
}
|
|
522 |
|
|
523 |
#----------------------
|
|
524 |
# S1 STEP: Find seabed
|
|
525 |
#----------------------
|
|
526 |
|
|
527 |
if (defined($opt_w)) {
|
|
528 |
print(STDERR "Using specified water depth...");
|
|
529 |
$water_depth = $opt_w; $sig_water_depth = nan;
|
|
530 |
} else {
|
|
531 |
print(STDERR "Finding seabed...");
|
|
532 |
($water_depth,$sig_water_depth) =
|
|
533 |
find_seabed(\%LADCP,$LADCP_atbottom,$LADCP{BEAM_COORDINATES});
|
|
534 |
}
|
|
535 |
|
|
536 |
&antsAddParams('water_depth',$water_depth,'water_depth.sig',$sig_water_depth);
|
|
537 |
printf(STDERR "\n\t%d(%d) m water depth",$water_depth,$sig_water_depth)
|
|
538 |
if defined($water_depth);
|
|
539 |
print(STDERR "\n");
|
|
540 |
|
|
541 |
#-----------------------------------
|
|
542 |
# S1 STEP: write time-series output
|
|
543 |
#-----------------------------------
|
|
544 |
|
|
545 |
if (defined($opt_t)) {
|
|
546 |
print(STDERR "Writing time-series data to <$opt_t>...");
|
|
547 |
|
|
548 |
@antsNewLayout = ('ens','elapsed','elapsed_mismatch','CTD_time_offset',
|
|
549 |
'past_lag','past_err','future_lag','future_err',
|
|
550 |
'depth','sound_speed','pitch','roll','heading',
|
|
551 |
'CTD_w','CTD_w_t','LADCP_reflr_w','LADCP_reflr_w_err',
|
|
552 |
'ocean_reflr_w');
|
|
553 |
|
|
554 |
&antsAddParams('LADCP_prof_start',$firstGoodEns, # required to make -t loadable
|
|
555 |
'LADCP_at_bottom',$LADCP_atbottom,
|
|
556 |
'LADCP_prof_end',$lastGoodEns);
|
|
557 |
|
|
558 |
close(STDOUT);
|
|
559 |
open(STDOUT,">$opt_t") || croak("$opt_t: $!\n");
|
|
560 |
|
|
561 |
for ($ens=$firstGoodEns; $ens<=$lastGoodEns; $ens++) {
|
|
562 |
my($reflr_w) = defined($LADCP{ENSEMBLE}[$ens]->{REFLR_W})
|
|
563 |
? $LADCP{ENSEMBLE}[$ens]->{REFLR_W} - $LADCP{ENSEMBLE}[$ens]->{CTD_W}
|
|
564 |
: undef;
|
|
565 |
&antsOut($ens,
|
|
566 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME},
|
|
567 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_MISMATCH},
|
|
568 |
$LADCP{ENSEMBLE}[$ens]->{CTD_TIMOFF},
|
|
569 |
$LADCP{ENSEMBLE}[$ens]->{PAST_LAG},
|
|
570 |
$LADCP{ENSEMBLE}[$ens]->{PAST_ERR},
|
|
571 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_LAG},
|
|
572 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_ERR},
|
|
573 |
$LADCP{ENSEMBLE}[$ens]->{DEPTH},
|
|
574 |
$LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED},
|
|
575 |
$LADCP{ENSEMBLE}[$ens]->{PITCH},
|
|
576 |
$LADCP{ENSEMBLE}[$ens]->{ROLL},
|
|
577 |
$LADCP{ENSEMBLE}[$ens]->{HEADING},
|
|
578 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W}, # NB: sound-speed corrected above
|
|
579 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W_T},
|
|
580 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W},
|
|
581 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W_ERR},
|
|
582 |
$reflr_w);
|
|
583 |
}
|
|
584 |
|
|
585 |
close(STDOUT);
|
|
586 |
undef($antsHeadersPrinted);
|
|
587 |
|
|
588 |
print(STDERR "done\n");
|
|
589 |
}
|
|
590 |
|
|
591 |
#======================================================================
|
|
592 |
# STAGE 2: bin vertical velocities in depth space
|
|
593 |
#======================================================================
|
|
594 |
|
|
595 |
STAGE_2:
|
|
596 |
|
|
597 |
#-----------------------------------------------------------------------------------------
|
|
598 |
# S2 STEP: Remove data contaminated by sidelobe reflection from seabed and sea surface
|
|
599 |
#-----------------------------------------------------------------------------------------
|
|
600 |
|
|
601 |
if ($LADCP{ENSEMBLE}[$LADCP_atbottom]->{XDUCER_FACING_DOWN} && !defined($water_depth)) {
|
|
602 |
print(STDERR "\n");
|
|
603 |
warning("WARNING: could not find seabed --- no sidelobe editing done");
|
|
604 |
print(STDERR "\n");
|
|
605 |
} else {
|
|
606 |
print(STDERR "Editing data to remove sidelobe interference from seabed or seasurface...");
|
|
607 |
($nvrm,$nerm) = editSideLobes($firstGoodEns,$lastGoodEns,$water_depth);
|
|
608 |
print(STDERR "\n\t$nvrm velocities from $nerm ensembles removed\n");
|
|
609 |
}
|
|
610 |
|
|
611 |
#---------------------------------------------------------------------------
|
|
612 |
# S2 STEP: Depth-bin LADCP velocity data
|
|
613 |
#
|
|
614 |
# NOTES:
|
|
615 |
# 1) ensemble and bin numbers are saved for maximum flexibility
|
|
616 |
# 2) only ensemble/bins with valid vertical velocities are saved
|
|
617 |
#---------------------------------------------------------------------------
|
|
618 |
|
|
619 |
print(STDERR "Depth-binning ocean velocities...");
|
|
620 |
|
|
621 |
sub bino($) {
|
|
622 |
my($depth) = @_;
|
|
623 |
&debug(),die("$0: assertion failed (ens = $ens, bin = $bin, depth = $depth, water_depth = $water_depth)")
|
|
624 |
if ($depth<0 || (defined($water_depth) && $depth>$water_depth));
|
|
625 |
return int($depth/$opt_o);
|
|
626 |
}
|
|
627 |
|
|
628 |
for ($ens=$firstGoodEns; $ens<$LADCP_atbottom; $ens++) { # downcast
|
|
629 |
my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED}/1500;
|
|
630 |
my($d1c) = $sscorr * $LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{BEAM_ANGLE}));
|
|
631 |
my($blc) = $sscorr * $LADCP{BIN_LENGTH}*cos(rad($LADCP{BEAM_ANGLE}));
|
|
632 |
for ($bin=$LADCP_firstBin-1,$dz=$d1c+$LADCP_firstBin*$blc; $bin<=$LADCP_lastBin-1; $bin++,$dz+=$blc) {
|
|
633 |
next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]) &&
|
|
634 |
numberp($LADCP{ENSEMBLE}[$ens]->{DEPTH});
|
|
635 |
my($depth) = $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}
|
|
636 |
? $LADCP{ENSEMBLE}[$ens]->{DEPTH} - $dz
|
|
637 |
: $LADCP{ENSEMBLE}[$ens]->{DEPTH} + $dz;
|
|
638 |
my($bi) = bino($depth);
|
|
639 |
push(@{$DNCAST{ENS}[$bi]},$ens);
|
|
640 |
push(@{$DNCAST{BIN}[$bi]},$bin);
|
|
641 |
push(@{$DNCAST{DEPTH}[$bi]},$depth);
|
|
642 |
}
|
|
643 |
}
|
|
644 |
|
|
645 |
for ($ens=$LADCP_atbottom; $ens<=$lastGoodEns; $ens++) { # upcast
|
|
646 |
my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED}/1500;
|
|
647 |
my($d1c) = $sscorr * $LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{BEAM_ANGLE}));
|
|
648 |
my($blc) = $sscorr * $LADCP{BIN_LENGTH}*cos(rad($LADCP{BEAM_ANGLE}));
|
|
649 |
for ($bin=$LADCP_firstBin-1,$dz=$d1c+$LADCP_firstBin*$blc; $bin<=$LADCP_lastBin-1; $bin++,$dz+=$blc) {
|
|
650 |
next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]) &&
|
|
651 |
numberp($LADCP{ENSEMBLE}[$ens]->{DEPTH});
|
|
652 |
my($depth) = $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}
|
|
653 |
? $LADCP{ENSEMBLE}[$ens]->{DEPTH} - $dz
|
|
654 |
: $LADCP{ENSEMBLE}[$ens]->{DEPTH} + $dz;
|
|
655 |
my($bi) = bino($depth);
|
|
656 |
push(@{$UPCAST{ENS}[$bi]},$ens);
|
|
657 |
push(@{$UPCAST{BIN}[$bi]},$bin);
|
|
658 |
push(@{$UPCAST{DEPTH}[$bi]},$depth);
|
|
659 |
}
|
|
660 |
}
|
|
661 |
|
|
662 |
print(STDERR "\n");
|
|
663 |
|
|
664 |
#---------------------------------------------------------------
|
|
665 |
# S2 STEP: Output all bins as separate files
|
|
666 |
#---------------------------------------------------------------
|
|
667 |
|
|
668 |
if (defined($opt_d)) {
|
|
669 |
|
|
670 |
print(STDERR "Writing profile-bin data of downcast...");
|
|
671 |
|
|
672 |
sub outProfBinRec($$$)
|
|
673 |
{
|
|
674 |
my($ens,$bin,$depth) = @_;
|
|
675 |
|
|
676 |
&antsPrintHeaders(STDOUT,'ens','bin','elapsed','elapsed_mismatch','CTD_time_offset',
|
|
677 |
'past_lag','past_err','future_lag','future_err',
|
|
678 |
'depth','sound_speed','pitch','roll','heading',
|
|
679 |
'CTD_w','CTD_w_t','LADCP_w','LADCP_e',
|
|
680 |
'LADCP_reflr_w','LADCP_reflr_w_err','w');
|
|
681 |
my($sscorr) = $LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED}/1500;
|
|
682 |
&antsOut($ens,
|
|
683 |
$bin,
|
|
684 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_TIME},
|
|
685 |
$LADCP{ENSEMBLE}[$ens]->{ELAPSED_MISMATCH},
|
|
686 |
$LADCP{ENSEMBLE}[$ens]->{CTD_TIMOFF},
|
|
687 |
$LADCP{ENSEMBLE}[$ens]->{PAST_LAG},
|
|
688 |
$LADCP{ENSEMBLE}[$ens]->{PAST_ERR},
|
|
689 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_LAG},
|
|
690 |
$LADCP{ENSEMBLE}[$ens]->{FUTURE_ERR},
|
|
691 |
$depth,
|
|
692 |
$LADCP{ENSEMBLE}[$ens]->{SOUND_SPEED},
|
|
693 |
$LADCP{ENSEMBLE}[$ens]->{PITCH},
|
|
694 |
$LADCP{ENSEMBLE}[$ens]->{ROLL},
|
|
695 |
$LADCP{ENSEMBLE}[$ens]->{HEADING},
|
|
696 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W},
|
|
697 |
$LADCP{ENSEMBLE}[$ens]->{CTD_W_T},
|
|
698 |
$LADCP{ENSEMBLE}[$ens]->{W}[$bin],
|
|
699 |
$LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin],
|
|
700 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W},
|
|
701 |
$LADCP{ENSEMBLE}[$ens]->{REFLR_W_ERR},
|
|
702 |
$LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$LADCP{ENSEMBLE}[$ens]->{CTD_W});
|
|
703 |
}
|
|
704 |
|
|
705 |
close(STDOUT);
|
|
706 |
|
|
707 |
for (my($bi)=0; $bi<=$#{$DNCAST{ENS}}; $bi++) {
|
|
708 |
my($fn) = sprintf("$opt_d%03d.dncast",$bi);
|
|
709 |
|
|
710 |
open(STDOUT,">$fn") || croak("$fn: $!\n");
|
|
711 |
for (my($eii)=0; $eii<=$#{$DNCAST{ENS}[$bi]}; $eii++) {
|
|
712 |
&outProfBinRec($DNCAST{ENS}[$bi][$eii],$DNCAST{BIN}[$bi][$eii],$DNCAST{DEPTH}[$bi][$eii]);
|
|
713 |
}
|
|
714 |
close(STDOUT);
|
|
715 |
undef($antsHeadersPrinted);
|
|
716 |
}
|
|
717 |
|
|
718 |
print(STDERR "done\nWriting profile-bin data of upcast...");
|
|
719 |
|
|
720 |
for (my($bi)=0; $bi<=$#{$UPCAST{ENS}}; $bi++) {
|
|
721 |
my($fn) = sprintf("$opt_d%03d.upcast",$bi);
|
|
722 |
|
|
723 |
open(STDOUT,">$fn") || croak("$fn: $!\n");
|
|
724 |
for (my($eii)=0; $eii<=$#{$UPCAST{ENS}[$bi]}; $eii++) {
|
|
725 |
&outProfBinRec($UPCAST{ENS}[$bi][$eii],$UPCAST{BIN}[$bi][$eii],$UPCAST{DEPTH}[$bi][$eii]);
|
|
726 |
}
|
|
727 |
close(STDOUT);
|
|
728 |
undef($antsHeadersPrinted);
|
|
729 |
}
|
|
730 |
|
|
731 |
print(STDERR "done\n");
|
|
732 |
}
|
|
733 |
|
|
734 |
|
|
735 |
&antsExit();
|