author | A.M. Thurnherr <athurnherr@yahoo.com> |
Wed, 03 Mar 2021 14:50:51 -0500 | |
changeset 54 | 21cf468fa8e0 |
parent 50 | 6bfec705d25e |
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 |
|
54 | 5 |
# dlm: Fri Jun 5 13:45:23 2020 |
0 | 6 |
# (c) 2006 A.M. Thurnherr |
54 | 7 |
# uE-Info: 367 103 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 |
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
74 |
# Jun 13, 2018: - adpated to RTI files (disabled BIT error check) |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
75 |
# - BUG: dn did not have sufficient digits |
50 | 76 |
# Feb 13, 2020: - added -z |
54 | 77 |
# May 11, 2020: - removed -z, added -t -m |
0 | 78 |
|
79 |
# General Notes: |
|
80 |
# - everything (e.g. beams) is numbered from 1 |
|
81 |
# - no support for BT data |
|
82 |
||
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
83 |
# Post-Processing: |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
84 |
# - e.g. in a Makefile, |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
85 |
# 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
|
86 |
# - used as follows |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
87 |
# listBins -o "${BFILT}" |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
88 |
# - 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
|
89 |
|
0 | 90 |
# Soundspeed Correction: |
91 |
# - applied as described in the RDI coord-trans manual |
|
92 |
# - sound-speed variation over range is ignored (valid for small gradients) |
|
93 |
# => - same simple correction for all velocity components |
|
94 |
# - simple correction for cell depths |
|
95 |
||
96 |
# Min %-good (min_pcg): |
|
97 |
# - nan for records w/o valid velocities |
|
98 |
# - min(%-good) of the beams used for the velocity solution |
|
99 |
# - min_pcg does not have to decrease monotonically with distance, |
|
100 |
# at least when 3-beam solutions are allowed and when -p is used to |
|
101 |
# edit the data |
|
102 |
# - non-monotonic min_pcg is particularly obvious with the DYNAMUCK BM_ADCP |
|
103 |
# data, where one of the beams performed much worse than the others |
|
104 |
||
37 | 105 |
# %-good of earth-coordinate data: |
106 |
# pcg1 3-beam (correlation threshold) |
|
107 |
# pcg2 bad (errvel threshold) |
|
108 |
# pcg3 bad (>1 bad beam) |
|
109 |
# pcg4 4-beam |
|
110 |
||
33 | 111 |
use Getopt::Std; |
28 | 112 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
113 |
$ADCP_tools_minVersion = 2.2; |
28 | 114 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
115 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
|
0 | 116 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
117 |
$antsMinLibVersion = 7.0; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
118 |
($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
119 |
require "$ANTS/ants.pl"; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
120 |
require "$ANTS/libconv.pl"; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
121 |
|
54 | 122 |
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
|
123 |
"[-o)utput <redirection[>bin%d.raw]>] " . |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
124 |
"[output -a)ll ens (not just those with good vels)] " . |
0 | 125 |
"[-M)agnetic <declination>] " . |
126 |
"[-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
|
127 |
"[Instrument -T)ransformation Matrix <file>] " . |
54 | 128 |
'[disable bin -m)apping] [use TRDI beam-to-earth -t)ransformation] ' . |
0 | 129 |
"[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " . |
130 |
"[require -4)-beam solutions] [-d)iscard <beam#>] " . |
|
12 | 131 |
"[-p)ct-good <min>] " . |
0 | 132 |
"<RDI file>\n") |
54 | 133 |
unless (&getopts("4aB:d:l:mM:o:p:r:P:RS:tT:") && @ARGV == 1); |
0 | 134 |
|
135 |
($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P); |
|
136 |
($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B); |
|
137 |
||
138 |
die("$0: -4 and -d are mutually exclusive\n") |
|
139 |
if ($opt_4 && defined($opt_d)); |
|
140 |
||
141 |
$opt_p = 0 unless defined($opt_p); |
|
142 |
||
54 | 143 |
$RDI_Coords::minValidVels = 4 if ($opt_4); # no 3-beam solutions |
144 |
$RDI_Coords::binMapping = 'none' if ($opt_m); # 'linterp' is default |
|
145 |
$RDI_Coords::beamTransformation = 'RDI' if ($opt_t); # 'LHR90' is default |
|
0 | 146 |
|
147 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
28 | 148 |
unless defined($opt_M); |
0 | 149 |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
150 |
$opt_o = '>bin%d.raw' unless defined($opt_o); |
0 | 151 |
$ifn = $ARGV[0]; |
152 |
||
44 | 153 |
if (defined($opt_r)) { |
154 |
($first_ens,$last_ens) = split(',',$opt_r); |
|
155 |
die("Cannot decode -r $opt_r\n") |
|
156 |
unless ($first_ens>0 && $last_ens>$first_ens); |
|
157 |
} |
|
0 | 158 |
|
12 | 159 |
if (defined($opt_S)) { |
160 |
($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S); |
|
161 |
$variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
|
162 |
} else { |
|
163 |
print(STDERR "WARNING: no soundspeed correction applied!\n"); |
|
164 |
} |
|
0 | 165 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
166 |
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
|
167 |
if (defined($opt_T)); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
168 |
|
0 | 169 |
#---------------------------------------------------------------------- |
170 |
||
171 |
sub min(@) # return minimum |
|
172 |
{ |
|
173 |
my($min) = 99e99; |
|
174 |
for (my($i)=0; $i<=$#_; $i++) { |
|
175 |
$min = $_[$i] if defined($_[$i]) && ($_[$i] < $min); |
|
176 |
} |
|
177 |
return ($min == 99e99) ? nan : $min; |
|
178 |
} |
|
179 |
||
180 |
sub dumpBin($$$) # write time series of single bin |
|
181 |
{ |
|
182 |
my($b,$fe,$le) = @_; |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
183 |
my($out) = sprintf($opt_o,$b+1); |
0 | 184 |
|
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
21
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
chmod(0777&~umask,*P); # activate output |
0 | 188 |
print(P "#ANTS#PARAMS# "); |
189 |
foreach my $k (keys(%P)) { |
|
190 |
print(P "$k\{$P{$k}\} "); |
|
191 |
} |
|
37 | 192 |
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
|
193 |
# 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
|
194 |
# if ($pct3b > 100); |
37 | 195 |
printf(STDERR "%02d:%.0f%%/%.0f%% ",$b+1,100*$good_vels[$b]/($le-$fe+1),$pct3b); |
28 | 196 |
|
197 |
printf(P "pct_3_beam{%.0f} ",$pct3b); |
|
0 | 198 |
printf(P "pct_good_vels{%.0f} ",100*$good_vels[$b]/($le-$fe+1)); |
199 |
printf(P "bin{%d}",$b+1); |
|
200 |
printf(P " soundspeed_correction{%s}",defined($opt_S) ? $opt_S : 'NONE!'); |
|
201 |
printf(P " dz{%g}",$dz[$b] * |
|
202 |
(defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1) |
|
203 |
) unless ($variable_ssCorr); |
|
204 |
print( P "\n"); |
|
205 |
||
206 |
print(P "#ANTS#FIELDS# " . |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
207 |
"{ensemble} {date} {time} {elapsed} {dn} " . |
0 | 208 |
"{heading} {pitch} {roll} " . |
209 |
"{sig_heading} {sig_pitch} {sig_roll} " . |
|
210 |
"{xmit_current} {xmit_voltage} " . |
|
211 |
"{temp} " . |
|
28 | 212 |
"{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " . |
21 | 213 |
"{v12} {w12} {v34} {w34} " . |
0 | 214 |
"{corr1} {corr2} {corr3} {corr4} " . |
215 |
"{amp1} {amp2} {amp3} {amp4} " . |
|
28 | 216 |
"{pcg1} {pcg2} {pcg3} {pcg4} {3_beam} {min_pcg}" |
0 | 217 |
); |
218 |
print(P " {dz}") if ($variable_ssCorr); |
|
219 |
print(P "\n"); |
|
220 |
||
221 |
my($t0) = $dta{ENSEMBLE}[$fe]->{UNIX_TIME}; |
|
222 |
for (my($e)=$fe; $e<=$le; $e++) { |
|
223 |
next unless ($opt_a || $dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]); |
|
224 |
||
225 |
my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1; |
|
226 |
||
227 |
print(P "$dta{ENSEMBLE}[$e]->{NUMBER} "); |
|
228 |
print(P "$dta{ENSEMBLE}[$e]->{DATE} "); |
|
229 |
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
|
230 |
printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0); # elapsed time |
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
231 |
printf(P "%.5f ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME})); # decimal day |
18 | 232 |
print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan '); |
233 |
print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan '); |
|
234 |
print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan '); |
|
0 | 235 |
print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} "); |
236 |
print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} "); |
|
237 |
print(P "$dta{ENSEMBLE}[$e]->{ROLL_STDDEV} "); |
|
238 |
print(P "$dta{ENSEMBLE}[$e]->{ADC_XMIT_CURRENT} "); |
|
239 |
print(P "$dta{ENSEMBLE}[$e]->{ADC_XMIT_VOLTAGE} "); |
|
240 |
print(P "$dta{ENSEMBLE}[$e]->{TEMPERATURE} "); |
|
241 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
|
28 | 242 |
printf(P "%g %g %g %g ",@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
0 | 243 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] * $ssCorr); |
244 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] * $ssCorr); |
|
245 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] * $ssCorr); |
|
246 |
if ($dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]) { |
|
247 |
print(P "nan "); |
|
248 |
} else { |
|
249 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] * $ssCorr); |
|
250 |
} |
|
21 | 251 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]) ? "%g " : "nan ", |
252 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][0]); |
|
253 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]) ? "%g " : "nan ", |
|
254 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][1]); |
|
255 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]) ? "%g " : "nan ", |
|
256 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][2]); |
|
257 |
printf(P defined($dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]) ? "%g " : "nan ", |
|
258 |
$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b][3]); |
|
0 | 259 |
} else { |
260 |
print(P "nan nan nan nan "); |
|
21 | 261 |
print(P "nan nan nan nan "); |
37 | 262 |
print(P "nan nan nan nan "); |
0 | 263 |
} |
264 |
print(P "@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]} "); |
|
265 |
print(P "@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]} "); |
|
37 | 266 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
267 |
print(P "@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} "); |
|
268 |
} else { |
|
269 |
print(P "nan nan nan nan "); |
|
270 |
} |
|
28 | 271 |
if ($beamCoords) { |
0 | 272 |
printf(P "%d ",$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b]); |
273 |
printf(P "%s ",min(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]})); |
|
28 | 274 |
} else { |
37 | 275 |
if ($dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b]) { |
276 |
print(P "$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0] "); |
|
277 |
} else { |
|
278 |
print(P "nan "); |
|
279 |
} |
|
280 |
printf(P "%g ",$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][0]+$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][3]); |
|
0 | 281 |
} |
282 |
printf(P "%g ",$dz[$b]*$ssCorr) if ($variable_ssCorr); |
|
283 |
print(P "\n"); |
|
284 |
} |
|
285 |
close(P); |
|
286 |
} |
|
287 |
||
288 |
#---------------------------------------------------------------------- |
|
289 |
# MAIN |
|
290 |
#---------------------------------------------------------------------- |
|
291 |
||
292 |
$P{RDI_file} = $ifn; |
|
293 |
$P{mag_decl} = $opt_M if defined($opt_M); |
|
294 |
||
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
42
diff
changeset
|
295 |
readData($ifn,\%dta,$first_ens,$last_ens,$opt_l); |
0 | 296 |
printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}})); |
297 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
298 |
||
299 |
if ($dta{BEAM_COORDINATES}) { # coords |
|
300 |
$beamCoords = 1; |
|
301 |
} else { |
|
28 | 302 |
die("$ifn: only beam and earth coordinates supported\n") |
0 | 303 |
if (!$dta{EARTH_COORDINATES}); |
28 | 304 |
die("$ifn: -p requires beam-coordinate data\n") |
305 |
if ($opt_p > 0); |
|
306 |
die("$ifn: -d requires beam-coordinate data\n") |
|
307 |
if defined($opt_d); |
|
308 |
die("$ifn: -B requires beam-coordinate data\n") |
|
309 |
if defined($opt_B); |
|
0 | 310 |
} |
311 |
||
312 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { # calc dz |
|
313 |
$dz[$b] = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
314 |
} |
|
315 |
||
316 |
$lastGoodBin = 0; |
|
1 | 317 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { # check/transform velocities |
318 |
$dta{ENSEMBLE}[$e]->{NUMBER} = $e+1 if ($opt_R); # renumber ensembles |
|
0 | 319 |
next if (defined($first_ens) && |
320 |
$dta{ENSEMBLE}[$e]->{NUMBER} < $first_ens); |
|
321 |
||
18 | 322 |
$dta{ENSEMBLE}[$e]->{PITCH} -= $P{pitch_bias} |
323 |
if defined($dta{ENSEMBLE}[$e]->{PITCH}); |
|
324 |
$dta{ENSEMBLE}[$e]->{ROLL} -= $P{roll_bias} |
|
325 |
if defined($dta{ENSEMBLE}[$e]->{ROLL}); |
|
0 | 326 |
|
327 |
$P{first_ens} = $dta{ENSEMBLE}[$e]->{NUMBER},$fe = $e |
|
328 |
unless defined($P{first_ens}); |
|
329 |
last if (defined($last_ens) && |
|
330 |
$dta{ENSEMBLE}[$e]->{NUMBER} > $last_ens); |
|
331 |
$P{last_ens} = $dta{ENSEMBLE}[$e]->{NUMBER}; |
|
332 |
$le = $e; |
|
333 |
||
334 |
die("3-beams used in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
335 |
if ($dta{ENSEMBLE}[$e]->{N_BEAMS_USED} < 4); |
|
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
336 |
# die("BIT error in ensemble $dta{ENSEMBLE}[$e]->{NUMBER}\n") |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
45
diff
changeset
|
337 |
# if defined($dta{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
0 | 338 |
die("Low gain in ensemble #$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
339 |
if ($dta{ENSEMBLE}[$e]->{LOW_GAIN}); |
|
340 |
||
341 |
for (my($b)=0; $b<$dta{N_BINS}; $b++) { |
|
28 | 342 |
if ($beamCoords) { |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
343 |
for (my($i)=0; $i<4; $i++) { # percent-good editing (-p) |
28 | 344 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i] < $opt_p) { |
345 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$i]); |
|
346 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$i]); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0] -= $P{velbias_b1} # beam-velocity biases (-B) |
|
351 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]); |
|
352 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1] -= $P{velbias_b2} |
|
353 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]); |
|
354 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2] -= $P{velbias_b3} |
|
355 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]); |
|
356 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3] -= $P{velbias_b4} |
|
357 |
if defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3]); |
|
358 |
||
359 |
if (defined($opt_d)) { # discard data from given beam (-d) |
|
360 |
undef($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b][$opt_d-1]); |
|
361 |
undef($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][$opt_d-1]); |
|
362 |
} |
|
363 |
||
364 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # save beam velocities |
|
365 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}; |
|
366 |
||
54 | 367 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate v12, w12, v34, w34 |
28 | 368 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
369 |
||
370 |
@{$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
|
371 |
velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
28 | 372 |
$dta{ENSEMBLE}[$e]->{THREE_BEAM}[$b] = $RDI_Coords::threeBeamFlag; |
373 |
$three_beam[$b] += $RDI_Coords::threeBeamFlag; |
|
374 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
375 |
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
|
376 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
28 | 377 |
next; |
378 |
} |
|
379 |
} else { # Earth coordinates |
|
380 |
@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]} = # calculate beam velocities |
|
32 | 381 |
velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
28 | 382 |
|
383 |
@{$dta{ENSEMBLE}[$e]->{BEAMPAIR_VELOCITY}[$b]} = # calculate w12, w34 |
|
384 |
velBeamToBPEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BEAM_VELOCITY}[$b]}); |
|
385 |
||
386 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]} = # correct for heading bias |
|
387 |
velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
388 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
33
diff
changeset
|
389 |
$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
|
390 |
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
|
391 |
undef(@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]}); |
28 | 392 |
next; |
393 |
} |
|
394 |
||
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
12
diff
changeset
|
395 |
} |
28 | 396 |
|
0 | 397 |
$dta{ENSEMBLE}[$e]->{GOOD_VEL}[$b] = 1; |
398 |
$good_vels[$b]++; |
|
399 |
$lastGoodBin = $b if ($b > $lastGoodBin); |
|
400 |
$firstGoodEns = $e unless defined($firstGoodEns); |
|
401 |
$lastGoodEns = $e; |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
unless (defined($opt_r)) { |
|
406 |
$fe = $firstGoodEns; |
|
407 |
$le = $lastGoodEns; |
|
408 |
} |
|
409 |
||
410 |
$P{N_ensembles} = $le - $fe + 1; |
|
411 |
||
412 |
$firstBin = 0; |
|
413 |
$lastBin = $lastGoodBin; |
|
414 |
||
415 |
print( STDERR "Start : $dta{ENSEMBLE}[$fe]->{DATE} $dta{ENSEMBLE}[$fe]->{TIME}\n"); |
|
416 |
print( STDERR "End : $dta{ENSEMBLE}[$le]->{DATE} $dta{ENSEMBLE}[$le]->{TIME}\n"); |
|
417 |
printf(STDERR "Bins : %d-%d\n",$firstBin+1,$lastBin+1); |
|
28 | 418 |
if ($beamCoords) { |
0 | 419 |
printf(STDERR "3-Beam : %d %d %d %d\n",$RDI_Coords::threeBeam_1, |
420 |
$RDI_Coords::threeBeam_2, |
|
421 |
$RDI_Coords::threeBeam_3, |
|
422 |
$RDI_Coords::threeBeam_4); |
|
423 |
||
424 |
} |
|
37 | 425 |
print(STDERR "Good/3-Beam: "); |
0 | 426 |
for ($b=$firstBin; $b<=$lastBin; $b++) { # generate output |
427 |
dumpBin($b,$fe,$le); |
|
428 |
} |
|
429 |
print(STDERR "\n"); |
|
430 |
||
431 |
exit(0); |