64 # - changed semantics to include all %-good fields of earth-coordinate data |
64 # - changed semantics to include all %-good fields of earth-coordinate data |
65 # and also report total pcg (3+4 beam) in min_pcg |
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 |
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 |
67 # entire ensemble range; 2) pings-per-ensemble were not considered |
68 # - BUG: output layout was all messed up for non-valid velocities |
68 # - BUG: output layout was all messed up for non-valid velocities |
|
69 # Feb 6, 2018: - added support for PD0_IO first_ens, last_ens |
|
70 # Apr 10, 2018: - added day number to output |
|
71 # - added -l)ast bin |
|
72 # - activate output files |
69 # Aug 29, 2018: - added error message on -r decoding failures |
73 # Aug 29, 2018: - added error message on -r decoding failures |
70 |
74 |
71 # General Notes: |
75 # General Notes: |
72 # - everything (e.g. beams) is numbered from 1 |
76 # - everything (e.g. beams) is numbered from 1 |
73 # - no support for BT data |
77 # - no support for BT data |
100 # pcg3 bad (>1 bad beam) |
104 # pcg3 bad (>1 bad beam) |
101 # pcg4 4-beam |
105 # pcg4 4-beam |
102 |
106 |
103 use Getopt::Std; |
107 use Getopt::Std; |
104 |
108 |
105 $ADCP_tools_minVersion = 2.1; |
109 $ADCP_tools_minVersion = 2.2; |
106 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
110 ($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
107 require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
111 require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
108 |
112 |
109 die("Usage: $0 [-r)ange <first_ens,last_ens>] [-R)enumber ensembles] " . |
113 $antsMinLibVersion = 7.0; |
|
114 ($ANTS) = (`which ANTSlib` =~ m{^(.*)/[^/]*$}); |
|
115 require "$ANTS/ants.pl"; |
|
116 require "$ANTS/libconv.pl"; |
|
117 |
|
118 die("Usage: $0 [-r)ange <first_ens,last_ens>] [-l)ast <bin>] [-R)enumber ensembles from 1] " . |
110 "[-o)utput <redirection[>bin%d.raw]>] " . |
119 "[-o)utput <redirection[>bin%d.raw]>] " . |
111 "[output -a)ll ens (not just those with good vels)] " . |
120 "[output -a)ll ens (not just those with good vels)] " . |
112 "[-M)agnetic <declination>] " . |
121 "[-M)agnetic <declination>] " . |
113 "[-S)oundspeed correction <salin|*,temp|*,depth|*> " . |
122 "[-S)oundspeed correction <salin|*,temp|*,depth|*> " . |
|
123 "[Instrument -T)ransformation Matrix <file>] " . |
114 "[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " . |
124 "[-P)itch/Roll <bias/bias>] [-B)eamvel <bias/bias/bias/bias>] " . |
115 "[require -4)-beam solutions] [-d)iscard <beam#>] " . |
125 "[require -4)-beam solutions] [-d)iscard <beam#>] " . |
116 "[-p)ct-good <min>] " . |
126 "[-p)ct-good <min>] " . |
117 "<RDI file>\n") |
127 "<RDI file>\n") |
118 unless (&getopts("4aB:d:M:o:p:r:P:RS:") && @ARGV == 1); |
128 unless (&getopts("4aB:d:l:M:o:p:r:P:RS:T:") && @ARGV == 1); |
119 |
129 |
120 ($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P); |
130 ($P{pitch_bias},$P{roll_bias}) = split('[,/]',$opt_P); |
121 ($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B); |
131 ($P{velbias_b1},$P{velbias_b2},$P{velbias_b3},$P{velbias_b4}) = split('[,/]',$opt_B); |
122 |
132 |
123 die("$0: -4 and -d are mutually exclusive\n") |
133 die("$0: -4 and -d are mutually exclusive\n") |
143 ($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S); |
153 ($SS_salin,$SS_temp,$SS_depth) = split(',',$opt_S); |
144 $variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
154 $variable_ssCorr = ($SS_salin eq '*' || $SS_temp eq '*' || $SS_depth eq '*'); |
145 } else { |
155 } else { |
146 print(STDERR "WARNING: no soundspeed correction applied!\n"); |
156 print(STDERR "WARNING: no soundspeed correction applied!\n"); |
147 } |
157 } |
|
158 |
|
159 loadInstrumentTransformation($opt_T) # load instrument-transformation matrix |
|
160 if (defined($opt_T)); |
148 |
161 |
149 #---------------------------------------------------------------------- |
162 #---------------------------------------------------------------------- |
150 |
163 |
151 sub min(@) # return minimum |
164 sub min(@) # return minimum |
152 { |
165 { |
161 { |
174 { |
162 my($b,$fe,$le) = @_; |
175 my($b,$fe,$le) = @_; |
163 my($out) = sprintf($opt_o,$b+1); |
176 my($out) = sprintf($opt_o,$b+1); |
164 |
177 |
165 open(P,"$out") || die("$out: $!\n"); |
178 open(P,"$out") || die("$out: $!\n"); |
|
179 print(P "#!/usr/bin/perl -S list\n"); |
|
180 chmod(0777&~umask,*P); # activate output |
166 print(P "#ANTS#PARAMS# "); |
181 print(P "#ANTS#PARAMS# "); |
167 foreach my $k (keys(%P)) { |
182 foreach my $k (keys(%P)) { |
168 print(P "$k\{$P{$k}\} "); |
183 print(P "$k\{$P{$k}\} "); |
169 } |
184 } |
170 my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE}); |
185 my($pct3b) = 100*$three_beam[$b]/(($le-$fe+1) * $dta{PINGS_PER_ENSEMBLE}); |
180 (defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1) |
195 (defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$fe],$SS_salin,$SS_temp,$SS_depth) : 1) |
181 ) unless ($variable_ssCorr); |
196 ) unless ($variable_ssCorr); |
182 print( P "\n"); |
197 print( P "\n"); |
183 |
198 |
184 print(P "#ANTS#FIELDS# " . |
199 print(P "#ANTS#FIELDS# " . |
185 "{ensemble} {date} {time} {elapsed} " . |
200 "{ensemble} {date} {time} {elapsed} {dn} " . |
186 "{heading} {pitch} {roll} " . |
201 "{heading} {pitch} {roll} " . |
187 "{sig_heading} {sig_pitch} {sig_roll} " . |
202 "{sig_heading} {sig_pitch} {sig_roll} " . |
188 "{xmit_current} {xmit_voltage} " . |
203 "{xmit_current} {xmit_voltage} " . |
189 "{temp} " . |
204 "{temp} " . |
190 "{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " . |
205 "{bv1} {bv2} {bv3} {bv4} {u} {v} {w} {err_vel} " . |
203 my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1; |
218 my($ssCorr) = defined($opt_S) ? ssCorr($dta{ENSEMBLE}[$e],$SS_salin,$SS_temp,$SS_depth) : 1; |
204 |
219 |
205 print(P "$dta{ENSEMBLE}[$e]->{NUMBER} "); |
220 print(P "$dta{ENSEMBLE}[$e]->{NUMBER} "); |
206 print(P "$dta{ENSEMBLE}[$e]->{DATE} "); |
221 print(P "$dta{ENSEMBLE}[$e]->{DATE} "); |
207 print(P "$dta{ENSEMBLE}[$e]->{TIME} "); |
222 print(P "$dta{ENSEMBLE}[$e]->{TIME} "); |
208 printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0); # elapsed time |
223 printf(P "%d ",$dta{ENSEMBLE}[$e]->{UNIX_TIME}-$t0); # elapsed time |
|
224 printf(P "%g ",str2dec_time($dta{ENSEMBLE}[$e]->{DATE},$dta{ENSEMBLE}[$e]->{TIME})); # decimal day |
209 print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan '); |
225 print(P defined($dta{ENSEMBLE}[$e]->{HEADING}) ? "$dta{ENSEMBLE}[$e]->{HEADING} " : 'nan '); |
210 print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan '); |
226 print(P defined($dta{ENSEMBLE}[$e]->{PITCH}) ? "$dta{ENSEMBLE}[$e]->{PITCH} " : 'nan '); |
211 print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan '); |
227 print(P defined($dta{ENSEMBLE}[$e]->{ROLL}) ? "$dta{ENSEMBLE}[$e]->{ROLL} " : 'nan '); |
212 print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} "); |
228 print(P "$dta{ENSEMBLE}[$e]->{HEADING_STDDEV} "); |
213 print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} "); |
229 print(P "$dta{ENSEMBLE}[$e]->{PITCH_STDDEV} "); |
267 #---------------------------------------------------------------------- |
283 #---------------------------------------------------------------------- |
268 |
284 |
269 $P{RDI_file} = $ifn; |
285 $P{RDI_file} = $ifn; |
270 $P{mag_decl} = $opt_M if defined($opt_M); |
286 $P{mag_decl} = $opt_M if defined($opt_M); |
271 |
287 |
272 readData($ifn,\%dta); |
288 readData($ifn,\%dta,$first_ens,$last_ens,$opt_l); |
273 printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}})); |
289 printf(STDERR "%d complete ensembles...\n",scalar(@{$dta{ENSEMBLE}})); |
274 $dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
290 $dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
275 |
291 |
276 if ($dta{BEAM_COORDINATES}) { # coords |
292 if ($dta{BEAM_COORDINATES}) { # coords |
277 $beamCoords = 1; |
293 $beamCoords = 1; |