1 #!/usr/bin/perl |
1 #!/usr/bin/perl |
2 #====================================================================== |
2 #====================================================================== |
3 # P A T C H P D 0 |
3 # P A T C H P D 0 |
4 # doc: Tue Aug 23 20:00:15 2016 |
4 # doc: Tue Aug 23 20:00:15 2016 |
5 # dlm: Wed Jun 13 20:35:05 2018 |
5 # dlm: Mon Jul 1 16:56:51 2019 |
6 # (c) 2010 A.M. Thurnherr |
6 # (c) 2010 A.M. Thurnherr |
7 # uE-Info: 184 88 NIL 0 0 72 2 2 4 NIL ofnI |
7 # uE-Info: 189 0 NIL 0 0 72 2 2 4 NIL ofnI |
8 #====================================================================== |
8 #====================================================================== |
9 |
9 |
10 $antsSummary = 'patch TRDI PD0 file with external attitude data'; |
10 $antsSummary = 'patch TRDI PD0 file with external attitude data'; |
11 |
11 |
12 # History: |
12 # History: |
17 # Dec 9, 2017: - added $antsSuppressCommonOptions = 1; |
17 # Dec 9, 2017: - added $antsSuppressCommonOptions = 1; |
18 # Dec 23, 2017: - added support for -c |
18 # Dec 23, 2017: - added support for -c |
19 # - BUG: not backward compatible with old IMP files any more |
19 # - BUG: not backward compatible with old IMP files any more |
20 # Jun 13, 2017: - added pitch and roll to -o |
20 # Jun 13, 2017: - added pitch and roll to -o |
21 # - BUG: ??? does -o handle pitch and roll ANOMALIES correctly? |
21 # - BUG: ??? does -o handle pitch and roll ANOMALIES correctly? |
|
22 # Jun 30, 2019: - -o did not work with single argument |
22 |
23 |
23 # PATCH-FILE REQUIREMENTS (ANTS format) |
24 # PATCH-FILE REQUIREMENTS (ANTS format) |
24 # - %LADCP_pitch.mu %LADCP_roll.mu mean LADCP pitch and roll |
25 # - %LADCP_pitch.mu %LADCP_roll.mu mean LADCP pitch and roll |
25 # - %IMU_hdg_offset heading offset of external IMU |
26 # - %IMU_hdg_offset heading offset of external IMU |
26 # - LADCP_ens ADCP ensemble number |
27 # - LADCP_ens ADCP ensemble number |
83 |
84 |
84 #---------------------------------------------------------------------- |
85 #---------------------------------------------------------------------- |
85 # Step 2: Process External Attidue Input to Patch PD0 file |
86 # Step 2: Process External Attidue Input to Patch PD0 file |
86 #---------------------------------------------------------------------- |
87 #---------------------------------------------------------------------- |
87 |
88 |
88 my($pr_missing,$hdg_missing) = (0,0); |
|
89 |
|
90 &antsIn(); # load first IMP record |
89 &antsIn(); # load first IMP record |
91 |
90 |
92 my($ensF) = &fnr('LADCP_ens'); |
91 my($ensF) = &fnr('LADCP_ens'); |
93 my($pitchF) = &fnr('pitch'); |
92 my($pitchF) = &fnr('pitch'); |
94 my($rollF) = &fnr('roll'); |
93 my($rollF) = &fnr('roll'); |
100 my($pofs,$rofs) = (0,0); # apply externally supplied offset(s) |
99 my($pofs,$rofs) = (0,0); # apply externally supplied offset(s) |
101 my($rho,$crho,$srho); |
100 my($rho,$crho,$srho); |
102 if (defined($opt_o)) { |
101 if (defined($opt_o)) { |
103 my($pofs,$rofs,$hofs) = split(/,/,$opt_o); |
102 my($pofs,$rofs,$hofs) = split(/,/,$opt_o); |
104 |
103 |
105 if (defined($pofs)) { # pitch and roll offsets supplied |
104 if (defined($rofs)) { # pitch and roll offsets supplied |
106 croak("$0: cannot decode -o $opt_o\n") |
105 croak("$0: cannot decode -o $opt_o\n") |
107 unless numbersp($pofs,$rofs); |
106 unless numbersp($pofs,$rofs,$hofs); |
108 } else { # no pitch and roll, only heading |
107 } else { # no pitch and roll, only heading |
109 $hofs = $pofs; |
108 $hofs = $pofs; |
110 $pofs = undef; |
109 $pofs = undef; |
111 } |
110 } |
112 croak("$0: cannot decode -o $opt_o\n") |
111 croak("$0: cannot decode -o $opt_o\n") |
126 $LADCP_pitch_mean = $IMP_pitch_mean - $pofs; # apply externally supplied offsets |
125 $LADCP_pitch_mean = $IMP_pitch_mean - $pofs; # apply externally supplied offsets |
127 $LADCP_roll_mean = $IMP_roll_mean - $rofs; |
126 $LADCP_roll_mean = $IMP_roll_mean - $rofs; |
128 } |
127 } |
129 } |
128 } |
130 |
129 |
|
130 my($pr_missing,$hdg_missing) = (0,0); |
|
131 my($missing_pr_block_len,$missing_hdg_block_len); |
|
132 |
131 do { |
133 do { |
|
134 my($ADCP_deployed); |
132 my($ens) = $P{RECNO}; |
135 my($ens) = $P{RECNO}; |
133 die("assertion failed [$ants_[0][$ensF] != $LADCP{ENSEMBLE}[$ens]->{NUMBER} --- 1-$LADCP{ENSEMBLE}[0]->{NUMBER} + $P{RECNO} + $d]") |
136 die("assertion failed [$ants_[0][$ensF] != $LADCP{ENSEMBLE}[$ens]->{NUMBER} --- 1-$LADCP{ENSEMBLE}[0]->{NUMBER} + $P{RECNO} + $d]") |
134 unless ($ants_[0][$ensF] == $LADCP{ENSEMBLE}[$ens]->{NUMBER}); |
137 unless ($ants_[0][$ensF] == $LADCP{ENSEMBLE}[$ens]->{NUMBER}); |
135 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} = 0xA0; |
138 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} = 0xA0; |
136 |
139 |
137 if (numbersp($ants_[0][$pitchF],$ants_[0][$rollF])) { # valid IMP data -> patch LADCP ensemble |
140 if (numbersp($ants_[0][$pitchF],$ants_[0][$rollF])) { # valid IMP data -> patch LADCP ensemble |
|
141 $ADCP_deployed = 1; |
|
142 $missing_pr_block_len = 0; |
138 if (defined($opt_o)) { # -o set: rotate pitch and roll into correct coordinates |
143 if (defined($opt_o)) { # -o set: rotate pitch and roll into correct coordinates |
139 my($rot_p) = ($ants_[$r][$pitchF] * $crho + |
144 my($rot_p) = ($ants_[$r][$pitchF] * $crho + |
140 $ants_[$r][$rollF] * $srho); |
145 $ants_[$r][$rollF] * $srho); |
141 my($rot_r) = (-$ants_[$r][$pitchF] * $srho + |
146 my($rot_r) = (-$ants_[$r][$pitchF] * $srho + |
142 $ants_[$r][$rollF] * $crho); |
147 $ants_[$r][$rollF] * $crho); |
151 if ($opt_r) { # patch roll |
156 if ($opt_r) { # patch roll |
152 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_r<<1); |
157 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_r<<1); |
153 $LADCP{ENSEMBLE}[$ens]->{ROLL} = $LADCP_roll_mean + $ants_[0][$rollF]; |
158 $LADCP{ENSEMBLE}[$ens]->{ROLL} = $LADCP_roll_mean + $ants_[0][$rollF]; |
154 } |
159 } |
155 } else { # no valid IMP pitch and roll => invalidate LADCP data |
160 } else { # no valid IMP pitch and roll => invalidate LADCP data |
156 $pr_missing++; |
161 $pr_missing++ if $ADCP_deployed; # don't count missing before deployment |
|
162 $missing_pr_block_len++; |
157 unless ($opt_k) { |
163 unless ($opt_k) { |
158 clearEns(\%LADCP,$ens); |
164 clearEns(\%LADCP,$ens); |
159 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
165 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
160 } |
166 } |
161 } |
167 } |
162 |
168 |
163 if (numberp($ants_[0][$hdgF])) { # valid IMP heading |
169 if (numberp($ants_[0][$hdgF])) { # valid IMP heading |
164 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= $opt_h; |
170 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= $opt_h; |
|
171 $missing_hdg_block_len = 0; |
165 if (defined($opt_o)) { # apply offset on -o; otherwise, data are correctly rotated |
172 if (defined($opt_o)) { # apply offset on -o; otherwise, data are correctly rotated |
166 $ants_[0][$hdgF] -= $rho; |
173 $ants_[0][$hdgF] -= $rho; |
167 $ants_[0][$hdgF] += 360 if ($ants_[0][$hdgF] < 0); |
174 $ants_[0][$hdgF] += 360 if ($ants_[0][$hdgF] < 0); |
168 } |
175 } |
169 $LADCP{ENSEMBLE}[$ens]->{HEADING} = $ants_[0][$hdgF] # patch heading |
176 $LADCP{ENSEMBLE}[$ens]->{HEADING} = $ants_[0][$hdgF] # patch heading |
170 if $opt_h; |
177 if $opt_h; |
171 } else { # no valid IMP heading => invalidate LADCP data |
178 } else { # no valid IMP heading => invalidate LADCP data |
172 $hdg_missing++; |
179 $hdg_missing++ if $ADCP_deployed; |
|
180 $missing_hdg_block_len++; |
173 unless ($opt_k) { |
181 unless ($opt_k) { |
174 clearEns(\%LADCP,$ens); |
182 clearEns(\%LADCP,$ens); |
175 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
183 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
176 } |
184 } |
177 } |
185 } |
178 } while (&antsIn()); |
186 } while (&antsIn()); |
|
187 $pr_missing -= missing_pr_block_len; # don't count final block (post recovery) |
|
188 $hdg_missing -= missing_hdg_block_len; |
179 |
189 |
180 $LADCP{ENSEMBLE}[0]->{DATA_SOURCE_ID} = 0x7F; # ensure correct DSID (1st ens: orig; 2nd ens: this prog) |
190 $LADCP{ENSEMBLE}[0]->{DATA_SOURCE_ID} = 0x7F; # ensure correct DSID (1st ens: orig; 2nd ens: this prog) |
181 $LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID} = 0xA0 |
191 $LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID} = 0xA0 |
182 unless ($LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID}&0xF0 == 0xA0); |
192 unless ($LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID}&0xF0 == 0xA0); |
183 |
193 |