--- a/patchPD0
+++ b/patchPD0
@@ -2,9 +2,9 @@
#======================================================================
# P A T C H P D 0
# doc: Tue Aug 23 20:00:15 2016
-# dlm: Wed Jun 13 20:35:05 2018
+# dlm: Mon Jul 1 16:56:51 2019
# (c) 2010 A.M. Thurnherr
-# uE-Info: 184 88 NIL 0 0 72 2 2 4 NIL ofnI
+# uE-Info: 189 0 NIL 0 0 72 2 2 4 NIL ofnI
#======================================================================
$antsSummary = 'patch TRDI PD0 file with external attitude data';
@@ -19,6 +19,7 @@
# - BUG: not backward compatible with old IMP files any more
# Jun 13, 2017: - added pitch and roll to -o
# - BUG: ??? does -o handle pitch and roll ANOMALIES correctly?
+# Jun 30, 2019: - -o did not work with single argument
# PATCH-FILE REQUIREMENTS (ANTS format)
# - %LADCP_pitch.mu %LADCP_roll.mu mean LADCP pitch and roll
@@ -85,8 +86,6 @@
# Step 2: Process External Attidue Input to Patch PD0 file
#----------------------------------------------------------------------
-my($pr_missing,$hdg_missing) = (0,0);
-
&antsIn(); # load first IMP record
my($ensF) = &fnr('LADCP_ens');
@@ -102,9 +101,9 @@
if (defined($opt_o)) {
my($pofs,$rofs,$hofs) = split(/,/,$opt_o);
- if (defined($pofs)) { # pitch and roll offsets supplied
+ if (defined($rofs)) { # pitch and roll offsets supplied
croak("$0: cannot decode -o $opt_o\n")
- unless numbersp($pofs,$rofs);
+ unless numbersp($pofs,$rofs,$hofs);
} else { # no pitch and roll, only heading
$hofs = $pofs;
$pofs = undef;
@@ -128,13 +127,19 @@
}
}
+my($pr_missing,$hdg_missing) = (0,0);
+my($missing_pr_block_len,$missing_hdg_block_len);
+
do {
+ my($ADCP_deployed);
my($ens) = $P{RECNO};
die("assertion failed [$ants_[0][$ensF] != $LADCP{ENSEMBLE}[$ens]->{NUMBER} --- 1-$LADCP{ENSEMBLE}[0]->{NUMBER} + $P{RECNO} + $d]")
unless ($ants_[0][$ensF] == $LADCP{ENSEMBLE}[$ens]->{NUMBER});
$LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} = 0xA0;
if (numbersp($ants_[0][$pitchF],$ants_[0][$rollF])) { # valid IMP data -> patch LADCP ensemble
+ $ADCP_deployed = 1;
+ $missing_pr_block_len = 0;
if (defined($opt_o)) { # -o set: rotate pitch and roll into correct coordinates
my($rot_p) = ($ants_[$r][$pitchF] * $crho +
$ants_[$r][$rollF] * $srho);
@@ -153,7 +158,8 @@
$LADCP{ENSEMBLE}[$ens]->{ROLL} = $LADCP_roll_mean + $ants_[0][$rollF];
}
} else { # no valid IMP pitch and roll => invalidate LADCP data
- $pr_missing++;
+ $pr_missing++ if $ADCP_deployed; # don't count missing before deployment
+ $missing_pr_block_len++;
unless ($opt_k) {
clearEns(\%LADCP,$ens);
$LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0;
@@ -162,6 +168,7 @@
if (numberp($ants_[0][$hdgF])) { # valid IMP heading
$LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID} |= $opt_h;
+ $missing_hdg_block_len = 0;
if (defined($opt_o)) { # apply offset on -o; otherwise, data are correctly rotated
$ants_[0][$hdgF] -= $rho;
$ants_[0][$hdgF] += 360 if ($ants_[0][$hdgF] < 0);
@@ -169,13 +176,16 @@
$LADCP{ENSEMBLE}[$ens]->{HEADING} = $ants_[0][$hdgF] # patch heading
if $opt_h;
} else { # no valid IMP heading => invalidate LADCP data
- $hdg_missing++;
+ $hdg_missing++ if $ADCP_deployed;
+ $missing_hdg_block_len++;
unless ($opt_k) {
clearEns(\%LADCP,$ens);
$LADCP{ENSEMBLE}[$ens]->{DATA_SOURCE_ID}= 0xA0;
}
}
} while (&antsIn());
+$pr_missing -= missing_pr_block_len; # don't count final block (post recovery)
+$hdg_missing -= missing_hdg_block_len;
$LADCP{ENSEMBLE}[0]->{DATA_SOURCE_ID} = 0x7F; # ensure correct DSID (1st ens: orig; 2nd ens: this prog)
$LADCP{ENSEMBLE}[1]->{DATA_SOURCE_ID} = 0xA0