author | Andreas Thurnherr <ant@ldeo.columbia.edu> |
Sun, 21 Oct 2018 20:01:48 -0400 | |
changeset 45 | 5767cbe470a0 |
parent 44 | b7654ea68af6 |
parent 43 | b63fa355644c |
child 48 | cdc74ebada81 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# L I S T B I N S |
|
4 |
# doc: Fri Aug 25 15:57:05 2006 |
|
44 | 5 |
# dlm: Wed Aug 29 07:23:21 2018 |
0 | 6 |
# (c) 2006 A.M. Thurnherr |
44 | 7 |
# uE-Info: 136 20 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 8 |
#====================================================================== |
9 |
||
10 |
# Split data file into per-bin time series. |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Aug 25, 2006: - created from [listEns] |
|
14 |
# Aug 26, 2006: - added -M)agdecl |
|
15 |
# - changed -b to -f |
|
16 |
# Aug 27, 2006: - added %bin |
|
17 |
# Aug 28, 2006: - BUG: options were confused |
|
18 |
# Jan 4, 2007: - improved usage message for -a |
|
19 |
# - added %mag_decl |
|
20 |
# - BUG: roundoff error in %pct_good_vels |
|
21 |
# Sep 19, 2007: - adapted to new [RDI_BB_Read.pl] |
|
22 |
# Feb 7, 2008: - added sound-speed correction |
|
23 |
# - enabled 3-beam solutions |
|
24 |
# Feb 8, 2008: - added -d)iscard <beam> |
|
25 |
# - added -b)eam coordinate output |
|
26 |
# Feb 12, 2008: - modified 3-beam output |
|
27 |
# - added -p)ct_good <min> |
|
28 |
# Feb 13, 2008: - various improvements |
|
29 |
# Feb 19, 2008: - BUG: division by zero |
|
30 |
# BUG: min() did not work with 1st elt undef |
|
31 |
# Feb 21, 2008: - BUG: had forgotten to undo debugging changes |
|
32 |
# - removed missing magdecl warning on -b |
|
33 |
# Feb 22, 2008: - moved ssCorr() to [RDI_Utils.pl] |
|
34 |
# - BUG: %d complete ensembles was written to STDOUT |
|
35 |
# - BUG: %N_ensembles was total number of ensembles, not |
|
36 |
# only the ones used |
|
37 |
# - BUG: 0 errvel was output for 3-beam solutions => |
|
38 |
# wrong time-average statistics |
|
39 |
# May 19, 2009: - added -w to calculate vertical velocities from |
|
40 |
# two beam pairs separately |
|
41 |
# May 21, 2009: - added horizontal beampair velocities on -w |
|
42 |
# - -P)itchRoll <bias/bias> |
|
43 |
# May 22, 2009: - added -B) <bias/bias/bias/bias> |
|
44 |
# May 23, 2009: - adapted to changed beampair-velocity fun name |
|
1 | 45 |
# Aug 22, 2010: - added -R |
12 | 46 |
# Apr 29, 2013: - cosmetics |
47 |
# - added warning on missing -S |
|
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
12
diff
changeset
|
48 |
# Aug 7, 2013: - BUG: -w did not respect -d |
18 | 49 |
# Mar 4, 2014: - added support for missing PITCH/ROLL/HEADING |
50 |
# Apr 22, 2014: - BUG: extraneous semicolon |
|
21 | 51 |
# Nov 24, 2014: - enabled -w always |
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
52 |
# Mar 22, 2015: - replaced -f by -o (allowing for pipes) |
24 | 53 |
# Jun 16, 2015: - BUG: velocity bias code did not respect bad velocities |
28 | 54 |
# Jan 5, 2016: - adapted to [ANTS_tools_lib.pl] |
55 |
# - adapted to calculation of w12, w34 from earth-coordinate data |
|
56 |
# - several other changes to the code that should not affect the results |
|
32 | 57 |
# Jan 6, 2016: - -b removed (always output beamvels) |
58 |
# Jan 31, 2016: - started debugging the obviously wrong Earth2Beam() transformation |
|
59 |
# Feb 29, 2016: - continued debugging; removed debugging code |
|
33 | 60 |
# Mar 17, 2016: - adapted to new Getopt library |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
61 |
# Jun 9, 2016: - minor improvements |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
62 |
# - BUG: velBeamToEarth() has new interface |
37 | 63 |
# Jan 27, 2017: - BUG: earth-coordinate label was wrong |
64 |
# - changed semantics to include all %-good fields of earth-coordinate data |
|
65 |
# and also report total pcg (3+4 beam) in min_pcg |
|
66 |
# - BUG: 3-beam %ages were incorrect: 1) they were based on goodvels instead of the |
|
67 |
# entire ensemble range; 2) pings-per-ensemble were not considered |
|
68 |
# - BUG: output layout was all messed up for non-valid velocities |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
69 |
# Feb 6, 2018: - added support for PD0_IO first_ens, last_ens |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
70 |
# Apr 10, 2018: - added day number to output |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
71 |
# - added -l)ast bin |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
72 |
# - activate output files |
44 | 73 |
# Aug 29, 2018: - added error message on -r decoding failures |
0 | 74 |
|
75 |
# General Notes: |
|
76 |
# - everything (e.g. beams) is numbered from 1 |
|
77 |
# - no support for BT data |
|
78 |
||
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
79 |
# Post-Processing: |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
80 |
# - e.g. in a Makefile, |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
81 |
# BFILT = | list -Lconv ensemble elapsed dn12='str2dec_time(\$$date,\$$time,2012)' heading pitch roll temp u v w err_vel w12 w34 corr1 corr2 corr3 corr4 amp1 amp2 amp3 amp4 > `basename $@ .b1`.b%d |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
82 |
# - used as follows |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
83 |
# listBins -o "${BFILT}" |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
84 |
# - this writes only the interesting fields and calculates a 2012-referenced decimal day field |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
85 |
|
0 | 86 |
# Soundspeed Correction: |
87 |
# - applied as described in the RDI coord-trans manual |
|
88 |
# - sound-speed variation over range is ignored (valid for small gradients) |
|
89 |
# => - same simple correction for all velocity components |
|
90 |
# - simple correction for cell depths |
|
91 |
||
92 |
# Min %-good (min_pcg): |
|
93 |
# - nan for records w/o valid velocities |
|
94 |
# - min(%-good) of the beams used for the velocity solution |
|
95 |
# - min_pcg does not have to decrease monotonically with distance, |
|
96 |
# at least when 3-beam solutions are allowed and when -p is used to |
|
97 |
# edit the data |
|
98 |
# - non-monotonic min_pcg is particularly obvious with the DYNAMUCK BM_ADCP |
|
99 |
# data, where one of the beams performed much worse than the others |
|
100 |
||
37 | 101 |
# %-good of earth-coordinate data: |
102 |
# pcg1 3-beam (correlation threshold) |
|
103 |
# pcg2 bad (errvel threshold) |
|
104 |
# pcg3 bad (>1 bad beam) |
|
105 |
# pcg4 4-beam |
|
106 |
||
33 | 107 |
use Getopt::Std; |
28 | 108 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
109 |
$ADCP_tools_minVersion = 2.2; |
28 | 110 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
111 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
|
0 | 112 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
113 |
$antsMinLibVersion = 7.0; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
114 |
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
115 |
require "$ANTS/ants.pl"; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
116 |
require "$ANTS/libconv.pl"; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
117 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
118 |
die("Usage: $0 [-r)ange <first_ens,last_ens>] [-l)ast <bin>] [-R)enumber ensembles from 1] " . |
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
119 |
"[-o)utput <redirection[>bin%d.raw]>] " . |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
120 |
"[output -a)ll ens (not just those with good vels)] " . |
0 | 121 |
"[-M)agnetic <declination>] " . |
122 |
"[-S)oundspeed correction <salin|*,temp|*,depth|*> " . |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
123 |
"[Instrument -T)ransformation Matrix <file>] " . |
0 | 124 |
"[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " . |
125 |
"[require -4)-beam solutions] [-d)iscard <beam#>] " . |
|
12 | 126 |
"[-p)ct-good <min>] " . |
0 | 127 |
"<RDI file>\n") |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
128 |
unless (&getopts("4aB:d:l:M:o:p:r:P:RS:T:") && @ARGV == 1); |
0 | 129 |
|
130 |
($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P); |
|
131 |
($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B); |
|
132 |
||
133 |
die("$0: -4 and -d are mutually exclusive\n") |
|
134 |
if ($opt_4 && defined($opt_d)); |
|
135 |
||
136 |
$opt_p = 0 unless defined($opt_p); |
|
137 |
||
138 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
|
139 |
||
140 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
28 | 141 |
unless defined($opt_M); |
0 | 142 |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
143 |
$opt_o = '>bin%d.raw' unless defined($opt_o); |
0 | 144 |
$ifn = $ARGV[0]; |
145 |
||
44 | 146 |
if (defined($opt_r)) { |
147 |
($first_ens,$last_ens) = split(',',$opt_r); |
|
148 |
die("Cannot decode -r $opt_r\n") |
|
149 |
unless ($first_ens>0 && $last_ens>$first_ens); |
|
150 |
} |
|
0 | 151 |
|
12 | 152 |
if (defined($opt_S)) { |
153 |
($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S); |
|
154 |
$variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
|
155 |
} else { |
|
156 |
print(STDERR "WARNING: no soundspeed correction applied!\n"); |
|
157 |
} |
|
0 | 158 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
159 |
loadInstrumentTransformation($opt_T) # load instrument-transformation matrix |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
160 |
if (defined($opt_T)); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
161 |
|
0 | 162 |
#---------------------------------------------------------------------- |
163 |
||
164 |
sub min(@) # return minimum |
|
165 |
{ |
|
166 |
my($min) = 99e99; |
|
167 |
for (my($i)=0; $i<=$#_; $i++) { |
|
168 |
$min = $_[$i] if defined($_[$i]) && ($_[$i] < $min); |
|
169 |
} |
|
170 |
return ($min == 99e99) ? nan : $min; |
|
171 |
} |
|
172 |
||
173 |
sub dumpBin($$$) # write time series of single bin |
|
174 |
{ |
|
175 |
my($b,$fe,$le) = @_; |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
176 |
my($out) = sprintf($opt_o,$b+1); |
0 | 177 |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
178 |
open(P,"$out") || die("$out: $!\n"); |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
179 |
print(P "#!/usr/bin/perl -S list\n"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
180 |
chmod(0777&~umask,*P); # activate output |
0 | 181 |
print(P "#ANTS#PARAMS# "); |
182 |
foreach my $k (keys(%P)) { |
|
183 |
print(P "$k\{$P{$k}\} "); |
|
184 |
} |
|
37 | 185 |
my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE}); |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
186 |
# die("assertion failed ($pct3b > 100): gv[$b] = $good_vels[$b]; 3b = $three_beam[$b]; ens=$fe..$le; ") |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
187 |
# if ($pct3b > 100); |
37 | 188 |
printf(STDERR "%02d:%.0f%%/%.0f%% ",$b+1,100*$good_vels[$b]/($le-$fe+1),$pct3b); |
28 | 189 |
|
190 |
printf(P "pct_3_beam{%.0f} ",$pct3b); |
|
0 | 191 |
printf(P "pct_good_vels{%.0f} ",100*$good_vels[$b]/($le-$fe+1)); |
192 |
printf(P "bin{%d}",$b+1); |
|
193 |
printf(P " soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!'); |
|
194 |
printf(P " dz{%g}",$dz[$b] * |
|
195 |
(defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1) |
|
196 |
) unless ($variable_ssCorr); |
|
197 |
print( P "\n"); |
|
198 |
||
199 |
print(P "#ANTS#FIELDS# " . |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
200 |
"{ensemble} {date} {time} {elapsed} {dn} " . |
0 | 201 |
"{heading} {pitch} {roll} " . |
202 |
"{sig_heading} {sig_pitch} {sig_roll} " . |
|
203 |
"{xmit_current} {xmit_voltage} " . |
|
204 |
"{temp} " . |
|
28 | 205 |
"{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " . |
21 | 206 |
"{v12} {w12} {v34} {w34} " . |
0 | 207 |
"{corr1} {corr2} {corr3} {corr4} " . |
208 |
"{amp1} {amp2} {amp3} {amp4} " . |
|
28 | 209 |
"{pcg1} {pcg2} {pcg3} {pcg4} {3_beam} {min_pcg}" |
0 | 210 |
); |
211 |
print(P " {dz}") if ($variable_ssCorr); |
|
212 |
print(P "\n"); |
|
213 |
||
214 |
my($t0) = $dta{ENSEMBLE}[$fe]->{UNIX_TIME}; |
|
215 |
for (my($e)=$fe; $e<=$le; $e++) { |
|
216 |
next unless ($opt_a || $dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]); |
|
217 |
||
218 |
my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1; |
|
219 |
||
220 |
print(P "$dta{ENSEMBLE}[$e]->{NUMBER} "); |
|
221 |
print(P "$dta{ENSEMBLE}[$e]->{DATE} "); |
|
222 |
print(P "$dta{ENSEMBLE}[$e]->{TIME} "); |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
223 |
printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0); # elapsed time |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
224 |
printf(P "%g ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME})); # decimal day |
18 | 225 |
print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan '); |
226 |
print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan '); |
|
227 |
print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan '); |
|
0 | 228 |
print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} "); |
229 |
print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} "); |
|
230 |
print(P "$dta{ENSEMBLE}[$e]->{ROLL_STDDEV} "); |
|
231 |
print(P "$dta{ENSEMBLE}[$e]->{ADC_XMIT_CURRENT} "); |
|
232 |
print(P "$dta{ENSEMBLE}[$e]->{ADC_XMIT_VOLTAGE} "); |
|
233 |
print(P "$dta{ENSEMBLE}[$e]->{TEMPERATURE} "); |
|
234 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
|
28 | 235 |
printf(P "%g %g %g %g ",@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
0 | 236 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] * $ssCorr); |
237 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] * $ssCorr); |
|
238 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] * $ssCorr); |
|
239 |
if ($dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]) { |
|
240 |
print(P "nan "); |
|
241 |
} else { |
|
242 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] * $ssCorr); |
|
243 |
} |
|
21 | 244 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]) ? "%g " : "nan ", |
245 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]); |
|
246 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]) ? "%g " : "nan ", |
|
247 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]); |
|
248 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]) ? "%g " : "nan ", |
|
249 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]); |
|
250 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ", |
|
251 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]); |
|
0 | 252 |
} else { |
253 |
print(P "nan nan nan nan "); |
|
21 | 254 |
print(P "nan nan nan nan "); |
37 | 255 |
print(P "nan nan nan nan "); |
0 | 256 |
} |
257 |
print(P "@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} "); |
|
258 |
print(P "@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} "); |
|
37 | 259 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
260 |
print(P "@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} "); |
|
261 |
} else { |
|
262 |
print(P "nan nan nan nan "); |
|
263 |
} |
|
28 | 264 |
if ($beamCoords) { |
0 | 265 |
printf(P "%d ",$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]); |
266 |
printf(P "%s ",min(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]})); |
|
28 | 267 |
} else { |
37 | 268 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
269 |
print(P "$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] "); |
|
270 |
} else { |
|
271 |
print(P "nan "); |
|
272 |
} |
|
273 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]+$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
|
0 | 274 |
} |
275 |
printf(P "%g ",$dz[$b]*$ssCorr) if ($variable_ssCorr); |
|
276 |
print(P "\n"); |
|
277 |
} |
|
278 |
close(P); |
|
279 |
} |
|
280 |
||
281 |
#---------------------------------------------------------------------- |
|
282 |
# MAIN |
|
283 |
#---------------------------------------------------------------------- |
|
284 |
||
285 |
$P{RDI_file} = $ifn; |
|
286 |
$P{mag_decl} = $opt_M if defined($opt_M); |
|
287 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
288 |
readData($ifn,\%dta,$first_ens,$last_ens,$opt_l); |
0 | 289 |
printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}})); |
290 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
291 |
||
292 |
if ($dta{BEAM_COORDINATES}) { # coords |
|
293 |
$beamCoords = 1; |
|
294 |
} else { |
|
28 | 295 |
die("$ifn: only beam and earth coordinates supported\n") |
0 | 296 |
if (!$dta{EARTH_COORDINATES}); |
28 | 297 |
die("$ifn: -p requires beam-coordinate data\n") |
298 |
if ($opt_p > 0); |
|
299 |
die("$ifn: -d requires beam-coordinate data\n") |
|
300 |
if defined($opt_d); |
|
301 |
die("$ifn: -B requires beam-coordinate data\n") |
|
302 |
if defined($opt_B); |
|
0 | 303 |
} |
304 |
||
305 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { # calc dz |
|
306 |
$dz[$b] = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
307 |
} |
|
308 |
||
309 |
$lastGoodBin = 0; |
|
1 | 310 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { # check/transform velocities |
311 |
$dta{ENSEMBLE}[$e]->{NUMBER} = $e+1 if ($opt_R); # renumber ensembles |
|
0 | 312 |
next if (defined($first_ens) && |
313 |
$dta{ENSEMBLE}[$e]->{NUMBER} < $first_ens); |
|
314 |
||
18 | 315 |
$dta{ENSEMBLE}[$e]->{PITCH} -= $P{pitch_bias} |
316 |
if defined($dta{ENSEMBLE}[$e]->{PITCH}); |
|
317 |
$dta{ENSEMBLE}[$e]->{ROLL} -= $P{roll_bias} |
|
318 |
if defined($dta{ENSEMBLE}[$e]->{ROLL}); |
|
0 | 319 |
|
320 |
$P{first_ens} = $dta{ENSEMBLE}[$e]->{NUMBER},$fe = $e |
|
321 |
unless defined($P{first_ens}); |
|
322 |
last if (defined($last_ens) && |
|
323 |
$dta{ENSEMBLE}[$e]->{NUMBER} > $last_ens); |
|
324 |
$P{last_ens} = $dta{ENSEMBLE}[$e]->{NUMBER}; |
|
325 |
$le = $e; |
|
326 |
||
327 |
die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
328 |
if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4); |
|
329 |
die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
330 |
if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
331 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
332 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN}); |
|
333 |
||
334 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { |
|
28 | 335 |
if ($beamCoords) { |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
336 |
for (my($i)=0; $i<4; $i++) { # percent-good editing (-p) |
28 | 337 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i] < $opt_p) { |
338 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i]); |
|
339 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$i]); |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] -= $P{velbias_b1} # beam-velocity biases (-B) |
|
344 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]); |
|
345 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] -= $P{velbias_b2} |
|
346 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]); |
|
347 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] -= $P{velbias_b3} |
|
348 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]); |
|
349 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] -= $P{velbias_b4} |
|
350 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3]); |
|
351 |
||
352 |
if (defined($opt_d)) { # discard data from given beam (-d) |
|
353 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]); |
|
354 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]); |
|
355 |
} |
|
356 |
||
357 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # save beam velocities |
|
358 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}; |
|
359 |
||
360 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate w12, w34 |
|
361 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
362 |
||
363 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = # calculate earth velocities |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
364 |
velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
28 | 365 |
$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b] = $RDI_Coords::threeBeamFlag; |
366 |
$three_beam[$b] += $RDI_Coords::threeBeamFlag; |
|
367 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
368 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { # not a valid transformation |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
369 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
28 | 370 |
next; |
371 |
} |
|
372 |
} else { # Earth coordinates |
|
373 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # calculate beam velocities |
|
32 | 374 |
velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
28 | 375 |
|
376 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate w12, w34 |
|
377 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
378 |
||
379 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = # correct for heading bias |
|
380 |
velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
381 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
382 |
$three_beam[$b] += ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]/100 * $dta{PINGS_PER_ENSEMBLE}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
383 |
unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0])) { # no valid velocity |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
384 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
28 | 385 |
next; |
386 |
} |
|
387 |
||
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
12
diff
changeset
|
388 |
} |
28 | 389 |
|
0 | 390 |
$dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b] = 1; |
391 |
$good_vels[$b]++; |
|
392 |
$lastGoodBin = $b if ($b > $lastGoodBin); |
|
393 |
$firstGoodEns = $e unless defined($firstGoodEns); |
|
394 |
$lastGoodEns = $e; |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
unless (defined($opt_r)) { |
|
399 |
$fe = $firstGoodEns; |
|
400 |
$le = $lastGoodEns; |
|
401 |
} |
|
402 |
||
403 |
$P{N_ensembles} = $le - $fe + 1; |
|
404 |
||
405 |
$firstBin = 0; |
|
406 |
$lastBin = $lastGoodBin; |
|
407 |
||
408 |
print( STDERR "Start : $dta{ENSEMBLE}[$fe]->{DATE} $dta{ENSEMBLE}[$fe]->{TIME}\n"); |
|
409 |
print( STDERR "End : $dta{ENSEMBLE}[$le]->{DATE} $dta{ENSEMBLE}[$le]->{TIME}\n"); |
|
410 |
printf(STDERR "Bins : %d-%d\n",$firstBin+1,$lastBin+1); |
|
28 | 411 |
if ($beamCoords) { |
0 | 412 |
printf(STDERR "3-Beam : %d %d %d %d\n",$RDI_Coords::threeBeam_1, |
413 |
$RDI_Coords::threeBeam_2, |
|
414 |
$RDI_Coords::threeBeam_3, |
|
415 |
$RDI_Coords::threeBeam_4); |
|
416 |
||
417 |
} |
|
37 | 418 |
print(STDERR "Good/3-Beam: "); |
0 | 419 |
for ($b=$firstBin; $b<=$lastBin; $b++) { # generate output |
420 |
dumpBin($b,$fe,$le); |
|
421 |
} |
|
422 |
print(STDERR "\n"); |
|
423 |
||
424 |
exit(0); |