author | A.M. Thurnherr <athurnherr@yahoo.com> |
Tue, 06 Dec 2022 12:36:04 -0500 | |
changeset 62 | 9e13aca980c7 |
parent 61 | 69192495f0db |
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 |
|
61 | 5 |
# dlm: Mon Oct 18 11:46:58 2021 |
14 | 6 |
# (c) 2013 A.M. Thurnherr |
61 | 7 |
# uE-Info: 45 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 |
# |
61 | 43 |
# dealias_attempt(<WV lim[m/s]>) correct data for erroneously low WV setting |
44 |
# - LIKELY DOES NOT WORK AT ALL |
|
45 |
# - DOES DEFINITELY NOT WORK FOR DATA WITH DOUBLE WRAPS |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
46 |
# |
31 | 47 |
# - -x notes: |
48 |
# - multiple perl expressions can be combined with , |
|
49 |
# |
|
50 |
# - Edit File Syntax: |
|
51 |
# - # comments ignored |
|
52 |
# - empty lines ignored |
|
53 |
# - [space] <ensemble-number|*> <space> <perl-expr> |
|
54 |
# - Examples: |
|
55 |
# 162 p(3), r(4), h(3.14) |
|
56 |
||
14 | 57 |
# HISTORY: |
31 | 58 |
# Nov 25, 2013: - created |
59 |
# Dec 18, 2015: - added switch_beams() |
|
60 |
# - added -x |
|
61 |
# Jan 9, 2016: - renamed switch_beams() to swap_beams() |
|
62 |
# - wrote documentation |
|
63 |
# - change output data-source ID from 0x7F to 0xE0 |
|
64 |
# - updated getopts to current perl version |
|
65 |
# - adapted to [ADCP_tools_lib.pl] |
|
32 | 66 |
# Feb 15, 2016: - added ensure_UL() ensure_DL() |
67 |
# Feb 23, 2016: - added -k |
|
68 |
# Feb 26, 2016: - added basic BT data to swap_beams() |
|
34 | 69 |
# - added earth2beam() |
70 |
# Apr 12, 2016: - added instrument2beam() |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
71 |
# Jun 3, 2016: - added beam2earth() |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
72 |
# - BUG: instrument2earth() set wrong flag |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
73 |
# 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
|
74 |
# - added %-good to beam2earth and earth2beam |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
75 |
# - 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
|
76 |
# Jul 12, 2016: - updated ensure_{DL,UL} routines |
37 | 77 |
# Nov 15, 2016: - BUG: ensure_{DL,UL} routines did not negate heading data |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
78 |
# Jul 27, 2017: - began working on dealias() |
41 | 79 |
# Dec 6, 2017: - cosmetics |
61 | 80 |
# Oct 18, 2021: - played around with dealias() with data from BLT and came |
81 |
# to the conclusion that it does not work; although, the |
|
82 |
# problem with the BLT data is that there are probably lots |
|
83 |
# of double wraps |
|
84 |
# END OF HISTORY |
|
14 | 85 |
|
31 | 86 |
use Getopt::Std; |
87 |
||
88 |
($ADCP_TOOLS) = ($0 =~ m{(.*/)[^/]+}); |
|
42 | 89 |
$ADCP_tools_minVersion = 2.1; |
31 | 90 |
require "$ADCP_TOOLS/ADCP_tools_lib.pl"; |
14 | 91 |
|
92 |
$USAGE = "$0 @ARGV"; |
|
93 |
die("Usage: $0 " . |
|
31 | 94 |
'-e) <edit-file> | -x) <expr> ' . |
41 | 95 |
'[-k)eep original data-source id] ' . |
31 | 96 |
"<input file> <output file>\n") |
32 | 97 |
unless (&getopts('ke:x:') && @ARGV == 2); |
14 | 98 |
|
28 | 99 |
die("$0: -e <edit-file> or -x <expr> required\n") |
31 | 100 |
unless (defined($opt_x) || -r $opt_e); |
14 | 101 |
|
31 | 102 |
print(STDERR "Reading $ARGV[0]..."); # read data |
14 | 103 |
readData($ARGV[0],\%dta); |
37 | 104 |
printf(STDERR "done (%d complete ensembles)\n", |
105 |
scalar(@{$dta{ENSEMBLE}})); |
|
14 | 106 |
|
107 |
#---------------------------------------------------------------------- |
|
108 |
||
31 | 109 |
print(STDERR "Editing Data..."); |
14 | 110 |
|
111 |
#-------------------------------------------------- |
|
31 | 112 |
# Data Editing Library |
14 | 113 |
#-------------------------------------------------- |
114 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
115 |
#-------------------------------------------------- |
32 | 116 |
# override pitch/roll/heading |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
117 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
118 |
|
31 | 119 |
sub p($) { $dta{ENSEMBLE}[$e]->{PITCH} = $_[0]; return 1; } |
120 |
sub r($) { $dta{ENSEMBLE}[$e]->{ROLL} = $_[0]; return 1; } |
|
121 |
sub h($) { $dta{ENSEMBLE}[$e]->{HEADING} = $_[0]; return 1;} |
|
14 | 122 |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
123 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
124 |
# correct data for erroneously low WV limit |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
125 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
126 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
127 |
{ my(@target); # static scope, undef initially |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
128 |
|
61 | 129 |
sub dealias_attempt($) |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
130 |
{ |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
131 |
my($WV) = @_; |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
132 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
133 |
if (@target) { # dealias everything but first ensemble |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
134 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
135 |
for (my($beam)=0; $beam<4; $beam++) { |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
136 |
next unless defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]); |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
137 |
my($dealiased) = 0; |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
138 |
$dealiased = ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] - 2*$WV) |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
139 |
if ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] > 0); |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
140 |
$dealiased = ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] + 2*$WV) |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
141 |
if ($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] < 0); |
61 | 142 |
# printf(STDERR "ens=$e beam=$beam bin=$bin: target=$target[$beam] vel=$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] vd=$dealiased\n"); |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
143 |
if (abs($target[$beam]-$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]) > |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
144 |
abs($target[$beam]-$dealiased)) { |
61 | 145 |
# print(STDERR "DEALIASED\n"); |
146 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam] = $dealiased; |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
147 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
148 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
149 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
150 |
} else { # @target is undef |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
151 |
$dealiased = 0; |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
152 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
153 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
154 |
@target = (0,0,0,0); # calc ref-lr average target for next ens |
61 | 155 |
@nSamp = (0,0,0,0); |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
156 |
for (my($bin)=1; $bin<=5; $bin++) { # should work even if N_BINS < 5 |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
157 |
for (my($beam)=0; $beam<4; $beam++) { |
61 | 158 |
next unless defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]); |
159 |
$target[$beam] += $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$beam]; |
|
160 |
$nSamp[$beam]++; |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
161 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
162 |
} |
61 | 163 |
for (my($beam)=0; $beam<4; $beam++) { |
164 |
$target[$beam] = $nSamp[$beam] ? ($target[$beam] / $nSamp[$beam]) : nan; |
|
165 |
} |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
166 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
167 |
return 1; |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
168 |
} |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
169 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
170 |
} # static scope |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
171 |
|
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
172 |
#-------------------------------------------------- |
32 | 173 |
# override transducer orientation |
174 |
# |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
175 |
# 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
|
176 |
# erroneous orientation switch readings, primarily because |
37 | 177 |
# of a stuck switch. |
178 |
# Roll: Based on text from the coord trans manual, |
|
179 |
# it seems likely that the roll data need to |
|
180 |
# be negated. In case of 2007(?) CLIVAR I08S |
|
181 |
# profile #1 w gets much better with negated |
|
182 |
# roll. Also, in 2016 CLIVAR P18 profile 003 |
|
183 |
# the instrument-offset calculation from |
|
184 |
# compass and pitch/roll only agree with the |
|
185 |
# roll negated. |
|
186 |
# Hdg: Based on the time-series of headings recorded |
|
187 |
# during P18 profile 003 the heading needs |
|
188 |
# to be negated. Doing so yields a good profile. |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
189 |
#-------------------------------------------------- |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
190 |
|
32 | 191 |
sub ensure_DL() |
192 |
{ |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
193 |
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
|
194 |
$dta{ENSEMBLE}[$e]->{ROLL} *= -1; |
37 | 195 |
$dta{ENSEMBLE}[$e]->{HEADING} *= -1; |
196 |
$dta{ENSEMBLE}[$e]->{HEADING} += 360 |
|
197 |
if ($dta{ENSEMBLE}[$e]->{HEADING} < 0); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
198 |
$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
|
199 |
$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
|
200 |
} |
32 | 201 |
return 1; |
202 |
} |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
203 |
|
32 | 204 |
sub ensure_UL() |
205 |
{ |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
206 |
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
|
207 |
$dta{ENSEMBLE}[$e]->{ROLL} *= -1; |
37 | 208 |
$dta{ENSEMBLE}[$e]->{HEADING} *= -1; |
209 |
$dta{ENSEMBLE}[$e]->{HEADING} += 360 |
|
210 |
if ($dta{ENSEMBLE}[$e]->{HEADING} < 0); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
211 |
$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
|
212 |
$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
|
213 |
} |
32 | 214 |
return 1; |
215 |
} |
|
216 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
217 |
#-------------------------------------------------- |
32 | 218 |
# swap data from two mis-connected beams |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
219 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
220 |
|
31 | 221 |
sub swap_beams($$) |
28 | 222 |
{ |
223 |
my($b1,$b2) = @_; |
|
32 | 224 |
my($tmp); |
28 | 225 |
|
31 | 226 |
# print(STDERR "\n entering swap_beams($b1,$b2) for ens = $e..."); |
227 |
||
228 |
die("$ARGV[0]: beam-coordinate data required\n") |
|
229 |
unless ($dta{BEAM_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
230 |
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
|
231 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
28 | 232 |
|
32 | 233 |
if ($dta{BT_PRESENT}) { |
234 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1]; |
|
235 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1]; |
|
236 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[$b2-1] = $tmp; |
|
237 |
||
238 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b1-1]; |
|
239 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b2-1]; |
|
240 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[$b2-1] = $tmp; |
|
241 |
||
242 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b1-1]; |
|
243 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b2-1]; |
|
244 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[$b2-1] = $tmp; |
|
245 |
||
246 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b1-1]; |
|
247 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b2-1]; |
|
248 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[$b2-1] = $tmp; |
|
249 |
||
250 |
$tmp = $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b1-1]; |
|
251 |
$dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b1-1] = $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b2-1]; |
|
252 |
$dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[$b2-1] = $tmp; |
|
253 |
} |
|
254 |
||
28 | 255 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
32 | 256 |
$tmp = $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b1-1]; |
28 | 257 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b2-1]; |
258 |
$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin][$b2-1] = $tmp; |
|
259 |
||
260 |
$tmp = $dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b1-1]; |
|
261 |
$dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b2-1]; |
|
262 |
$dta{ENSEMBLE}[$e]->{CORRELATION}[$bin][$b2-1] = $tmp; |
|
263 |
||
264 |
$tmp = $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b1-1]; |
|
265 |
$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b2-1]; |
|
266 |
$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$bin][$b2-1] = $tmp; |
|
267 |
||
268 |
$tmp = $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b1-1]; |
|
269 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b1-1] = $dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b2-1]; |
|
270 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$bin][$b2-1] = $tmp; |
|
271 |
} |
|
31 | 272 |
return 1; |
273 |
} |
|
28 | 274 |
|
31 | 275 |
|
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
276 |
#-------------------------------------------------- |
32 | 277 |
# transform earth to beam coordinates |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
278 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
279 |
|
31 | 280 |
{ my($checked); |
281 |
||
282 |
sub earth2beam() |
|
283 |
{ |
|
284 |
unless ($checked) { |
|
285 |
die("$ARGV[0]: earth-coordinate data required\n") |
|
286 |
unless ($dta{EARTH_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
287 |
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
|
288 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
31 | 289 |
$dta{BEAM_COORDINATES} = 1; undef($dta{EARTH_COORDINATES}); |
290 |
$checked = 1; |
|
291 |
} |
|
292 |
||
293 |
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
|
294 |
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
|
295 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
296 |
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
|
297 |
@{$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
|
298 |
} 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
|
299 |
undef(@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
300 |
@{$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
|
301 |
} |
31 | 302 |
} |
303 |
||
304 |
return 1; |
|
305 |
} |
|
306 |
||
28 | 307 |
} |
308 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
309 |
#-------------------------------------------------- |
34 | 310 |
# transform instrument to beam coordinates |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
311 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
312 |
|
34 | 313 |
{ my($checked); |
314 |
||
315 |
sub instrument2beam() |
|
316 |
{ |
|
317 |
unless ($checked) { |
|
318 |
die("$ARGV[0]: instrument-coordinate data required\n") |
|
319 |
unless ($dta{INSTRUMENT_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
320 |
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
|
321 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
34 | 322 |
$dta{BEAM_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES}); |
323 |
$checked = 1; |
|
324 |
} |
|
325 |
||
326 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
327 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
328 |
velInstrumentToBeam(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
34 | 329 |
} |
330 |
||
331 |
return 1; |
|
332 |
} |
|
333 |
||
334 |
} |
|
335 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
336 |
#-------------------------------------------------- |
34 | 337 |
# transform instrument to earth coordinates |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
338 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
339 |
|
34 | 340 |
{ my($checked); |
341 |
||
342 |
sub instrument2earth() |
|
343 |
{ |
|
344 |
unless ($checked) { |
|
345 |
die("$ARGV[0]: instrument-coordinate data required\n") |
|
346 |
unless ($dta{INSTRUMENT_COORDINATES}); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
347 |
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
|
348 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
349 |
$dta{EARTH_COORDINATES} = 1; undef($dta{INSTRUMENT_COORDINATES}); |
34 | 350 |
$checked = 1; |
351 |
} |
|
352 |
||
353 |
for (my($bin)=0; $bin<$dta{N_BINS}; $bin++) { |
|
354 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
|
355 |
velInstrumentToEarth(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]}); |
|
356 |
} |
|
357 |
||
358 |
return 1; |
|
359 |
} |
|
360 |
||
361 |
} |
|
362 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
363 |
#-------------------------------------------------- |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
364 |
# transform beam to earth coordinates |
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
365 |
#-------------------------------------------------- |
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
366 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
367 |
{ my($checked); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
368 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
369 |
sub beam2earth() |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
370 |
{ |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
371 |
unless ($checked) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
372 |
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
|
373 |
unless ($dta{BEAM_COORDINATES}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
374 |
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
|
375 |
unless ($dta{PINGS_PER_ENSEMBLE} == 1); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
376 |
$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
|
377 |
$checked = 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
378 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
379 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
380 |
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
|
381 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$bin]} = |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
382 |
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
|
383 |
$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
|
384 |
$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
|
385 |
$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
|
386 |
@{$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
|
387 |
$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
|
388 |
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
|
389 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
390 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
391 |
return 1; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
392 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
393 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
394 |
} |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
34
diff
changeset
|
395 |
|
14 | 396 |
#-------------------------------------------------- |
397 |
# Main Routine |
|
398 |
#-------------------------------------------------- |
|
399 |
||
31 | 400 |
if (defined($opt_x)) { # edit instructions on the command line |
28 | 401 |
push(@EE,'*'); |
402 |
my($id) = ($opt_x =~ m/^([A-Z]+)\s/); # e.g. PITCH, ROLL, HEADING |
|
403 |
$opt_x = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id) |
|
14 | 404 |
if defined($id); |
28 | 405 |
push(@EX,$opt_x); |
406 |
} |
|
14 | 407 |
|
31 | 408 |
if (defined($opt_e)) { # edit instructions in edit file |
28 | 409 |
open(EF,$opt_e) || die("$opt_e: $!\n"); |
410 |
while (<EF>) { |
|
411 |
s/\#.*//; |
|
412 |
next if m/^\s+$/; |
|
413 |
my($ens,$expr) = m/^\s*(\*|\d+)\s+(.*)$/; |
|
414 |
||
40
6a46e9d31106
after Hamburg visit
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
37
diff
changeset
|
415 |
my($id) = ($expr =~ m/^([A-Z]+)\s/); # e.g. PITCH, ROLL, HEADING |
28 | 416 |
$expr = sprintf('$dta{ENSEMBLE}[$e]->{%s}',$id) |
417 |
if defined($id); |
|
418 |
||
419 |
push(@EE,$ens); |
|
420 |
push(@EX,$expr); |
|
421 |
} |
|
422 |
close(EF); |
|
423 |
} |
|
424 |
||
425 |
for (local($e)=my($eei)=0; $e<@{$dta{ENSEMBLE}}; $e++) { # local() needed for p(), r(), h() |
|
32 | 426 |
$dta{ENSEMBLE}[$e]->{DATA_SOURCE_ID} = 0xE0 # mark all ensembles except first |
427 |
unless ($opt_k || $e==0); |
|
28 | 428 |
if ($EE[$eei] eq '*' || $EE[$eei] == $dta{ENSEMBLE}[$e]->{NUMBER}) { # match => edit |
14 | 429 |
eval($EX[$eei]) || die("$@ while executing <$EX[$eei]>\n"); |
28 | 430 |
} elsif ($EE[$eei] > $dta{ENSEMBLE}[$e]->{NUMBER}) { # next edit later in file => skip |
14 | 431 |
next; |
28 | 432 |
} else { # need next edit |
14 | 433 |
$eei++; |
434 |
last if ($eei >= @EE); |
|
435 |
redo; |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
print(STDERR "done\n"); |
|
440 |
||
441 |
#---------------------------------------------------------------------- |
|
442 |
||
443 |
print(STDERR "Writing $ARGV[1]..."); # write data |
|
444 |
writeData($ARGV[1],\%dta); |
|
445 |
print(STDERR "done\n"); |
|
446 |
||
447 |
exit(0); |