author | A.M. Thurnherr <athurnherr@yahoo.com> |
Fri, 05 Aug 2016 10:10:28 -0400 | |
changeset 36 | 515b06dae59c |
parent 34 | 3b4bcd55e1ea |
child 37 | 40d85448debf |
permissions | -rwxr-xr-x |
14 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# E D I T P D 0 |
|
4 |
# doc: Mon Nov 25 20:24:31 2013 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
5 |
# dlm: Tue Jul 12 18:56:55 2016 |
14 | 6 |
# (c) 2013 A.M. Thurnherr |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
7 |
# uE-Info: 118 0 NIL 0 0 72 2 2 4 NIL ofnI |
14 | 8 |
#====================================================================== |
9 |
||
10 |
# edit RDI PD0 file, e.g. to replace pitch/roll/heading with external values |
|
11 |
||
31 | 12 |
# NOTES: |
13 |
# |
|
14 |
# - editing instructions can be provided either in an editing file (primarily |
|
15 |
# for ensemble-specific editing), or with the -x option on the command line |
|
16 |
# (only or editing applied to all ensembles) |
|
17 |
# |
|
18 |
# - Data-Editing Library: |
|
19 |
# p(<pitch>) set pitch value (RDI not gimbal pitch) of current ensemble |
|
20 |
# r(<roll>) set roll alue value of current ensemble |
|
21 |
# h(<heading>) set heading alue value of current ensemble |
|
22 |
# |
|
23 |
# swap_beams(<b1>,<b2>) swap data from beams b1 and b2 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
24 |
# - input in beam coords required |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
25 |
# - beam rotation is equivalent to 3 consecutive beam swaps |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
26 |
# - basic BT data are swapped as well (not RL and not SIGNAL_STRENGTH) |
31 | 27 |
# |
28 |
# earth2beam() transform beam to earth coordinates |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
29 |
# - does not handle bin-remapping |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
30 |
# - input in earth coords required |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
31 |
# |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
32 |
# beam2earth() transform earth to beam coordinates |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
33 |
# - does not handle bin-remapping |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
34 |
# - input in beam coords required |
31 | 35 |
# |
34 | 36 |
# instrument2beam() transform instrument to earth coordinates |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
37 |
# - does not handle bin-remapping |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
38 |
# - input in instrument coords required |
34 | 39 |
# |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
40 |
# ensure_UL() correct data for wrong transducer orientation |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
41 |
# ensure_DL() - sets correct flag & negates roll value |
32 | 42 |
# |
31 | 43 |
# - -x notes: |
44 |
# - multiple perl expressions can be combined with , |
|
45 |
# |
|
46 |
# - Edit File Syntax: |
|
47 |
# - # comments ignored |
|
48 |
# - empty lines ignored |
|
49 |
# - [space] <ensemble-number|*> <space> <perl-expr> |
|
50 |
# - Examples: |
|
51 |
# 162 p(3), r(4), h(3.14) |
|
52 |
||
14 | 53 |
# HISTORY: |
31 | 54 |
# Nov 25, 2013: - created |
55 |
# Dec 18, 2015: - added switch_beams() |
|
56 |
# - added -x |
|
57 |
# Jan 9, 2016: - renamed switch_beams() to swap_beams() |
|
58 |
# - wrote documentation |
|
59 |
# - change output data-source ID from 0x7F to 0xE0 |
|
60 |
# - updated getopts to current perl version |
|
61 |
# - adapted to [ADCP_tools_lib.pl] |
|
32 | 62 |
# Feb 15, 2016: - added ensure_UL() ensure_DL() |
63 |
# Feb 23, 2016: - added -k |
|
64 |
# Feb 26, 2016: - added basic BT data to swap_beams() |
|
34 | 65 |
# - added earth2beam() |
66 |
# Apr 12, 2016: - added instrument2beam() |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
67 |
# Jun 3, 2016: - added beam2earth() |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
68 |
# - BUG: instrument2earth() set wrong flag |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
69 |
# Jun 8, 2016: - adapted to new interface of velInstrumentToBeam() |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
70 |
# - added %-good to beam2earth and earth2beam |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
71 |
# - made single-ping ensemble requirement for most routines |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
72 |
# Jul 12, 2016: - updated ensure_{DL,UL} routines |
14 | 73 |
|
31 | 74 |
use Getopt::Std; |
75 |
||
76 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
|
77 |
$ADCP_tools_minVersion = 1.4; |
|
78 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
|
14 | 79 |
|
80 |
$USAGE = "$0 @ARGV"; |
|
81 |
die("Usage: $0 " . |
|
31 | 82 |
'-e) <edit-file> | -x) <expr> ' . |
32 | 83 |
'-k)eep original data-source id' . |
31 | 84 |
"<input file> <output file>\n") |
32 | 85 |
unless (&getopts('ke:x:') && @ARGV == 2); |
14 | 86 |
|
28 | 87 |
die("$0: -e <edit-file> or -x <expr> required\n") |
31 | 88 |
unless (defined($opt_x) || -r $opt_e); |
14 | 89 |
|
31 | 90 |
print(STDERR "Reading $ARGV[0]..."); # read data |
14 | 91 |
readData($ARGV[0],\%dta); |
92 |
print(STDERR "done\n"); |
|
93 |
||
94 |
#---------------------------------------------------------------------- |
|
95 |
||
31 | 96 |
print(STDERR "Editing Data..."); |
14 | 97 |
|
98 |
#-------------------------------------------------- |
|
31 | 99 |
# Data Editing Library |
14 | 100 |
#-------------------------------------------------- |
101 |
||
32 | 102 |
# |
103 |
# override pitch/roll/heading |
|
104 |
# |
|
31 | 105 |
sub p($) { $dta{ENSEMBLE}[$e]->{PITCH} = $_[0]; return 1; } |
106 |
sub r($) { $dta{ENSEMBLE}[$e]->{ROLL} = $_[0]; return 1; } |
|
107 |
sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;} |
|
14 | 108 |
|
32 | 109 |
# |
110 |
# override transducer orientation |
|
111 |
# |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
112 |
# These routines are intended to correct ADCP data for |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
113 |
# erroneous orientation switch readings, primarily because |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
114 |
# of a stuck switch. While not fully debugged, negating |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
115 |
# the roll value greatly improves the vertical velocity |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
116 |
# solutions of 2007 CLIVAR I08S profile #1. (#2-#7 could |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
117 |
# also be used for testing) |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
118 |
# |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
119 |
|
32 | 120 |
sub ensure_DL() |
121 |
{ |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
122 |
if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP}) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
123 |
$dta{ENSEMBLE}[$e]->{ROLL} *= -1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
124 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
125 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = undef; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
126 |
} |
32 | 127 |
return 1; |
128 |
} |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
129 |
|
32 | 130 |
sub ensure_UL() |
131 |
{ |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
132 |
if ($dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN}) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
133 |
$dta{ENSEMBLE}[$e]->{ROLL} *= -1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
134 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_UP} = 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
135 |
$dta{ENSEMBLE}[$e]->{XDUCER_FACING_DOWN} = undef; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
136 |
} |
32 | 137 |
return 1; |
138 |
} |
|
139 |
||
140 |
# |
|
141 |
# swap data from two mis-connected beams |
|
142 |
# |
|
31 | 143 |
sub swap_beams($$) |
28 | 144 |
{ |
145 |
my($b1,$b2) = @_; |
|
32 | 146 |
my($tmp); |
28 | 147 |
|
31 | 148 |
# print(STDERR "\n entering swap_beams($b1,$b2) for ens = $e..."); |
149 |
||
150 |
die("$ARGV[0]: beam-coordinate data required\n") |
|
151 |
unless ($dta{BEAM_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
152 |
die("$ARGV[0]: single-ping ensembles required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
153 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
28 | 154 |
|
32 | 155 |
if ($dta{BT_PRESENT}) { |
156 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1]; |
|
157 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1]; |
|
158 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1] = $tmp; |
|
159 |
||
160 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b1-1]; |
|
161 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b2-1]; |
|
162 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b2-1] = $tmp; |
|
163 |
||
164 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b1-1]; |
|
165 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b2-1]; |
|
166 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b2-1] = $tmp; |
|
167 |
||
168 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b1-1]; |
|
169 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b2-1]; |
|
170 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b2-1] = $tmp; |
|
171 |
||
172 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b1-1]; |
|
173 |
$dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b2-1]; |
|
174 |
$dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b2-1] = $tmp; |
|
175 |
} |
|
176 |
||
28 | 177 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
32 | 178 |
$tmp = $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b1-1]; |
28 | 179 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b2-1]; |
180 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b2-1] = $tmp; |
|
181 |
||
182 |
$tmp = $dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b1-1]; |
|
183 |
$dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b2-1]; |
|
184 |
$dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b2-1] = $tmp; |
|
185 |
||
186 |
$tmp = $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b1-1]; |
|
187 |
$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b2-1]; |
|
188 |
$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b2-1] = $tmp; |
|
189 |
||
190 |
$tmp = $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b1-1]; |
|
191 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b2-1]; |
|
192 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b2-1] = $tmp; |
|
193 |
} |
|
31 | 194 |
return 1; |
195 |
} |
|
28 | 196 |
|
31 | 197 |
|
32 | 198 |
# |
199 |
# transform earth to beam coordinates |
|
200 |
# |
|
31 | 201 |
{ my($checked); |
202 |
||
203 |
sub earth2beam() |
|
204 |
{ |
|
205 |
unless ($checked) { |
|
206 |
die("$ARGV[0]: earth-coordinate data required\n") |
|
207 |
unless ($dta{EARTH_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
208 |
die("$ARGV[0]: single-ping ensembles required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
209 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
31 | 210 |
$dta{BEAM_COORDINATES} = 1; undef($dta{EARTH_COORDINATES}); |
211 |
$checked = 1; |
|
212 |
} |
|
213 |
||
214 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
215 |
if ($dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][3] == 100) { # 4-beam solution |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
216 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
217 |
velEarthToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
218 |
@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin]} = (100,100,100,100); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
219 |
} else { # 3-beam solution or no solution |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
220 |
undef(@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
221 |
@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin]} = (0,0,0,0); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
222 |
} |
31 | 223 |
} |
224 |
||
225 |
return 1; |
|
226 |
} |
|
227 |
||
28 | 228 |
} |
229 |
||
34 | 230 |
# |
231 |
# transform instrument to beam coordinates |
|
232 |
# |
|
233 |
{ my($checked); |
|
234 |
||
235 |
sub instrument2beam() |
|
236 |
{ |
|
237 |
unless ($checked) { |
|
238 |
die("$ARGV[0]: instrument-coordinate data required\n") |
|
239 |
unless ($dta{INSTRUMENT_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
240 |
die("$ARGV[0]: single-ping ensembles required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
241 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
34 | 242 |
$dta{BEAM_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES}); |
243 |
$checked = 1; |
|
244 |
} |
|
245 |
||
246 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
247 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
248 |
velInstrumentToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
34 | 249 |
} |
250 |
||
251 |
return 1; |
|
252 |
} |
|
253 |
||
254 |
} |
|
255 |
||
256 |
# |
|
257 |
# transform instrument to earth coordinates |
|
258 |
# |
|
259 |
{ my($checked); |
|
260 |
||
261 |
sub instrument2earth() |
|
262 |
{ |
|
263 |
unless ($checked) { |
|
264 |
die("$ARGV[0]: instrument-coordinate data required\n") |
|
265 |
unless ($dta{INSTRUMENT_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
266 |
die("$ARGV[0]: single-ping ensembles required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
267 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
268 |
$dta{EARTH_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES}); |
34 | 269 |
$checked = 1; |
270 |
} |
|
271 |
||
272 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
273 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
|
274 |
velInstrumentToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
|
275 |
} |
|
276 |
||
277 |
return 1; |
|
278 |
} |
|
279 |
||
280 |
} |
|
281 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
282 |
# |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
283 |
# transform beam to earth coordinates |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
284 |
# |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
285 |
{ my($checked); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
286 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
287 |
sub beam2earth() |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
288 |
{ |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
289 |
unless ($checked) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
290 |
die("$ARGV[0]: beam-coordinate data required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
291 |
unless ($dta{BEAM_COORDINATES}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
292 |
die("$ARGV[0]: single-ping ensembles required\n") |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
293 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
294 |
$dta{EARTH_COORDINATES} = 1; undef($dta{BEAM_COORDINATES}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
295 |
$checked = 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
296 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
297 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
298 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
299 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
300 |
velBeamToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
301 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][0] = 100*$RDI_Coords::threeBeamFlag; # 3-beam solution |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
302 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][1] = 0; # error velocity not checked |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
303 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][2] = # no solution -> more than 1 bad beam |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
304 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} ? 0 : 100; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
305 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][2] = # 4-beam solution |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
306 |
100 - $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][0]; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
307 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
308 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
309 |
return 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
310 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
311 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
312 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
313 |
|
14 | 314 |
#-------------------------------------------------- |
315 |
# Main Routine |
|
316 |
#-------------------------------------------------- |
|
317 |
||
31 | 318 |
if (defined($opt_x)) { # edit instructions on the command line |
28 | 319 |
push(@EE,'*'); |
320 |
my($id) = ($opt_x =~ m/^([A-Z]+)\s/); # e.g. PITCH, ROLL, HEADING |
|
321 |
$opt_x = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id) |
|
14 | 322 |
if defined($id); |
28 | 323 |
push(@EX,$opt_x); |
324 |
} |
|
14 | 325 |
|
31 | 326 |
if (defined($opt_e)) { # edit instructions in edit file |
28 | 327 |
open(EF,$opt_e) || die("$opt_e: $!\n"); |
328 |
while (<EF>) { |
|
329 |
s/\#.*//; |
|
330 |
next if m/^\s+$/; |
|
331 |
my($ens,$expr) = m/^\s*(\*|\d+)\s+(.*)$/; |
|
332 |
||
333 |
my($id) = ($expr =~ m/^([A-Z]+)\s/); # e.g. PITCH, ROLL, HEADING |
|
334 |
$expr = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id) |
|
335 |
if defined($id); |
|
336 |
||
337 |
push(@EE,$ens); |
|
338 |
push(@EX,$expr); |
|
339 |
} |
|
340 |
close(EF); |
|
341 |
} |
|
342 |
||
343 |
for (local($e)=my($eei)=0; $e<@{$dta{ENSEMBLE}}; $e++) { # local() needed for p(), r(), h() |
|
32 | 344 |
$dta{ENSEMBLE}[$e]->{DATA_SOURCE_ID} = 0xE0 # mark all ensembles except first |
345 |
unless ($opt_k || $e==0); |
|
28 | 346 |
if ($EE[$eei] eq '*' || $EE[$eei] == $dta{ENSEMBLE}[$e]->{NUMBER}) { # match => edit |
14 | 347 |
eval($EX[$eei]) || die("$@ while executing <$EX[$eei]>\n"); |
28 | 348 |
} elsif ($EE[$eei] > $dta{ENSEMBLE}[$e]->{NUMBER}) { # next edit later in file => skip |
14 | 349 |
next; |
28 | 350 |
} else { # need next edit |
14 | 351 |
$eei++; |
352 |
last if ($eei >= @EE); |
|
353 |
redo; |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
print(STDERR "done\n"); |
|
358 |
||
359 |
#---------------------------------------------------------------------- |
|
360 |
||
361 |
print(STDERR "Writing $ARGV[1]..."); # write data |
|
362 |
writeData($ARGV[1],\%dta); |
|
363 |
print(STDERR "done\n"); |
|
364 |
||
365 |
exit(0); |