75 |
77 |
76 #---------------------------------------------------------------------- |
78 #---------------------------------------------------------------------- |
77 # Step 1: Read LADCP Data |
79 # Step 1: Read LADCP Data |
78 #---------------------------------------------------------------------- |
80 #---------------------------------------------------------------------- |
79 |
81 |
80 readData($LADCP_file,\%LADCP); |
82 readData($LADCP_file,\%LADCP); # TRDI PD0 file |
81 |
83 |
82 #---------------------------------------------------------------------- |
84 #---------------------------------------------------------------------- |
83 # Step 2: Process External Attidue Input to Patch PD0 file |
85 # Step 2: Process External Attidue Input to Patch PD0 file |
84 #---------------------------------------------------------------------- |
86 #---------------------------------------------------------------------- |
85 |
87 |
86 my($pr_missing,$hdg_missing) = (0,0); |
88 my($pr_missing,$hdg_missing) = (0,0); |
87 |
89 |
88 &antsIn(); |
90 &antsIn(); # load first IMP record |
89 |
91 |
90 my($ensF) = &fnr('LADCP_ens'); |
92 my($ensF) = &fnr('LADCP_ens'); |
91 my($pitchF) = &fnr('pitch'); |
93 my($pitchF) = &fnr('pitch'); |
92 my($rollF) = &fnr('roll'); |
94 my($rollF) = &fnr('roll'); |
93 my($hdgF) = &fnr('hdg'); |
95 my($hdgF) = &fnr('hdg'); |
94 my($LADCP_pitch_mean) = &antsRequireParam('LADCP_pitch.mu'); |
96 my($LADCP_pitch_mean) = &antsRequireParam('LADCP_pitch.mu'); |
95 my($LADCP_roll_mean) = &antsRequireParam('LADCP_roll.mu'); |
97 my($LADCP_roll_mean) = &antsRequireParam('LADCP_roll.mu'); |
96 |
98 |
97 my($rho,$crho,$srho); |
99 |
|
100 my($pofs,$rofs) = (0,0); # apply externally supplied offset(s) |
|
101 my($rho,$crho,$srho); |
98 if (defined($opt_o)) { |
102 if (defined($opt_o)) { |
|
103 my($pofs,$rofs,$hofs) = split(/,/,$opt_o); |
|
104 |
|
105 if (defined($pofs)) { # pitch and roll offsets supplied |
|
106 croak("$0: cannot decode -o $opt_o\n") |
|
107 unless numbersp($pofs,$rofs); |
|
108 } else { # no pitch and roll, only heading |
|
109 $hofs = $pofs; |
|
110 $pofs = undef; |
|
111 } |
|
112 croak("$0: cannot decode -o $opt_o\n") |
|
113 unless numberp($hofs); |
|
114 # set up heading correction |
99 &antsAddParams('IMU_hdg_offset',$P{IMP_hdg_offset}) # backward compatibility |
115 &antsAddParams('IMU_hdg_offset',$P{IMP_hdg_offset}) # backward compatibility |
100 if defined($P{IMP_hdg_offset}); |
116 if defined($P{IMP_hdg_offset}); |
101 $rho = $opt_o - &antsRequireParam('IMU_hdg_offset'); |
117 $rho = $hofs - &antsRequireParam('IMU_hdg_offset'); # calculate correction relative to already applied one |
102 $crho = cos(rad($rho)); |
118 $crho = cos(rad($rho)); |
103 $srho = sin(rad($rho)); |
119 $srho = sin(rad($rho)); |
|
120 |
|
121 if (defined($pofs)) { # rotate IMP pitch and roll offsets into new LADCP frame |
|
122 my($IMP_pitch_mean) = &antsRequireParam('IMP_pitch.mu') * $crho |
|
123 + &antsRequireParam('IMP_roll.mu') * $srho; |
|
124 my($IMP_roll_mean) = -&antsRequireParam('IMP_pitch.mu') * $srho |
|
125 + &antsRequireParam('IMP_roll.mu') * $crho; |
|
126 $LADCP_pitch_mean = $IMP_pitch_mean - $pofs; # apply externally supplied offsets |
|
127 $LADCP_roll_mean = $IMP_roll_mean - $rofs; |
|
128 } |
104 } |
129 } |
105 |
130 |
106 do { |
131 do { |
107 my($ens) = $P{RECNO}; |
132 my($ens) = $P{RECNO}; |
108 die("assertion failed [$ants_[0][$ensF] != $LADCP{ENSEMBLE}[$ens]->{NUMBER} --- 1-$LADCP{ENSEMBLE}[0]->{NUMBER} + $P{RECNO} + $d]") |
133 die("assertion failed [$ants_[0][$ensF] != $LADCP{ENSEMBLE}[$ens]->{NUMBER} --- 1-$LADCP{ENSEMBLE}[0]->{NUMBER} + $P{RECNO} + $d]") |
109 unless ($ants_[0][$ensF] == $LADCP{ENSEMBLE}[$ens]->{NUMBER}); |
134 unless ($ants_[0][$ensF] == $LADCP{ENSEMBLE}[$ens]->{NUMBER}); |
110 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} = 0xA0; |
135 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} = 0xA0; |
111 |
136 |
112 if (numbersp($ants_[0][$pitchF],$ants_[0][$rollF])) { |
137 if (numbersp($ants_[0][$pitchF],$ants_[0][$rollF])) { # valid IMP data -> patch LADCP ensemble |
113 if (defined($opt_o)) { |
138 if (defined($opt_o)) { # -o set: rotate pitch and roll into correct coordinates |
114 my($rot_p) = ($ants_[$r][$pitchF] * $crho + |
139 my($rot_p) = ($ants_[$r][$pitchF] * $crho + |
115 $ants_[$r][$rollF] * $srho); |
140 $ants_[$r][$rollF] * $srho); |
116 my($rot_r) = (-$ants_[$r][$pitchF] * $srho + |
141 my($rot_r) = (-$ants_[$r][$pitchF] * $srho + |
117 $ants_[$r][$rollF] * $crho); |
142 $ants_[$r][$rollF] * $crho); |
118 $ants_[$r][$pitchF] = $rot_p; |
143 $ants_[$r][$pitchF] = $rot_p; |
119 $ants_[$r][$rollF] = $rot_r; |
144 $ants_[$r][$rollF] = $rot_r; |
120 } |
145 } |
121 if ($opt_p) { |
146 if ($opt_p) { # patch pitch |
122 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_p<<2); |
147 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_p<<2); |
123 $LADCP{ENSEMBLE}[$ens]->{PITCH} = RDI_pitch($LADCP_pitch_mean + $ants_[0][$pitchF], |
148 $LADCP{ENSEMBLE}[$ens]->{PITCH} = RDI_pitch($LADCP_pitch_mean + $ants_[0][$pitchF], |
124 $LADCP_roll_mean + $ants_[0][$rollF]); |
149 $LADCP_roll_mean + $ants_[0][$rollF]); |
125 } |
150 } |
126 if ($opt_r) { |
151 if ($opt_r) { # patch roll |
127 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_r<<1); |
152 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= ($opt_r<<1); |
128 $LADCP{ENSEMBLE}[$ens]->{ROLL} = $LADCP_roll_mean + $ants_[0][$rollF]; |
153 $LADCP{ENSEMBLE}[$ens]->{ROLL} = $LADCP_roll_mean + $ants_[0][$rollF]; |
129 } |
154 } |
130 } else { |
155 } else { # no valid IMP pitch and roll => invalidate LADCP data |
131 $pr_missing++; |
156 $pr_missing++; |
132 unless ($opt_k) { |
157 unless ($opt_k) { |
133 clearEns(\%LADCP,$ens); |
158 clearEns(\%LADCP,$ens); |
134 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
159 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
135 } |
160 } |
136 } |
161 } |
137 |
162 |
138 if (numberp($ants_[0][$hdgF])) { |
163 if (numberp($ants_[0][$hdgF])) { # valid IMP heading |
139 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= $opt_h; |
164 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= $opt_h; |
140 if (defined($opt_o)) { |
165 if (defined($opt_o)) { # apply offset on -o; otherwise, data are correctly rotated |
141 $ants_[0][$hdgF] -= $rho; |
166 $ants_[0][$hdgF] -= $rho; |
142 $ants_[0][$hdgF] += 360 if ($ants_[0][$hdgF] < 0); |
167 $ants_[0][$hdgF] += 360 if ($ants_[0][$hdgF] < 0); |
143 } |
168 } |
144 $LADCP{ENSEMBLE}[$ens]->{HEADING} = $ants_[0][$hdgF] |
169 $LADCP{ENSEMBLE}[$ens]->{HEADING} = $ants_[0][$hdgF] # patch heading |
145 if $opt_h; |
170 if $opt_h; |
146 } else { |
171 } else { # no valid IMP heading => invalidate LADCP data |
147 $hdg_missing++; |
172 $hdg_missing++; |
148 unless ($opt_k) { |
173 unless ($opt_k) { |
149 clearEns(\%LADCP,$ens); |
174 clearEns(\%LADCP,$ens); |
150 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
175 $LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0; |
151 } |
176 } |
152 } |
177 } |
153 } while (&antsIn()); |
178 } while (&antsIn()); |
154 |
179 |
155 $LADCP{ENSEMBLE}[0]->{DATA_SOURCE_ID} = 0x7F; # ensure correct DSID (1st ens: orig; 2nd ens: this prog) |
180 $LADCP{ENSEMBLE}[0]->{DATA_SOURCE_ID} = 0x7F; # ensure correct DSID (1st ens: orig; 2nd ens: this prog) |
156 $LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID} = 0xA0 |
181 $LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID} = 0xA0 |
157 unless ($LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID}&0xF0 == 0xA0); |
182 unless ($LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID}&0xF0 == 0xA0); |
158 |
183 |
159 writeData($outPD0,\%LADCP); |
184 writeData($outPD0,\%LADCP); # write new PD0 |
160 |
185 |
161 my($verb) = $opt_k ? 'retained' : 'cleared'; |
186 my($verb) = $opt_k ? 'retained' : 'cleared'; |
162 printf(STDERR "$outPD0: %d pitch/roll & %d heading values $verb\n",$pr_missing,$hdg_missing) |
187 printf(STDERR "$outPD0: %d pitch/roll & %d heading values $verb\n",$pr_missing,$hdg_missing) |
163 if ($pr_missing+$hdg_missing); |
188 if ($pr_missing+$hdg_missing); |
164 |
189 |