LADCP_w_CTD
changeset 59 4118a8e880de
parent 58 7688bec6fe87
parent 57 69e39fcb7f41
child 61 20d9316fdeb8
--- a/LADCP_w_CTD	Mon Jun 27 19:06:50 2022 -1000
+++ b/LADCP_w_CTD	Mon Jun 27 20:07:11 2022 -1000
@@ -93,6 +93,16 @@
 #	Aug 30, 2019: - renamed -g to -m)odulo error correction (not)
 #				  - added -f)ill missing data
 #	Jun 26, 2020: - added salinity -b)ias correction
+#	Apr 29, 2021: - improved warning message
+#	Jun 29, 2021: - improved plot labelling
+#	Jun 30, 2021: - ditto
+#	Jul 13, 2021: - improved gaps PARAMs
+#				  - added clock/transmission warnings
+#	Apr  6, 2022: - added %profile_id (not tested)
+#	May 10, 2022: - BUG: non-numeric ids no longer worked
+#				  - added -d to allow for station and cast numbering
+#	May 17, 2022: - made station cast numbering work based on input file name
+# HISTORY END
 #	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
@@ -101,6 +111,9 @@
 #	w_CTD is positive during the downcast to make the sign of the apparent
 #		  water velocity consistent with w_ocean
 
+# TODO:
+#	- add transmission warnings to figure?
+
 ($ANTS)  = (`which ANTSlib`   =~ m{^(.*)/[^/]*$});
 ($WCALC) = ($0                =~ m{^(.*)/[^/]*$});
 $WCALC   = '.' if ($WCALC eq '');
@@ -118,7 +131,7 @@
 $antsParseHeader = 0;											# usage
 $antsSuppressCommonOptions = 1;
 $IS = &antsLoadModel('`','.nminterp','linear');
-&antsUsage("ab:c:fgi:l:morp:qs:v:w:$IS_opts",1,
+&antsUsage("ab:c:d:fgi:l:morp:qs:v:w:$IS_opts",1,
 	'[-v)erbosity <level[0]>]',
 	'[use -a)lternate sensor pair]',
 	'[correct -S)alinity <bias>]',
@@ -126,7 +139,7 @@
 	'[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>]',
+	'[profile -i)d <id>] [id -d)igits <#[3]>] [station -l)ocation <lat/lon>]',
 	'[-p)lot_basenames <[%03d_w_CTD.ps],[%03d_sspd.ps]>]',
 	'[-q)uiet (no plots)]',
 	'[-f)ill gaps with linear interpolation]',
@@ -139,8 +152,14 @@
 &antsFloatOpt(\$opt_b,0);										# salinity bias
 &antsCardOpt(\$opt_v,$ENV{VERB});								# support VERB env variable
 
-$CNVfile = $ARGV[0];											# open CNV file
-open(F,&antsFileArg());
+$CNVfile = $ARGV[0];											# input file
+
+($basename) = ($CNVfile =~ m{([^/]*)\.[^\.]*$});					# determine number of digits to use in profile id
+$opt_d = length($basename)										# 	- default is 3
+	if length($basename)>3 && !defined($opt_d);					#	- use length of input basename if it is longer than 3
+&antsCardOpt(\$opt_d,3);										# 	- explicit -d overrides 
+	
+open(F,&antsFileArg());											# open CNV file
 &antsAddDeps($CNVfile);
 &antsActivateOut();												# activate ANTS file
 
@@ -217,7 +236,7 @@
 			$fill_gaps = 1;
 		} else {
 			print(STDERR "\n\n") if ($opt_v > 1);
-			print(STDERR "WARNING: timeY and/or modError missing from $CNVfile -- cannot correct for CTD modulo errors\n");
+			print(STDERR "WARNING: timeY and/or modError missing from $CNVfile -- cannot correct for CTD transmission errors\n");
 	    }
 	}
 	
@@ -271,6 +290,7 @@
 	my($scans_filled) = 0;
 	my($scans_replaced) = 0;
 	my($scans_deleted) = 0;
+	my($tot_gaps) = 0;
 
 	printf("BEFORE: %d scans\n",scalar(@ants_));
 	for (my($scan)=my($scani)=0; $scan<@ants_; $scan++,$scani++) {					# remove scans with incomplete information
@@ -286,7 +306,7 @@
 
 		if ($ants_[$scan][$systimeF] > $ants_[$scan-1][$systimeF]+1) {				# gap spans at least one full second
 			print(STDERR "\n\n") if ($opt_v > 1);
-			printf(STDERR "WARNING: %d full seconds of data missing at elapsed %d s\n",
+			printf(STDERR "WARNING: $CNVfile: %d full seconds of data missing at elapsed %d s\n",
 				$ants_[$scan][$systimeF]-$ants_[$scan-1][$systimeF]-1,
 				$ants_[$scan-1][$systimeF]-$ants_[0][$systimeF]);
 			my(@splicescan);														# scan to splice in 
@@ -318,6 +338,7 @@
 		for (my($s)=$second_start; $s<=$scan; $s++) {
 			$ngaps++ if ($ants_[$s][$xmerrF] > $ants_[$s-1][$xmerrF]);
 		}
+		$tot_gaps += $ngaps;
 
 		my(@splicescan);															# scan to splice in 
 		$splicescan[$systimeF] = $ants_[$second_start][$systimeF];
@@ -376,17 +397,29 @@
 #		$sts = 1;
 #	}
 
-	&antsAddParams('gaps_scans_filled',$scans_filled,
-				   'scans_removed',$scans_deleted,
-				   'gap_scans_cleared',$scans_replaced);
+	&antsAddParams('CTD_transmission_errors',$tot_gaps,
+				   'CTD_scans_added',$scans_filled,
+				   'CTD_scans_deleted',$scans_deleted,
+				   'CTD_gap_scans_cleared',$scans_replaced);
 
 	if ($opt_v>1 && $scans_filled) {
-		printf(STDERR "\n\t%d scans removed (clock drift)",$scans_deleted);
-		printf(STDERR "\n\t%d scans added (gaps & clock drift)",$scans_filled);
+		printf(STDERR "\n\t%d scans removed (clock jitter/drift)",$scans_deleted);
+		printf(STDERR "\n\t%d scans added (gaps & clock jitter/drift)",$scans_filled);
 		printf(STDERR "\n\t%d scans cleared (gap clusters)",$scans_replaced);
 	}
 	printf(STDERR "\n") if ($opt_v);
-} # if ($fill_gaps
+
+	if ($tot_gaps) {
+		printf(STDERR "WARNING: $CNVfile: %d transmission errors\n",$tot_gaps);
+		printf(STDERR "WARNING: $CNVfile: CTD clock drift (%d scans removed)\n",$scans_deleted-$scans_filled)
+			if ($scans_deleted-$scans_filled > 2);
+	} else {
+		printf(STDERR "WARNING: $CNVfile: CTD clock drift (%d scans removed)\n",$scans_deleted-$scans_filled)
+			if ($scans_deleted-$scans_filled > 2);
+		printf(STDERR "WARNING: $CNVfile: CTD clock drift (%d scans added)\n",$scans_filled-$scans_deleted)
+			if ($scans_filled-$scans_deleted > 2);
+	}
+} # if ($fill_gaps)
 
 #----------------------------------------------------------------------
 # Redirect STDOUT to %.6Hz & create %_w_CTD.ps,%_sspd.ps if STDOUT is a tty
@@ -395,14 +428,16 @@
 $id = defined($opt_i) ? $opt_i : &antsParam('station');
 _croak("$CNVfile: no station information in header => -i required\n")
 	unless defined($id);
-_croak("$CNVfile: non-numeric station information <$id> in header => -i required\n")
-	unless numberp($id);
+#_croak("$CNVfile: non-numeric station information <$id> in header => -i required\n")
+#	unless numberp($id);
+&antsAddParams('profile_id',$id);	
 	
 if (-t STDOUT) {
 	if (numberp($id)) {
-		$opt_p = '%03d_w_CTD.ps,%03d_sspd.ps'
+		my($numfmt) = "%0${opt_d}d";
+		$opt_p = "${numfmt}_w_CTD.ps,${numfmt}_sspd.ps"
 			unless defined($opt_p);
-		$outfile = sprintf('%03d.%dHz',$id,$opt_s);
+		$outfile = sprintf("$numfmt.%dHz",$id,$opt_s);
 	} else {
 		$opt_p = '%s_w_CTD.ps,%s_sspd.ps'
 			unless defined($opt_p);
@@ -918,12 +953,13 @@
     }
 	GMT_psbasemap('-Bg60a30f5:"Elapsed Time [min]":/g1a1f0.1:"Downward Package Velocity [ms@+-1@+]":WeSn');
 	GMT_unitcoords();
-	GMT_pstext('-F+f14,Helvetica,coral+jBR'); 	 print(GMT "0.98 0.96 dc\n");
-	GMT_pstext('-F+f14,Helvetica,SeaGreen+jBR'); print(GMT "0.98 0.93 uc\n");
-	GMT_pstext('-F+f14,Helvetica,magenta+jBR');  print(GMT "0.98 0.89 winch\n");
+	GMT_pstext('-F+f14,Helvetica,coral+jBR -Gwhite'); 	 print(GMT "0.98 0.96 downcast\n");
+	GMT_pstext('-F+f14,Helvetica,SeaGreen+jBR -Gwhite'); print(GMT "0.98 0.92 upcast\n");
+	GMT_pstext('-F+f14,Helvetica,magenta+jBR -Gwhite');  print(GMT "0.98 0.88 winch\n");
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 	if (defined($outfile)) { printf(GMT "0.01 1.06 $outfile\n",$id); }
 	else 				   { printf(GMT "0.01 1.06 %03d\n",$id); }
+	GMT_pstext('-F+f9,Helvetica,orange+jBL -N -Gwhite'); print(GMT "0.01 0.01 V$VERSION\n");
 	GMT_end();	                
 
 	my($xmin) = round($min_sspd-3,5);
@@ -940,11 +976,12 @@
 		GMT_psxy('-W1.5,SeaGreen') if ($r == $atBtm);
 	}
 	GMT_unitcoords();
-	GMT_pstext('-F+f14,Helvetica,coral+jTR'); 	 print(GMT "0.98 0.02 dc\n");
-	GMT_pstext('-F+f14,Helvetica,SeaGreen+jTR'); print(GMT "0.98 0.06 uc\n");
+	GMT_pstext('-F+f14,Helvetica,coral+jTR -Gwhite'); 	 print(GMT "0.98 0.02 downcast\n");
+	GMT_pstext('-F+f14,Helvetica,SeaGreen+jTR -Gwhite'); print(GMT "0.98 0.06 upcast\n");
 	GMT_pstext('-F+f14,Helvetica,blue+jTL -N');
 	if (defined($outfile)) { printf(GMT "0.01 -0.06 $outfile\n",$id); }
 	else 				   { printf(GMT "0.01 -0.06 %03d\n",$id); }
+	GMT_pstext('-F+f9,Helvetica,orange+jBL -N -Gwhite'); print(GMT "0.01 0.99 V$VERSION\n");
 	GMT_end();	                
 }