LADCP_w_CTD
changeset 58 7688bec6fe87
parent 54 828e5466391b
child 59 4118a8e880de
--- a/LADCP_w_CTD	Sat Apr 10 06:00:45 2021 -0400
+++ b/LADCP_w_CTD	Mon Jun 27 19:06:50 2022 -1000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W _ C T D 
 #                    doc: Mon Nov  3 17:34:19 2014
-#                    dlm: Fri Jun 26 13:07:13 2020
+#                    dlm: Mon Jun 27 19:04:02 2022
 #                    (c) 2014 A.M. Thurnherr
-#                    uE-Info: 144 14 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 213 68 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 $antsSummary = 'pre-process SBE 9plus CTD data for LADCP_w';
@@ -93,6 +93,9 @@
 #	Aug 30, 2019: - renamed -g to -m)odulo error correction (not)
 #				  - added -f)ill missing data
 #	Jun 26, 2020: - added salinity -b)ias correction
+#	Jun 27, 2022: - BUG: fill_gaps code could not deal with format errors (nans)
+#				  - reversed semantics of -m because modulo error correction code has bugs
+# HISTORY END
 
 # NOTES:
 #	w_CTD is positive during the downcast to make the sign of the apparent
@@ -120,7 +123,7 @@
 	'[use -a)lternate sensor pair]',
 	'[correct -S)alinity <bias>]',
 	'[-r)etain all data (no editing)] [allow infinite -o)utliers]',
-	'[suppress CTD -m)odulo error correction]',
+	'[apply CTD -m)odulo error correction]',
 	'[-s)ampling <rate[6Hz]>]',
 	'[lowpass w_CTD -c)utoff <limit[2s]>] [-w)inch-speed <granularity[10s]>]',
 	'[profile -i)d <id>] [station -l)ocation <lat/lon>]',
@@ -207,7 +210,7 @@
 		}
 	}
 
-	unless ($opt_m) {												# set up correction for dropped scans
+	if ($opt_m) {													# set up correction for dropped scans
 		$systimeF = &fnrNoErr('timeY');
 		$xmerrF  = &fnrNoErr('modError');
 		if (defined($systimeF) && defined($xmerrF)) {
@@ -269,7 +272,16 @@
 	my($scans_replaced) = 0;
 	my($scans_deleted) = 0;
 
-	for (my($scan)=30; $scan<@ants_; $scan++) {										# start a bit more than 1 second into the cast
+	printf("BEFORE: %d scans\n",scalar(@ants_));
+	for (my($scan)=my($scani)=0; $scan<@ants_; $scan++,$scani++) {					# remove scans with incomplete information
+		next if numbersp($ants_[$scan][$systimeF],$ants_[$scan][$xmerrF]);
+		printf(STDERR "scani#%d removed\n",$scani+1);
+		splice(@ants_,$scan,1);
+		$scan--; $scans_deleted++;
+    }
+	printf("AFTER: %d scans\n",scalar(@ants_));
+
+	for (my($scan) = 30; $scan<@ants_; $scan++) {									# start a bit more than 1 second into the cast	
 		next if ($ants_[$scan][$systimeF] == $ants_[$scan-1][$systimeF]);			# skip forward to next systime second
 
 		if ($ants_[$scan][$systimeF] > $ants_[$scan-1][$systimeF]+1) {				# gap spans at least one full second
@@ -344,7 +356,7 @@
 		}
 
 		my($scans_this_sec) = 0;
-		die("$ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1")
+		die("scan#$second_start+1: $ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1: assertion failed")
 			unless ($ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1);
 		for (my($i)=0; $ants_[$second_start+$i][$systimeF]==$ants_[$second_start-1][$systimeF]+1; $i++) {
 			$scans_this_sec++;